Skip to content

Commit 9d43689

Browse files
authored
Merge pull request #89 from chapterjason/upmerge-2-x
Upmerge from 2.x
2 parents d07b81c + 6da11fa commit 9d43689

File tree

8 files changed

+139
-34
lines changed

8 files changed

+139
-34
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,48 @@ jobs:
2929
exclude:
3030
- php: '7.2'
3131
symfony: '6.0.*'
32-
- php: '7.3'
33-
symfony: '6.0.*'
34-
- php: '7.4'
35-
symfony: '6.0.*'
3632
- php: '7.2'
3733
symfony: '6.1.*'
38-
- php: '7.3'
39-
symfony: '6.1.*'
40-
- php: '7.4'
41-
symfony: '6.1.*'
42-
- php: '8.0'
43-
symfony: '6.1.*'
4434
- php: '7.2'
4535
symfony: '6.2.*'
46-
- php: '7.3'
47-
symfony: '6.2.*'
48-
- php: '7.4'
49-
symfony: '6.2.*'
50-
- php: '8.0'
51-
symfony: '6.2.*'
5236
- php: '7.2'
5337
symfony: '6.3.*'
54-
- php: '7.3'
55-
symfony: '6.3.*'
56-
- php: '7.4'
57-
symfony: '6.3.*'
58-
- php: '8.0'
59-
symfony: '6.3.*'
6038
- php: '7.2'
6139
symfony: '6.4.*'
62-
- php: '7.3'
63-
symfony: '6.4.*'
64-
- php: '7.4'
65-
symfony: '6.4.*'
66-
- php: '8.0'
67-
symfony: '6.4.*'
6840
- php: '7.2'
6941
symfony: '7.0.*'
42+
- php: '7.3'
43+
symfony: '6.0.*'
44+
- php: '7.3'
45+
symfony: '6.1.*'
46+
- php: '7.3'
47+
symfony: '6.2.*'
48+
- php: '7.3'
49+
symfony: '6.3.*'
50+
- php: '7.3'
51+
symfony: '6.4.*'
7052
- php: '7.3'
7153
symfony: '7.0.*'
54+
- php: '7.4'
55+
symfony: '6.0.*'
56+
- php: '7.4'
57+
symfony: '6.1.*'
58+
- php: '7.4'
59+
symfony: '6.2.*'
60+
- php: '7.4'
61+
symfony: '6.3.*'
62+
- php: '7.4'
63+
symfony: '6.4.*'
7264
- php: '7.4'
7365
symfony: '7.0.*'
66+
- php: '8.0'
67+
symfony: '6.1.*'
68+
- php: '8.0'
69+
symfony: '6.2.*'
70+
- php: '8.0'
71+
symfony: '6.3.*'
72+
- php: '8.0'
73+
symfony: '6.4.*'
7474
- php: '8.0'
7575
symfony: '7.0.*'
7676
- php: '8.1'

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
1313
- Drop support for Symfony 4.4
1414
- Drop support for Symfony 5.3
1515

16+
## 2.1.0
17+
18+
### Added
19+
20+
- Support for Symfony 6.2, 6.3 and 6.4
21+
- Support for PHP 8.2 and 8.3
22+
- Allow to set type and priority for compiler passes in `TestKernel::addTestCompilerPass`
23+
1624
## 2.0.0
1725

1826
### Added

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ Using this bundle test together with Matthias Nobacks's
1111
[SymfonyDependencyInjectionTest](https://github.com/SymfonyTest/SymfonyDependencyInjectionTest)
1212
will give you a good base for testing a Symfony bundle.
1313

14+
## Support
15+
16+
Currently supported PHP and Symfony Versions.
17+
18+
| Branch | PHP Version | Symfony Version | Supported |
19+
|--------|-------------------------|-----------------|-----------|
20+
| 2.x | 7.2 - 8.3 | 4.4, 6.3 - 6.4 | Yes |
21+
22+
Please always try to update to the latest version of this package before reporting an issue.
23+
1424
## Install
1525

1626
Via Composer

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"description": "",
44
"license": "MIT",
55
"type": "library",
6+
"keywords": [
7+
"testing"
8+
],
69
"authors": [
710
{
811
"name": "Tobias Nyholm",

src/TestKernel.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
77
use Symfony\Component\Config\Loader\LoaderInterface;
88
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9+
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
910
use Symfony\Component\DependencyInjection\ContainerBuilder;
1011
use Symfony\Component\Filesystem\Filesystem;
1112
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
@@ -41,7 +42,7 @@ class TestKernel extends Kernel
4142
private $testProjectDir;
4243

4344
/**
44-
* @var CompilerPassInterface[]
45+
* @var array{CompilerPassInterface, string, int}[]
4546
*/
4647
private $testCompilerPasses = [];
4748

@@ -125,19 +126,23 @@ protected function buildContainer(): ContainerBuilder
125126
{
126127
$container = parent::buildContainer();
127128

128-
foreach ($this->testCompilerPasses as $pass) {
129-
$container->addCompilerPass($pass);
129+
foreach ($this->testCompilerPasses as $compilerPass) {
130+
$container->addCompilerPass($compilerPass[0], $compilerPass[1], $compilerPass[2]);
130131
}
131132

132133
return $container;
133134
}
134135

135136
/**
136-
* @param CompilerPassInterface $compilerPasses
137+
* @param CompilerPassInterface $compilerPass
138+
* @param string $type
139+
* @param int $priority
140+
*
141+
* @psalm-param PassConfig::TYPE_* $type
137142
*/
138-
public function addTestCompilerPass($compilerPasses): void
143+
public function addTestCompilerPass($compilerPass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, $priority = 0): void
139144
{
140-
$this->testCompilerPasses[] = $compilerPasses;
145+
$this->testCompilerPasses[] = [$compilerPass, $type, $priority];
141146
}
142147

143148
/**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
class DeRegisterSomethingPass implements CompilerPassInterface
9+
{
10+
public function process(ContainerBuilder $container)
11+
{
12+
if ($container->hasDefinition('something')) {
13+
$container->removeDefinition('something');
14+
}
15+
}
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Definition;
8+
9+
class RegisterSomethingPass implements CompilerPassInterface
10+
{
11+
public function process(ContainerBuilder $container)
12+
{
13+
if ($container->hasDefinition('something')) {
14+
return;
15+
}
16+
17+
$definition = new Definition();
18+
$definition->setClass(\stdClass::class);
19+
$definition->setPublic(true);
20+
21+
$container->setDefinition('something', $definition);
22+
}
23+
}

tests/Functional/BundleConfigurationTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
use Nyholm\BundleTest\TestKernel;
66
use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle;
7+
use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler\DeRegisterSomethingPass;
8+
use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler\RegisterSomethingPass;
79
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
10+
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
811
use Symfony\Component\DependencyInjection\ContainerBuilder;
912
use Symfony\Component\HttpKernel\KernelInterface;
1013

@@ -61,4 +64,41 @@ public function testBundleWithDifferentConfigurationFormats($config): void
6164
$this->assertEquals('val1', $container->getParameter('app.foo'));
6265
$this->assertEquals(['val2', 'val3'], $container->getParameter('app.bar'));
6366
}
67+
68+
public function testAddCompilerPassPriority(): void
69+
{
70+
// CASE 1: Compiler pass without priority, should be prioritized by order of addition
71+
$kernel = self::bootKernel(['config' => function (TestKernel $kernel) {
72+
$kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php');
73+
$kernel->addTestCompilerPass(new DeRegisterSomethingPass());
74+
$kernel->addTestCompilerPass(new RegisterSomethingPass());
75+
}]);
76+
77+
$container = $kernel->getContainer();
78+
79+
$this->assertTrue($container->has('something'));
80+
81+
// CASE 2: Compiler pass with priority, should be prioritized by priority
82+
$kernel = self::bootKernel(['config' => function (TestKernel $kernel) {
83+
$kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php');
84+
$kernel->addTestCompilerPass(new DeRegisterSomethingPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -5);
85+
$kernel->addTestCompilerPass(new RegisterSomethingPass());
86+
}]);
87+
88+
$container = $kernel->getContainer();
89+
90+
$this->assertFalse($container->has('something'));
91+
92+
// CASE 3: Compiler pass without priority, should be prioritized by order of addition
93+
$kernel = self::bootKernel(['config' => function (TestKernel $kernel) {
94+
$kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php');
95+
// DeRegisterSomethingPass is now added as second compiler pass
96+
$kernel->addTestCompilerPass(new RegisterSomethingPass());
97+
$kernel->addTestCompilerPass(new DeRegisterSomethingPass());
98+
}]);
99+
100+
$container = $kernel->getContainer();
101+
102+
$this->assertFalse($container->has('something'));
103+
}
64104
}

0 commit comments

Comments
 (0)