|
|
@@ -10,47 +10,74 @@ use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
class TestablePdfEncoder extends PdfEncoder
|
|
|
{
|
|
|
- public function setDomPdfOptions(Options $options): void
|
|
|
+ public function getDomPdf(): Dompdf
|
|
|
{
|
|
|
- $this->domPdfOptions = $options;
|
|
|
+ return parent::getDomPdf();
|
|
|
}
|
|
|
|
|
|
- public function setDomPdf(Dompdf $dompdf): void
|
|
|
+ public function getDomPdfOptions(): Options
|
|
|
{
|
|
|
- $this->dompdf = $dompdf;
|
|
|
+ return parent::getDomPdfOptions();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class PdfEncoderTest extends TestCase
|
|
|
{
|
|
|
+ private function getPdfEncoderMockFor(string $method): TestablePdfEncoder
|
|
|
+ {
|
|
|
+ return $this->getMockBuilder(TestablePdfEncoder::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->setMethodsExcept([$method])
|
|
|
+ ->getMock();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @see PdfEncoder::support()
|
|
|
*/
|
|
|
public function testSupport(): void
|
|
|
{
|
|
|
- $encoder = $this->getMockBuilder(PdfEncoder::class)
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->setMethodsExcept(['support'])
|
|
|
- ->getMock();
|
|
|
+ $encoder = $this->getPdfEncoderMockFor('support');
|
|
|
|
|
|
$this->assertTrue($encoder->support('pdf'));
|
|
|
$this->assertFalse($encoder->support('txt'));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @see PdfEncoder::getDomPdf()
|
|
|
+ */
|
|
|
+ public function testGetDomPdf(): void
|
|
|
+ {
|
|
|
+ $encoder = $this->getPdfEncoderMockFor('getDomPdf');
|
|
|
+
|
|
|
+ $dompdf = $encoder->getDomPdf();
|
|
|
+
|
|
|
+ $this->assertInstanceOf(Dompdf::class, $dompdf);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see PdfEncoder::getDomPdfOptions()
|
|
|
+ */
|
|
|
+ public function testGetDomPdfOptions(): void
|
|
|
+ {
|
|
|
+ $encoder = $this->getPdfEncoderMockFor('getDomPdfOptions');
|
|
|
+
|
|
|
+ $options = $encoder->getDomPdfOptions();
|
|
|
+
|
|
|
+ $this->assertInstanceOf(Options::class, $options);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @see PdfEncoder::encode()
|
|
|
*/
|
|
|
public function testEncode(): void
|
|
|
{
|
|
|
- $encoder = $this->getMockBuilder(TestablePdfEncoder::class)
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->setMethodsExcept(['encode', 'setDomPdfOptions', 'setDomPdf'])
|
|
|
- ->getMock();
|
|
|
+ $encoder = $this->getPdfEncoderMockFor('encode');
|
|
|
|
|
|
$domPdfOptions = $this->getMockBuilder(Options::class)->disableOriginalConstructor()->getMock();
|
|
|
$domPdf = $this->getMockBuilder(Dompdf::class)->disableOriginalConstructor()->getMock();
|
|
|
- $encoder->setDomPdfOptions($domPdfOptions);
|
|
|
- $encoder->setDomPdf($domPdf);
|
|
|
+
|
|
|
+ $encoder->expects(self::once())->method('getDomPdfOptions')->willReturn($domPdfOptions);
|
|
|
+ $encoder->expects(self::once())->method('getDomPdf')->willReturn($domPdf);
|
|
|
|
|
|
$domPdfOptions->expects(self::once())->method('setIsRemoteEnabled')->with(true);
|
|
|
$domPdfOptions->expects(self::once())->method('setChroot')->with(PathUtils::getProjectDir().'/public');
|