Skip to content

Commit 1d3d70f

Browse files
committed
Move non FrameworkBundle dependent fixtures to its own namespace
In preparation to introducing FrameworkBundle dependent fixtures.
1 parent 44a0444 commit 1d3d70f

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

src/Symfony/Compiler/ExposeServicesForTestsPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Zalas\Injector\PHPUnit\Symfony\Compiler\Discovery\PropertyDiscovery;
1313
use Zalas\Injector\Service\Property;
1414

15+
/**
16+
* Looks for `@inject` annotations to register services in test service locators and make them available in tests.
17+
*/
1518
class ExposeServicesForTestsPass implements CompilerPassInterface
1619
{
1720
/**

src/Symfony/TestCase/SymfonyContainer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/**
99
* Provides a `ServiceContainerTestCase` implementation with the container created by the Symfony Kernel.
10+
*
11+
* Relies on `ExposeServicesForTestsPass` compiler pass being registered.
1012
*/
1113
trait SymfonyContainer
1214
{

tests/Symfony/TestCase/Fixtures/AnotherTestKernel.php renamed to tests/Symfony/TestCase/Fixtures/NoFrameworkBundle/AnotherTestKernel.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures;
4+
namespace Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle;
55

66
use Symfony\Component\Config\Loader\LoaderInterface;
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Reference;
89
use Symfony\Component\HttpKernel\Kernel;
910
use Zalas\Injector\PHPUnit\Symfony\Compiler\Discovery\ClassFinder;
1011
use Zalas\Injector\PHPUnit\Symfony\Compiler\Discovery\PropertyDiscovery;
1112
use Zalas\Injector\PHPUnit\Symfony\Compiler\ExposeServicesForTestsPass;
13+
use Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\Service1;
1214

1315
class AnotherTestKernel extends Kernel
1416
{
@@ -19,17 +21,14 @@ public function registerBundles()
1921

2022
public function getCacheDir()
2123
{
22-
return \sys_get_temp_dir().'/ZalasPHPUnitInjector2/cache/'.$this->environment;
24+
return \sys_get_temp_dir().'/ZalasPHPUnitInjector/NoFrameworkBundle/AnotherTestKernel/cache/'.$this->environment;
2325
}
2426

2527
public function getLogDir()
2628
{
27-
return \sys_get_temp_dir().'/ZalasPHPUnitInjector2/logs';
29+
return \sys_get_temp_dir().'/ZalasPHPUnitInjector/NoFrameworkBundle/AnotherTestKernel/logs';
2830
}
2931

30-
/**
31-
* Loads the container configuration.
32-
*/
3332
public function registerContainerConfiguration(LoaderInterface $loader)
3433
{
3534
$loader->load(function (ContainerBuilder $container) use ($loader) {
@@ -42,7 +41,7 @@ protected function build(ContainerBuilder $container)
4241
if ('test' === $this->getEnvironment()) {
4342
$container->addCompilerPass(
4443
new ExposeServicesForTestsPass(
45-
new PropertyDiscovery(new ClassFinder(__DIR__ . '/../'))
44+
new PropertyDiscovery(new ClassFinder(__DIR__ . '/../../'))
4645
)
4746
);
4847
}

tests/Symfony/TestCase/Fixtures/TestKernel.php renamed to tests/Symfony/TestCase/Fixtures/NoFrameworkBundle/TestKernel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures;
4+
namespace Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle;
55

66
use Symfony\Component\Config\Loader\LoaderInterface;
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Reference;
89
use Symfony\Component\HttpKernel\Kernel;
910
use Zalas\Injector\PHPUnit\Symfony\Compiler\Discovery\ClassFinder;
1011
use Zalas\Injector\PHPUnit\Symfony\Compiler\Discovery\PropertyDiscovery;
1112
use Zalas\Injector\PHPUnit\Symfony\Compiler\ExposeServicesForTestsPass;
13+
use Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\Service1;
14+
use Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\Service2;
1215

1316
class TestKernel extends Kernel
1417
{
@@ -19,17 +22,14 @@ public function registerBundles()
1922

2023
public function getCacheDir()
2124
{
22-
return \sys_get_temp_dir().'/ZalasPHPUnitInjector/cache/'.$this->environment;
25+
return \sys_get_temp_dir().'/ZalasPHPUnitInjector/NoFrameworkBundle/TestKernel/cache/'.$this->environment;
2326
}
2427

2528
public function getLogDir()
2629
{
27-
return \sys_get_temp_dir().'/ZalasPHPUnitInjector/logs';
30+
return \sys_get_temp_dir().'/ZalasPHPUnitInjector/NoFrameworkBundle/TestKernel/logs';
2831
}
2932

30-
/**
31-
* Loads the container configuration.
32-
*/
3333
public function registerContainerConfiguration(LoaderInterface $loader)
3434
{
3535
$loader->load(function (ContainerBuilder $container) use ($loader) {
@@ -43,7 +43,7 @@ protected function build(ContainerBuilder $container)
4343
if ('test' === $this->getEnvironment()) {
4444
$container->addCompilerPass(
4545
new ExposeServicesForTestsPass(
46-
new PropertyDiscovery(new ClassFinder(__DIR__ . '/../'))
46+
new PropertyDiscovery(new ClassFinder(__DIR__ . '/../../'))
4747
)
4848
);
4949
}

tests/Symfony/TestCase/SymfonyContainerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SymfonyContainerTest extends TestCase implements ServiceContainerTestCase
2727
private $service2;
2828

2929
/**
30-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
30+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
3131
*/
3232
public function test_it_initializes_the_container_by_booting_the_symfony_kernel()
3333
{
@@ -41,15 +41,15 @@ public function test_it_initializes_the_container_by_booting_the_symfony_kernel(
4141
}
4242

4343
/**
44-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\AnotherTestKernel
44+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\AnotherTestKernel
4545
*/
4646
public function test_it_ignores_missing_services_when_registering_the_service_locator()
4747
{
4848
$container = $this->createContainer();
4949

5050
$this->assertInstanceOf(ServiceLocator::class, $container, 'Full container is not exposed.');
5151
$this->assertTrue($container->has(Service1::class), 'The private service is available in tests.');
52-
$this->assertFalse($container->has('foo.service2'), 'The private service is available in tests.');
52+
$this->assertFalse($container->has('foo.service2'), 'The private service is not available in tests.');
5353
$this->assertInstanceOf(Service1::class, $container->get(Service1::class));
5454
}
5555
}

tests/Symfony/TestCase/SymfonyKernelTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPUnit\Framework\TestCase;
77
use Symfony\Component\HttpKernel\KernelInterface;
88
use Zalas\Injector\PHPUnit\Symfony\TestCase\SymfonyKernel;
9-
use Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel;
9+
use Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel;
1010

1111
class SymfonyKernelTest extends TestCase
1212
{
@@ -20,7 +20,7 @@ public function test_it_throws_an_exception_if_kernel_class_is_not_configured()
2020
}
2121

2222
/**
23-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
23+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
2424
*/
2525
public function test_it_boots_the_kernel_in_test_environment_with_debug_enabled_by_default()
2626
{
@@ -33,7 +33,7 @@ public function test_it_boots_the_kernel_in_test_environment_with_debug_enabled_
3333
}
3434

3535
/**
36-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
36+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
3737
* @env APP_ENV=test_foo
3838
* @env APP_DEBUG=0
3939
*/
@@ -48,7 +48,7 @@ public function test_it_boots_the_kernel_configured_via_env_variable()
4848
}
4949

5050
/**
51-
* @server KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
51+
* @server KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
5252
* @server APP_ENV=test_foo
5353
* @server APP_DEBUG=0
5454
*/
@@ -98,7 +98,7 @@ public function test_it_prefers_options_over_env_variables()
9898
}
9999

100100
/**
101-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
101+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
102102
* @env APP_ENV=test_foo
103103
* @env APP_DEBUG=0
104104
* @server KERNEL_CLASS=Bar
@@ -115,7 +115,7 @@ public function test_it_prefers_env_variables_over_server()
115115
}
116116

117117
/**
118-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
118+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
119119
*/
120120
public function test_it_ensures_the_kernel_was_shut_down()
121121
{
@@ -127,7 +127,7 @@ public function test_it_ensures_the_kernel_was_shut_down()
127127
}
128128

129129
/**
130-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
130+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
131131
*/
132132
public function test_ensureKernelShutdown_shuts_down_the_kernel()
133133
{
@@ -139,7 +139,7 @@ public function test_ensureKernelShutdown_shuts_down_the_kernel()
139139
}
140140

141141
/**
142-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
142+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
143143
*/
144144
public function test_ensureKernelShutdown_resets_the_container()
145145
{
@@ -158,7 +158,7 @@ public function test_it_starts_in_a_fresh_state()
158158
}
159159

160160
/**
161-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
161+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
162162
*/
163163
public function test_it_creates_the_kernel_in_test_environment_with_debug_enabled_by_default()
164164
{
@@ -170,7 +170,7 @@ public function test_it_creates_the_kernel_in_test_environment_with_debug_enable
170170
}
171171

172172
/**
173-
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
173+
* @env KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
174174
* @env APP_ENV=test_foo
175175
* @env APP_DEBUG=0
176176
*/
@@ -184,7 +184,7 @@ public function test_it_creates_the_kernel_configured_via_env_variable()
184184
}
185185

186186
/**
187-
* @server KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\TestKernel
187+
* @server KERNEL_CLASS=Zalas\Injector\PHPUnit\Tests\Symfony\TestCase\Fixtures\NoFrameworkBundle\TestKernel
188188
* @server APP_ENV=test_foo
189189
* @server APP_DEBUG=0
190190
*/

0 commit comments

Comments
 (0)