| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- use App\Service\Export\Encoder\PdfEncoder;
- use Knp\Snappy\Pdf;
- use PHPUnit\Framework\TestCase;
- class PdfEncoderTest extends TestCase
- {
- public function testSupport() {
- $mocker = $this->getMockBuilder(Pdf::class);
- $knpSnappy = $mocker->getMock();
- $encoder = new PdfEncoder($knpSnappy);
- $this->assertTrue($encoder->support('pdf'));
- $this->assertFalse($encoder->support('txt'));
- }
- public function testGetDefaultOptions() {
- $mocker = $this->getMockBuilder(Pdf::class);
- $knpSnappy = $mocker->getMock();
- $encoder = new PdfEncoder($knpSnappy);
- $this->assertIsArray($encoder->getDefaultOptions());
- }
- public function testEncode() {
- $mocker = $this->getMockBuilder(Pdf::class);
- $knpSnappy = $mocker->getMock();
- $knpSnappy
- ->expects(self::once())
- ->method('getOutputFromHtml')
- ->with('<div>content</div>')
- ->willReturn('%%encoded%%');
- $encoder = new PdfEncoder($knpSnappy);
- $this->assertEquals('%%encoded%%', $encoder->encode('<div>content</div>'));
- }
- }
|