From ae94a00f539b603adfe26e4e2bc8122634a59c5c Mon Sep 17 00:00:00 2001 From: chapterjason Date: Sun, 17 Dec 2023 00:30:26 +0100 Subject: [PATCH 1/6] Backport php and symfony version for ci (#87) * Add CI and support table for more PHP and Symfony versions --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++-- CHANGELOG.md | 7 +++++++ README.md | 10 ++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 170b3e4..e20cf07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: - '7.4' - '8.0' - '8.1' + - '8.2' + - '8.3' dependency: - '' - 'lowest' @@ -22,6 +24,9 @@ jobs: - '5.4.*' - '6.0.*' - '6.1.*' + - '6.2.*' + - '6.3.*' + - '6.4.*' exclude: - php: '7.2' symfony: '4.4.*' @@ -30,25 +35,46 @@ jobs: symfony: '6.0.*' - php: '7.2' symfony: '6.1.*' + - php: '7.2' + symfony: '6.2.*' + - php: '7.2' + 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.1.*' - dependency: 'lowest' + symfony: '6.2.*' + - php: '8.0' + symfony: '6.3.*' + - php: '8.0' + symfony: '6.4.*' - php: '8.1' symfony: '4.4.*' dependency: 'lowest' diff --git a/CHANGELOG.md b/CHANGELOG.md index 83f8699..08937b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.1.0 + +### Added + +- Support for Symfony 6.2, 6.3 and 6.4 +- Support for PHP 8.2 and 8.3 + ## 2.0.0 ### Added diff --git a/README.md b/README.md index 6985ad6..ff2aa5e 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 From 2bbd5970774e189a54bff4eabae0d60c453581e4 Mon Sep 17 00:00:00 2001 From: chapterjason Date: Sun, 17 Dec 2023 01:05:29 +0100 Subject: [PATCH 2/6] Allow to set type and priority for addTestCompilerPass (#88) --- CHANGELOG.md | 1 + src/TestKernel.php | 17 +++++--- .../Compiler/DeRegisterSomethingPass.php | 16 ++++++++ .../Compiler/RegisterSomethingPass.php | 23 +++++++++++ tests/Functional/BundleConfigurationTest.php | 40 +++++++++++++++++++ 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/DeRegisterSomethingPass.php create mode 100644 tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/RegisterSomethingPass.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 08937b2..71272ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - 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 diff --git a/src/TestKernel.php b/src/TestKernel.php index 6fbe60a..e7a61a5 100644 --- a/src/TestKernel.php +++ b/src/TestKernel.php @@ -7,6 +7,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; @@ -42,7 +43,7 @@ class TestKernel extends Kernel private $testProjectDir; /** - * @var CompilerPassInterface[] + * @var array{CompilerPassInterface, string, int}[] */ private $testCompilerPasses = []; @@ -131,19 +132,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')); + } } From 04a1862debf70339feeecef89e70716457144afd Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 17 Dec 2023 01:10:21 +0100 Subject: [PATCH 3/6] chore: add composer keyword for testing (#82) Co-authored-by: Christopher Georg --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 46d5149..07d8ce4 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "description": "", "license": "MIT", "type": "library", + "keywords": ["testing"], "authors": [ { "name": "Tobias Nyholm", From 17bbf71696f49bc9352e744bed88d7b1539783c1 Mon Sep 17 00:00:00 2001 From: chapterjason Date: Sun, 17 Dec 2023 01:22:25 +0100 Subject: [PATCH 4/6] Fix ci --- .github/workflows/ci.yml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0aef461..5b5ce80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,8 +37,8 @@ jobs: symfony: '6.3.*' - php: '7.2' symfony: '6.4.*' - - php: '7.3' - symfony: '4.4.*' + - php: '7.2' + symfony: '7.0.*' - php: '7.3' symfony: '6.0.*' - php: '7.3' @@ -49,8 +49,8 @@ jobs: symfony: '6.3.*' - php: '7.3' symfony: '6.4.*' - - php: '7.4' - symfony: '4.4.*' + - php: '7.3' + symfony: '7.0.*' - php: '7.4' symfony: '6.0.*' - php: '7.4' @@ -61,8 +61,6 @@ jobs: symfony: '6.3.*' - php: '7.4' symfony: '6.4.*' - - php: '8.0' - symfony: '4.4.*' - php: '8.0' symfony: '6.1.*' - php: '8.0' @@ -71,12 +69,6 @@ jobs: symfony: '6.3.*' - php: '8.0' symfony: '6.4.*' - - php: '7.2' - symfony: '7.0.*' - - php: '7.3' - symfony: '7.0.*' - - php: '7.4' - symfony: '7.0.*' - php: '8.0' symfony: '7.0.*' - php: '8.1' From 28c269baf2418c81c40830edf8deedd8d8aac769 Mon Sep 17 00:00:00 2001 From: chapterjason Date: Sun, 17 Dec 2023 01:24:53 +0100 Subject: [PATCH 5/6] Add missing exclude --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b5ce80..86a2429 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,8 @@ jobs: symfony: '6.3.*' - php: '7.4' symfony: '6.4.*' + - php: '7.4' + symfony: '7.0.*' - php: '8.0' symfony: '6.1.*' - php: '8.0' From 28ff207255882892c0714399a833b45d3ac3a231 Mon Sep 17 00:00:00 2001 From: chapterjason Date: Sun, 17 Dec 2023 01:32:56 +0100 Subject: [PATCH 6/6] Normalize composer.json (#90) --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 07d8ce4..555572a 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,9 @@ "description": "", "license": "MIT", "type": "library", - "keywords": ["testing"], + "keywords": [ + "testing" + ], "authors": [ { "name": "Tobias Nyholm",