From 62d82c405262c44ab85a715de5d6e76d068f27d5 Mon Sep 17 00:00:00 2001 From: SmetDenis Date: Fri, 12 Apr 2024 17:27:22 +0400 Subject: [PATCH] Refactor PreloadBuilderTest and add new test Refactored test method name in PreloadBuilderTest for clarity. Added new test `testPreloaderWithCompiling` to cover more cases, primarily for PreloadBuilder with opcache compiler enabled. Check for specific function existence in compiled contents. --- tests/Tools/PreloadBuilderTest.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/Tools/PreloadBuilderTest.php b/tests/Tools/PreloadBuilderTest.php index ed420ea4..125e335d 100644 --- a/tests/Tools/PreloadBuilderTest.php +++ b/tests/Tools/PreloadBuilderTest.php @@ -19,11 +19,12 @@ use JBZoo\CsvBlueprint\Tools\PreloadBuilder; use JBZoo\PHPUnit\TestCase; +use function JBZoo\PHPUnit\isContain; use function JBZoo\PHPUnit\isNotContain; class PreloadBuilderTest extends TestCase { - public function testPreloader(): void + public function testPreloaderWithoutCompiling(): void { (new PreloadBuilder(enableOpcacheCompiler: false)) ->setExcludes([ @@ -36,5 +37,30 @@ public function testPreloader(): void $content = \file_get_contents(PROJECT_BUILD . '/preload.php'); isNotContain(__FILE__, $content); + isContain('PreloadBuilder.php', $content); + + isNotContain('function_exists', $content); + isNotContain('opcache_compile_file', $content); + isContain('require_once', $content); + } + + public function testPreloaderWithCompiling(): void + { + (new PreloadBuilder(enableOpcacheCompiler: true)) + ->setExcludes([ + __FILE__, + ]) + ->setFiles(\get_included_files()) + ->saveToFile(PROJECT_BUILD . '/preload.php'); + + self::assertFileExists(PROJECT_BUILD . '/preload.php'); + + $content = \file_get_contents(PROJECT_BUILD . '/preload.php'); + isNotContain(__FILE__, $content); + isContain('PreloadBuilder.php', $content); + + isContain('function_exists', $content); + isContain('opcache_compile_file', $content); + isNotContain('require_once', $content); } }