diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64b2f8e..0aef461 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,40 +29,46 @@ jobs: exclude: - php: '7.2' symfony: '6.0.*' - - php: '7.3' - symfony: '6.0.*' - - php: '7.4' - symfony: '6.0.*' - php: '7.2' symfony: '6.1.*' - - php: '7.3' - symfony: '6.1.*' - - php: '7.4' - symfony: '6.1.*' - - php: '8.0' - symfony: '6.1.*' - php: '7.2' symfony: '6.2.*' - - php: '7.3' - symfony: '6.2.*' - - php: '7.4' - symfony: '6.2.*' - - php: '8.0' - symfony: '6.2.*' - php: '7.2' symfony: '6.3.*' - - php: '7.3' - symfony: '6.3.*' - - php: '7.4' - symfony: '6.3.*' - - php: '8.0' - symfony: '6.3.*' - php: '7.2' symfony: '6.4.*' + - php: '7.3' + symfony: '4.4.*' + - php: '7.3' + symfony: '6.0.*' + - php: '7.3' + symfony: '6.1.*' + - php: '7.3' + symfony: '6.2.*' + - php: '7.3' + symfony: '6.3.*' - php: '7.3' symfony: '6.4.*' + - php: '7.4' + symfony: '4.4.*' + - php: '7.4' + symfony: '6.0.*' + - php: '7.4' + symfony: '6.1.*' + - php: '7.4' + symfony: '6.2.*' + - php: '7.4' + symfony: '6.3.*' - php: '7.4' symfony: '6.4.*' + - php: '8.0' + symfony: '4.4.*' + - php: '8.0' + symfony: '6.1.*' + - php: '8.0' + symfony: '6.2.*' + - php: '8.0' + symfony: '6.3.*' - php: '8.0' symfony: '6.4.*' - php: '7.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 070f998..c660f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,14 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - Drop support for Symfony 4.4 - Drop support for Symfony 5.3 +## 2.1.0 + +### Added + +- Support for Symfony 6.2, 6.3 and 6.4 +- Support for PHP 8.2 and 8.3 +- Allow to set type and priority for compiler passes in `TestKernel::addTestCompilerPass` + ## 2.0.0 ### Added diff --git a/README.md b/README.md index 664bce7..848645e 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,16 @@ Using this bundle test together with Matthias Nobacks's [SymfonyDependencyInjectionTest](https://github.com/SymfonyTest/SymfonyDependencyInjectionTest) will give you a good base for testing a Symfony bundle. +## Support + +Currently supported PHP and Symfony Versions. + +| Branch | PHP Version | Symfony Version | Supported | +|--------|-------------------------|-----------------|-----------| +| 2.x | 7.2 - 8.3 | 4.4, 6.3 - 6.4 | Yes | + +Please always try to update to the latest version of this package before reporting an issue. + ## Install Via Composer diff --git a/composer.json b/composer.json index 5390fbf..3e66533 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "description": "", "license": "MIT", "type": "library", + "keywords": ["testing"], "authors": [ { "name": "Tobias Nyholm", diff --git a/src/TestKernel.php b/src/TestKernel.php index 37889e0..d9ddf5b 100644 --- a/src/TestKernel.php +++ b/src/TestKernel.php @@ -6,6 +6,7 @@ use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\Bundle\BundleInterface; @@ -41,7 +42,7 @@ class TestKernel extends Kernel private $testProjectDir; /** - * @var CompilerPassInterface[] + * @var array{CompilerPassInterface, string, int}[] */ private $testCompilerPasses = []; @@ -125,19 +126,23 @@ protected function buildContainer(): ContainerBuilder { $container = parent::buildContainer(); - foreach ($this->testCompilerPasses as $pass) { - $container->addCompilerPass($pass); + foreach ($this->testCompilerPasses as $compilerPass) { + $container->addCompilerPass($compilerPass[0], $compilerPass[1], $compilerPass[2]); } return $container; } /** - * @param CompilerPassInterface $compilerPasses + * @param CompilerPassInterface $compilerPass + * @param string $type + * @param int $priority + * + * @psalm-param PassConfig::TYPE_* $type */ - public function addTestCompilerPass($compilerPasses): void + public function addTestCompilerPass($compilerPass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, $priority = 0): void { - $this->testCompilerPasses[] = $compilerPasses; + $this->testCompilerPasses[] = [$compilerPass, $type, $priority]; } /** diff --git a/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/DeRegisterSomethingPass.php b/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/DeRegisterSomethingPass.php new file mode 100644 index 0000000..350664e --- /dev/null +++ b/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/DeRegisterSomethingPass.php @@ -0,0 +1,16 @@ +hasDefinition('something')) { + $container->removeDefinition('something'); + } + } +} diff --git a/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/RegisterSomethingPass.php b/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/RegisterSomethingPass.php new file mode 100644 index 0000000..86590ea --- /dev/null +++ b/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/RegisterSomethingPass.php @@ -0,0 +1,23 @@ +hasDefinition('something')) { + return; + } + + $definition = new Definition(); + $definition->setClass(\stdClass::class); + $definition->setPublic(true); + + $container->setDefinition('something', $definition); + } +} diff --git a/tests/Functional/BundleConfigurationTest.php b/tests/Functional/BundleConfigurationTest.php index 26c5d6d..546b54d 100644 --- a/tests/Functional/BundleConfigurationTest.php +++ b/tests/Functional/BundleConfigurationTest.php @@ -4,7 +4,10 @@ use Nyholm\BundleTest\TestKernel; use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle; +use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler\DeRegisterSomethingPass; +use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler\RegisterSomethingPass; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\KernelInterface; @@ -61,4 +64,41 @@ public function testBundleWithDifferentConfigurationFormats($config): void $this->assertEquals('val1', $container->getParameter('app.foo')); $this->assertEquals(['val2', 'val3'], $container->getParameter('app.bar')); } + + public function testAddCompilerPassPriority(): void + { + // CASE 1: Compiler pass without priority, should be prioritized by order of addition + $kernel = self::bootKernel(['config' => function (TestKernel $kernel) { + $kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php'); + $kernel->addTestCompilerPass(new DeRegisterSomethingPass()); + $kernel->addTestCompilerPass(new RegisterSomethingPass()); + }]); + + $container = $kernel->getContainer(); + + $this->assertTrue($container->has('something')); + + // CASE 2: Compiler pass with priority, should be prioritized by priority + $kernel = self::bootKernel(['config' => function (TestKernel $kernel) { + $kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php'); + $kernel->addTestCompilerPass(new DeRegisterSomethingPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -5); + $kernel->addTestCompilerPass(new RegisterSomethingPass()); + }]); + + $container = $kernel->getContainer(); + + $this->assertFalse($container->has('something')); + + // CASE 3: Compiler pass without priority, should be prioritized by order of addition + $kernel = self::bootKernel(['config' => function (TestKernel $kernel) { + $kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php'); + // DeRegisterSomethingPass is now added as second compiler pass + $kernel->addTestCompilerPass(new RegisterSomethingPass()); + $kernel->addTestCompilerPass(new DeRegisterSomethingPass()); + }]); + + $container = $kernel->getContainer(); + + $this->assertFalse($container->has('something')); + } }