Skip to content

Commit

Permalink
Merge pull request #542 from lcobucci/sf-7.2-compatibility
Browse files Browse the repository at this point in the history
Make tests compatible with Symfony 7.1 and 7.2
  • Loading branch information
lcobucci authored Nov 19, 2024
2 parents 74971bf + 881ce3b commit 9295b97
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions test/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Container;

use function count;
use function array_keys;
use function array_reduce;
use function file_get_contents;
use function file_put_contents;
use function iterator_to_array;
use function str_starts_with;

#[PHPUnit\CoversClass(Compiler::class)]
#[PHPUnit\UsesClass(ParameterBag::class)]
Expand All @@ -32,13 +34,6 @@ final class CompilerTest extends TestCase
{
use GeneratesDumpDirectory;

private const EXPECTED_FILES = [
'getTestingService.php',
'AppContainer.php',
'AppContainer.preload.php',
'AppContainer.php.meta',
];

private ContainerConfiguration $config;
private ConfigCache $dump;
private ParameterBag $parameters;
Expand Down Expand Up @@ -75,14 +70,10 @@ public function compileShouldCreateMultipleFilesForDevelopmentMode(): void
$compiler = new Compiler();
$compiler->compile($this->config, $this->dump, new Yaml(__FILE__));

$expectedFiles = self::EXPECTED_FILES;
$generatedFiles = iterator_to_array($this->getGeneratedFiles());

self::assertCount(count($expectedFiles), $generatedFiles);

foreach ($generatedFiles as $name => $file) {
self::assertContains($name, $expectedFiles);
}
self::assertArrayHasKey('getTestingService.php', $generatedFiles);
self::assertArrayHasKey('AppContainer.php', $generatedFiles);
}

#[PHPUnit\Test]
Expand All @@ -93,14 +84,10 @@ public function compileShouldInlineFactoriesForProductionMode(): void
$compiler = new Compiler();
$compiler->compile($this->config, $this->dump, new Yaml(__FILE__));

$expectedFiles = self::EXPECTED_FILES;
$generatedFiles = iterator_to_array($this->getGeneratedFiles());

self::assertCount(count($expectedFiles) - 1, $generatedFiles);

foreach ($generatedFiles as $name => $file) {
self::assertContains($name, $expectedFiles);
}
self::assertArrayNotHasKey('getTestingService.php', $generatedFiles);
self::assertArrayHasKey('AppContainer.php', $generatedFiles);
}

#[PHPUnit\Test]
Expand All @@ -126,10 +113,19 @@ public function compileShouldAllowForLazyServices(): void
$compiler = new Compiler();
$compiler->compile($this->config, $this->dump, new Yaml(__FILE__));

$expectedFiles = self::EXPECTED_FILES;
$generatedFiles = iterator_to_array($this->getGeneratedFiles());

self::assertCount(count($expectedFiles) + 1, $generatedFiles);
self::assertArrayHasKey('getTestingService.php', $generatedFiles);
self::assertArrayHasKey('AppContainer.php', $generatedFiles);
self::assertTrue(
array_reduce(
array_keys($generatedFiles),
// @phpstan-ignore-next-line
static fn (bool $result, string $name): bool => $result ?: str_starts_with($name, 'stdClassGhost'),
false,
),
'Failed asserting that ghost file for the stdClass service exists.',
);
}

#[PHPUnit\Test]
Expand Down

0 comments on commit 9295b97

Please sign in to comment.