From 9d997c1a830d8c12db3d83e49b36ced3828bef34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 18 Oct 2021 23:53:10 +0200 Subject: [PATCH] Remove flaky test Depending on the order of the test suite execution we were having issues as the compiled container for `CompilerTest` was using the same FQCN as the `GeneratorTest`. This makes sure we use different namespaces for the generated containers, avoiding those conflicts. It also plugs vfsStream to remove the file system dependency on `CompilerTest`. Running PHPUnit using the flag `--random-order-seed=1634593025` was enough to reproduce the issue. --- test/CompilerTest.php | 20 +++++--------------- test/GeneratorTest.php | 12 ++++++------ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/test/CompilerTest.php b/test/CompilerTest.php index 12edb562..4cf329ee 100644 --- a/test/CompilerTest.php +++ b/test/CompilerTest.php @@ -16,15 +16,11 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\Container; -use function bin2hex; use function count; -use function exec; use function file_get_contents; use function file_put_contents; use function iterator_to_array; use function mkdir; -use function random_bytes; -use function realpath; /** * @covers \Lcobucci\DependencyInjection\Compiler @@ -53,7 +49,7 @@ final class CompilerTest extends TestCase public function configureDependencies(): void { vfsStream::setup( - 'tests', + 'tests-compilation', null, ['services.yml' => 'services: { testing: { class: stdClass } }'], ); @@ -67,8 +63,8 @@ public function configureDependencies(): void $this->dump = new ConfigCache($this->dumpDir . '/AppContainer.php', false); $this->config = new ContainerConfiguration( - 'Me\\MyApp', - [vfsStream::url('tests/services.yml')], + 'Me\\CompilationTest', + [vfsStream::url('tests-compilation/services.yml')], [ [$this->parameters, PassConfig::TYPE_BEFORE_OPTIMIZATION], [[MakeServicesPublic::class, []], PassConfig::TYPE_BEFORE_OPTIMIZATION], @@ -80,18 +76,12 @@ public function configureDependencies(): void private function createDumpDirectory(): string { - $dir = __DIR__ . '/../tmp/' . bin2hex(random_bytes(5)) . '/me_myapp'; + $dir = vfsStream::url('tests-compilation/tmp/me_myapp'); mkdir($dir, 0777, true); return $dir; } - /** @after */ - public function cleanUpDumpDirectory(): void - { - exec('rm -rf ' . realpath($this->dumpDir . '/../../')); - } - /** @test */ public function compileShouldCreateMultipleFilesForDevelopmentMode(): void { @@ -143,7 +133,7 @@ public function compileShouldTrackChangesOnTheConfigurationFile(): void public function compileShouldAllowForLazyServices(): void { file_put_contents( - vfsStream::url('tests/services.yml'), + vfsStream::url('tests-compilation/services.yml'), 'services: { testing: { class: stdClass, lazy: true } }', ); diff --git a/test/GeneratorTest.php b/test/GeneratorTest.php index 409d2933..2fb93f41 100644 --- a/test/GeneratorTest.php +++ b/test/GeneratorTest.php @@ -79,19 +79,19 @@ public function initializeContainerCanOptionallyUseACustomClass(): void public function generateShouldCompileAndLoadTheContainer(): void { vfsStream::setup( - 'tests', + 'tests-generation', null, ['services.yml' => 'services: { testing: { class: stdClass, public: true } }'], ); $config = new ContainerConfiguration( - 'Me\\MyApp', - [vfsStream::url('tests/services.yml')], + 'Me\\GenerationTest', + [vfsStream::url('tests-generation/services.yml')], [ [new ParameterBag(['app.devmode' => true]), PassConfig::TYPE_BEFORE_OPTIMIZATION], [ new DumpXmlContainer( - new ConfigCache(vfsStream::url('tests/dump.xml'), true), + new ConfigCache(vfsStream::url('tests-generation/dump.xml'), true), ), PassConfig::TYPE_AFTER_REMOVING, -255, @@ -99,7 +99,7 @@ public function generateShouldCompileAndLoadTheContainer(): void ], ); - $dump = new ConfigCache(vfsStream::url('tests/container.php'), false); + $dump = new ConfigCache(vfsStream::url('tests-generation/container.php'), false); $this->generator->method('getLoader')->willReturnCallback( static function (SymfonyBuilder $container, array $paths): YamlFileLoader { @@ -113,6 +113,6 @@ static function (SymfonyBuilder $container, array $paths): YamlFileLoader { $container = $this->generator->generate($config, $dump); self::assertInstanceOf(stdClass::class, $container->get('testing')); - self::assertFileExists(vfsStream::url('tests/dump.xml')); + self::assertFileExists(vfsStream::url('tests-generation/dump.xml')); } }