Skip to content

Commit

Permalink
Reorganized tests for ZugferdDocumentPdfBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Nov 1, 2024
1 parent de81d98 commit f133197
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/ZugferdDocumentPdfBuilderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ private function isFile($pdfData): bool
{
try {
return @is_file($pdfData);
} catch (TypeError $ex) {
return false;
} catch (Throwable $ex) {
return false;
}
Expand Down
35 changes: 31 additions & 4 deletions tests/testcases/PdfBuilderEn16931Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use horstoeko\zugferd\ZugferdDocumentBuilder;
use horstoeko\zugferd\ZugferdDocumentPdfBuilder;
use horstoeko\zugferd\ZugferdDocumentPdfBuilderAbstract;
use horstoeko\zugferd\ZugferdPackageVersion;
use horstoeko\zugferd\ZugferdProfiles;
use setasign\Fpdi\PdfParser\PdfParserException;
use setasign\Fpdi\PdfParser\StreamReader;
Expand Down Expand Up @@ -106,6 +105,19 @@ public function testBuildFromSourcePdfFile(): void
$pdfBuilder->saveDocument(self::$destPdfFilename);

$this->assertFileExists(self::$destPdfFilename);

ob_start();
$pdfBuilder->saveDocumentInline(self::$destPdfFilename);
$pdfContent = ob_get_clean();

$this->assertIsString($pdfContent);
$this->assertNotEquals('', $pdfContent);

$pdfContent = $pdfBuilder->downloadString(self::$destPdfFilename);

$this->assertIsString($pdfContent);
$this->assertNotEquals('', $pdfContent);
$this->assertStringStartsNotWith('%PDF-1.4', $pdfContent);
}

public function testBuildFromSourcePdfStringWhichIsInvalid(): void
Expand All @@ -121,11 +133,26 @@ public function testBuildFromSourcePdfStringWhichIsInvalid(): void

public function testBuildFromSourcePdfString(): void
{
$pdfBuilder = new ZugferdDocumentPdfBuilder(self::$document, self::$sourcePdfFilename);
$pdfContent = file_get_contents(self::$sourcePdfFilename);

$pdfBuilder = new ZugferdDocumentPdfBuilder(self::$document, $pdfContent);
$pdfBuilder->generateDocument();
$pdfBuilder->downloadString(self::$destPdfFilename);
$pdfBuilder->saveDocument(self::$destPdfFilename);

$this->assertFileExists(self::$destPdfFilename);

ob_start();
$pdfBuilder->saveDocumentInline(self::$destPdfFilename);
$pdfContent = ob_get_clean();

$this->assertIsString($pdfContent);
$this->assertNotEquals('', $pdfContent);

$pdfContent = $pdfBuilder->downloadString(self::$destPdfFilename);

$this->assertIsString(self::$destPdfFilename);
$this->assertIsString($pdfContent);
$this->assertNotEquals('', $pdfContent);
$this->assertStringStartsNotWith('%PDF-1.4', $pdfContent);
}

public function testPdfMetaData(): void
Expand Down

0 comments on commit f133197

Please sign in to comment.