PdfEncoderTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use App\Service\Export\Encoder\PdfEncoder;
  3. use Knp\Snappy\Pdf;
  4. use PHPUnit\Framework\TestCase;
  5. class PdfEncoderTest extends TestCase
  6. {
  7. public function testSupport() {
  8. $mocker = $this->getMockBuilder(Pdf::class);
  9. $knpSnappy = $mocker->getMock();
  10. $encoder = new PdfEncoder($knpSnappy);
  11. $this->assertTrue($encoder->support('pdf'));
  12. $this->assertFalse($encoder->support('txt'));
  13. }
  14. public function testGetDefaultOptions() {
  15. $mocker = $this->getMockBuilder(Pdf::class);
  16. $knpSnappy = $mocker->getMock();
  17. $encoder = new PdfEncoder($knpSnappy);
  18. $this->assertIsArray($encoder->getDefaultOptions());
  19. }
  20. public function testEncode() {
  21. $mocker = $this->getMockBuilder(Pdf::class);
  22. $knpSnappy = $mocker->getMock();
  23. $knpSnappy
  24. ->expects(self::once())
  25. ->method('getOutputFromHtml')
  26. ->with('<div>content</div>')
  27. ->willReturn('%%encoded%%');
  28. $encoder = new PdfEncoder($knpSnappy);
  29. $this->assertEquals('%%encoded%%', $encoder->encode('<div>content</div>'));
  30. }
  31. }