Skip to content

Commit

Permalink
Refactor PreloadBuilderTest and add new test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SmetDenis committed Apr 12, 2024
1 parent 652e128 commit 62d82c4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/Tools/PreloadBuilderTest.php
Expand Up @@ -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([
Expand All @@ -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);
}
}

0 comments on commit 62d82c4

Please sign in to comment.