diff --git a/.gitignore b/.gitignore index 9f7991b..dd0fa4d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ resources/photos/ resources/pdftemplates/ tests/.phpunit.result.cache resources/*/output/ +tests/pdftemplates-test/output/* diff --git a/tests/SirTest.php b/tests/SirTest.php index 653a3aa..9bcf3ec 100644 --- a/tests/SirTest.php +++ b/tests/SirTest.php @@ -4,12 +4,14 @@ use PHPUnit\Framework\TestCase; use WEEEOpen\Crauto\Sir; -const TEST_DIR = __DIR__ . '/../resources/pdftemplates-test'; +const TEST_DIR = __DIR__ . '/pdftemplates-test'; class SirTest extends TestCase { - private static function delete_file(string $file) { - // Comment out if you want to check the output files - //unlink($file); + private static function delete_file(?string $file): void { + if(isset($file) && is_file($file)) { + // Comment out if you want to check the output files + unlink($file); + } } protected function setUp(): void { @@ -23,11 +25,7 @@ protected function setUp(): void { public function testGenerateSir() { $pdfFilePath = null; - register_shutdown_function(function() use (&$pdfFilePath) { - if(is_file($pdfFilePath)) { - self::delete_file($pdfFilePath); - } - }); + register_shutdown_function(function() use (&$pdfFilePath) { self::delete_file($pdfFilePath); }); $replacements = [ '[NAME]' => 'John', @@ -45,11 +43,7 @@ public function testGenerateSir() { public function testGenerateSirPhD() { $pdfFilePath = null; - register_shutdown_function(function() use (&$pdfFilePath) { - if(is_file($pdfFilePath)) { - self::delete_file($pdfFilePath); - } - }); + register_shutdown_function(function() use (&$pdfFilePath) { self::delete_file($pdfFilePath); }); $replacements = [ '[NAME]' => 'Andrea', @@ -68,14 +62,7 @@ public function testGenerateSirPhD() { public function testGenerateSir2() { $pdfFilePath = null; $pdfFilePath2 = null; - register_shutdown_function(function() use (&$pdfFilePath, &$pdfFilePath2) { - if(is_file($pdfFilePath)) { - self::delete_file($pdfFilePath); - } - if(is_file($pdfFilePath2)) { - self::delete_file($pdfFilePath2); - } - }); + register_shutdown_function(function() use (&$pdfFilePath, &$pdfFilePath2) { self::delete_file($pdfFilePath); self::delete_file($pdfFilePath2); }); $replacements = [ '[NAME]' => 'John', @@ -105,14 +92,7 @@ public function testGenerateSir2() { public function testGenerateSirOnce() { $pdfFilePath = null; $pdfFilePath2 = null; - register_shutdown_function(function() use (&$pdfFilePath, &$pdfFilePath2) { - if(is_file($pdfFilePath)) { - self::delete_file($pdfFilePath); - } - if(is_file($pdfFilePath2)) { - self::delete_file($pdfFilePath2); - } - }); + register_shutdown_function(function() use (&$pdfFilePath, &$pdfFilePath2) { self::delete_file($pdfFilePath); self::delete_file($pdfFilePath2); }); $replacements = [ '[NAME]' => 'John', @@ -135,14 +115,7 @@ public function testGenerateSirOnce() { public function testGenerateSirWithUpdate() { $pdfFilePath = null; $pdfFilePath2 = null; - register_shutdown_function(function() use (&$pdfFilePath, &$pdfFilePath2) { - if(is_file($pdfFilePath)) { - self::delete_file($pdfFilePath); - } - if(is_file($pdfFilePath2)) { - self::delete_file($pdfFilePath2); - } - }); + register_shutdown_function(function() use (&$pdfFilePath, &$pdfFilePath2) { self::delete_file($pdfFilePath); self::delete_file($pdfFilePath2); }); $replacements = [ '[NAME]' => 'John', diff --git a/resources/pdftemplates-test/F-MOD-LABORATORI.pdf b/tests/pdftemplates-test/F-MOD-LABORATORI.pdf similarity index 100% rename from resources/pdftemplates-test/F-MOD-LABORATORI.pdf rename to tests/pdftemplates-test/F-MOD-LABORATORI.pdf diff --git a/resources/pdftemplates-test/template-dottorandi.csv b/tests/pdftemplates-test/template-dottorandi.csv similarity index 100% rename from resources/pdftemplates-test/template-dottorandi.csv rename to tests/pdftemplates-test/template-dottorandi.csv diff --git a/resources/pdftemplates-test/template-studenti.csv b/tests/pdftemplates-test/template-studenti.csv similarity index 100% rename from resources/pdftemplates-test/template-studenti.csv rename to tests/pdftemplates-test/template-studenti.csv