| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- use App\Service\Export\Encoder\PdfEncoder;
- use Knp\Snappy\Pdf;
- use PHPUnit\Framework\MockObject\MockObject;
- use PHPUnit\Framework\TestCase;
- class PdfEncoderTest extends TestCase
- {
- private MockObject | Pdf $knpSnappy;
- public function setUp(): void
- {
- $this->knpSnappy = $this->getMockBuilder(Pdf::class)->getMock();
- }
- public function testSupport(): void
- {
- $encoder = $this->getMockBuilder(PdfEncoder::class)
- ->setConstructorArgs([$this->knpSnappy])
- ->setMethodsExcept(['support'])
- ->getMock();
- $this->assertTrue($encoder->support('pdf'));
- $this->assertFalse($encoder->support('txt'));
- }
- public function testGetDefaultOptions(): void
- {
- $encoder = $this->getMockBuilder(PdfEncoder::class)
- ->setConstructorArgs([$this->knpSnappy])
- ->setMethodsExcept(['getDefaultOptions'])
- ->getMock();
- $this->assertIsArray($encoder->getDefaultOptions());
- }
- public function testEncode(): void
- {
- $encoder = $this->getMockBuilder(PdfEncoder::class)
- ->setConstructorArgs([$this->knpSnappy])
- ->setMethodsExcept(['encode'])
- ->getMock();
- $encoder->method('getDefaultOptions')->willReturn(['defaultOption' => 1]);
- $this->knpSnappy
- ->expects(self::once())
- ->method('getOutputFromHtml')
- ->with('<div>content</div>', ['defaultOption' => 1, 'additionalOption' => 2])
- ->willReturn('%%encoded%%');
- $this->assertEquals(
- '%%encoded%%',
- $encoder->encode('<div>content</div>', ['additionalOption' => 2])
- );
- }
- }
|