Skip to content

Commit f5aa545

Browse files
committed
Allow Symfony 5
1 parent ba8c0b2 commit f5aa545

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
"zalas/injector": "^1.3"
1010
},
1111
"require-dev": {
12-
"symfony/config": "^3.4 || ^4.3",
13-
"symfony/dependency-injection": "^3.4 || ^4.3",
14-
"symfony/http-kernel": "^3.4 || ^4.3",
12+
"symfony/config": "^3.4 || ^4.4 || ^5.0",
13+
"symfony/dependency-injection": "^3.4 || ^4.4 || ^5.0",
14+
"symfony/http-kernel": "^3.4 || ^4.4 || ^5.0",
1515
"zalas/phpunit-globals": "^1.0",
16-
"symfony/framework-bundle": "^3.4 || ^4.3",
17-
"zalas/phpunit-doubles": "^1.2"
16+
"symfony/framework-bundle": "^3.4 || ^4.4 || ^5.0",
17+
"zalas/phpunit-doubles": "^1.2",
18+
"phpspec/prophecy": "^1.9"
1819
},
1920
"autoload": {
2021
"psr-4": {

depfile.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ layers:
4242
collectors:
4343
- type: className
4444
regex: ^Symfony\\Component\\HttpKernel\\.*
45+
- name: Symfony Service Contracts
46+
collectors:
47+
- type: className
48+
regex: ^Symfony\\Contracts\\Service\\.*
4549
- name: PHPUnit
4650
collectors:
4751
- type: className
@@ -71,6 +75,8 @@ layers:
7175
regex: ^Symfony\\Component\\DependencyInjection\\.*
7276
- type: className
7377
regex: ^Symfony\\Component\\HttpKernel\\.*
78+
- type: className
79+
regex: ^Symfony\\Contracts\\Service\\.*
7480
ruleset:
7581
Symfony Compiler:
7682
- Injector Factory
@@ -83,6 +89,7 @@ ruleset:
8389
- Psr Container
8490
- Symfony DependencyInjection
8591
- Symfony HttpKernel
92+
- Symfony Service Contracts
8693
TestCase:
8794
- Psr Container
8895
TestListener:

src/Symfony/TestCase/SymfonyKernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
77
use Symfony\Component\HttpKernel\KernelInterface;
8+
use Symfony\Contracts\Service\ResetInterface;
89

910
/**
1011
* Mimics the behaviour of Symfony's KernelTestCase.
@@ -54,7 +55,7 @@ protected static function ensureKernelShutdown(): void
5455
if (static::$kernel instanceof KernelInterface) {
5556
$container = static::$kernel->getContainer();
5657
static::$kernel->shutdown();
57-
if ($container instanceof ResettableContainerInterface) {
58+
if ($container instanceof ResetInterface || $container instanceof ResettableContainerInterface) {
5859
$container->reset();
5960
}
6061

tests/Symfony/TestCase/SymfonyKernelTest.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Zalas\Injector\PHPUnit\Tests\Symfony\TestCase;
55

66
use PHPUnit\Framework\TestCase;
7+
use Symfony\Component\HttpKernel\Kernel;
78
use Symfony\Component\HttpKernel\KernelInterface;
89
use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyKernel;
910
use Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel;
@@ -117,8 +118,11 @@ public function test_it_prefers_env_variables_over_server()
117118
/**
118119
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
119120
*/
120-
public function test_it_ensures_the_kernel_was_shut_down()
121+
public function test_it_ensures_the_kernel_was_shut_down_on_legacy_symfony_versions()
121122
{
123+
if (Kernel::MAJOR_VERSION > 4) {
124+
$this->markTestSkipped();
125+
}
122126
$kernel1 = self::bootKernel();
123127
$kernel2 = self::bootKernel();
124128

@@ -129,15 +133,55 @@ public function test_it_ensures_the_kernel_was_shut_down()
129133
/**
130134
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
131135
*/
132-
public function test_ensureKernelShutdown_shuts_down_the_kernel()
136+
public function test_ensureKernelShutdown_shuts_down_the_kernel_on_legacy_symfony_versions()
133137
{
138+
if (Kernel::MAJOR_VERSION > 4) {
139+
$this->markTestSkipped();
140+
}
134141
$kernel = self::bootKernel();
135142

136143
self::ensureKernelShutdown();
137144

138145
$this->assertNull($kernel->getContainer());
139146
}
140147

148+
/**
149+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
150+
*/
151+
public function test_it_ensures_the_kernel_was_shut_down()
152+
{
153+
if (Kernel::MAJOR_VERSION < 5) {
154+
$this->markTestSkipped();
155+
}
156+
$this->expectException(\LogicException::class);
157+
$this->expectExceptionMessageMatches('/Cannot retrieve the container from a non-booted kernel/');
158+
159+
$kernel1 = self::bootKernel();
160+
$kernel2 = self::bootKernel();
161+
162+
$this->assertNotNull($kernel2->getContainer());
163+
164+
$kernel1->getContainer();
165+
}
166+
167+
/**
168+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
169+
*/
170+
public function test_ensureKernelShutdown_shuts_down_the_kernel()
171+
{
172+
if (Kernel::MAJOR_VERSION < 5) {
173+
$this->markTestSkipped();
174+
}
175+
$this->expectException(\LogicException::class);
176+
$this->expectExceptionMessageMatches('/Cannot retrieve the container from a non-booted kernel/');
177+
178+
$kernel = self::bootKernel();
179+
180+
self::ensureKernelShutdown();
181+
182+
$kernel->getContainer();
183+
}
184+
141185
/**
142186
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
143187
*/

0 commit comments

Comments
 (0)