Skip to content

Commit 2539294

Browse files
authored
refactor #154 Remove container cleanup in test environment (1.3) (Zales0123)
This PR was merged into the 1.3 branch. Discussion ---------- changes incorporated from Sylius/Sylius#10067 Commits ------- 0cb492e Remove container cleanup in test environment
2 parents bd5d3c6 + 0cb492e commit 2539294

File tree

2 files changed

+1
-69
lines changed

2 files changed

+1
-69
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env:
1919
- SYLIUS_BUILD_DIR=etc/build
2020
matrix:
2121
- SYMFONY_VERSION="3.4.*"
22-
- SYMFONY_VERSION="4.1.*"
22+
- SYMFONY_VERSION="4.2.*"
2323

2424
before_install:
2525
- phpenv config-rm xdebug.ini

tests/Application/Kernel.php

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

55
namespace Tests\Acme\SyliusExamplePlugin\Application;
66

7-
use ProxyManager\Proxy\VirtualProxyInterface;
87
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
98
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
109
use Symfony\Component\Config\Loader\DelegatingLoader;
@@ -31,13 +30,6 @@ final class Kernel extends BaseKernel
3130

3231
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
3332

34-
private const IGNORED_SERVICES_DURING_CLEANUP = [
35-
'kernel',
36-
'http_kernel',
37-
'liip_imagine.mime_type_guesser',
38-
'liip_imagine.extension_guesser',
39-
];
40-
4133
public function getCacheDir(): string
4234
{
4335
return $this->getProjectDir() . '/var/cache/' . $this->environment;
@@ -58,25 +50,6 @@ public function registerBundles(): iterable
5850
}
5951
}
6052

61-
public function shutdown(): void
62-
{
63-
if (!$this->isTestEnvironment()) {
64-
parent::shutdown();
65-
66-
return;
67-
}
68-
69-
if (false === $this->booted) {
70-
return;
71-
}
72-
73-
$container = $this->getContainer();
74-
75-
parent::shutdown();
76-
77-
$this->cleanupContainer($container);
78-
}
79-
8053
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
8154
{
8255
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
@@ -130,45 +103,4 @@ private function isTestEnvironment(): bool
130103
{
131104
return 0 === strpos($this->getEnvironment(), 'test');
132105
}
133-
134-
/**
135-
* Remove all container references from all loaded services
136-
*/
137-
private function cleanupContainer(ContainerInterface $container): void
138-
{
139-
$containerReflection = new \ReflectionObject($container);
140-
$containerServicesPropertyReflection = $containerReflection->getProperty('services');
141-
$containerServicesPropertyReflection->setAccessible(true);
142-
143-
$services = $containerServicesPropertyReflection->getValue($container) ?: [];
144-
foreach ($services as $serviceId => $service) {
145-
if (null === $service) {
146-
continue;
147-
}
148-
149-
if (in_array($serviceId, self::IGNORED_SERVICES_DURING_CLEANUP, true)) {
150-
continue;
151-
}
152-
153-
$serviceReflection = new \ReflectionObject($service);
154-
155-
if ($serviceReflection->implementsInterface(VirtualProxyInterface::class)) {
156-
continue;
157-
}
158-
159-
$servicePropertiesReflections = $serviceReflection->getProperties();
160-
$servicePropertiesDefaultValues = $serviceReflection->getDefaultProperties();
161-
foreach ($servicePropertiesReflections as $servicePropertyReflection) {
162-
$defaultPropertyValue = null;
163-
if (isset($servicePropertiesDefaultValues[$servicePropertyReflection->getName()])) {
164-
$defaultPropertyValue = $servicePropertiesDefaultValues[$servicePropertyReflection->getName()];
165-
}
166-
167-
$servicePropertyReflection->setAccessible(true);
168-
$servicePropertyReflection->setValue($service, $defaultPropertyValue);
169-
}
170-
}
171-
172-
$containerServicesPropertyReflection->setValue($container, null);
173-
}
174106
}

0 commit comments

Comments
 (0)