Merge branch '1.2' into 1.3

* 1.2:
  Remove container cleanup in test environment
This commit is contained in:
Kamil Kokot 2019-01-11 10:14:38 +01:00
commit c0200a5966
No known key found for this signature in database
GPG key ID: 7BD76F7054D93C89
2 changed files with 18 additions and 69 deletions

View file

@ -18,7 +18,7 @@ matrix:
- SYMFONY_VERSION="3.4.*"
services:
- memcached
-
- if: type IN (cron, api) OR tag IS present
php: 7.2
env:
- SYLIUS_SUITE="application"
@ -26,6 +26,13 @@ matrix:
services:
- memcached
-
php: 7.2
env:
- SYLIUS_SUITE="application"
- SYMFONY_VERSION="4.2.*"
services:
- memcached
-
php: 7.2
env:
- SYLIUS_SUITE="packages"
@ -34,11 +41,20 @@ matrix:
apt:
packages:
- parallel
- if: type IN (cron, api) OR tag IS present
php: 7.2
env:
- SYLIUS_SUITE="packages"
- SYMFONY_VERSION="4.1.*"
addons:
apt:
packages:
- parallel
-
php: 7.2
env:
- SYLIUS_SUITE="docs packages"
- SYMFONY_VERSION="4.1.*"
- SYMFONY_VERSION="4.2.*"
services:
- docker
addons:

View file

@ -39,13 +39,6 @@ class Kernel extends BaseKernel
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
private const IGNORED_SERVICES_DURING_CLEANUP = [
'kernel',
'http_kernel',
'liip_imagine.mime_type_guesser',
'liip_imagine.extension_guesser',
];
public function getCacheDir(): string
{
return $this->getProjectDir() . '/var/cache/' . $this->environment;
@ -66,25 +59,6 @@ class Kernel extends BaseKernel
}
}
public function shutdown(): void
{
if (!$this->isTestEnvironment()) {
parent::shutdown();
return;
}
if (false === $this->booted) {
return;
}
$container = $this->getContainer();
parent::shutdown();
$this->cleanupContainer($container);
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
@ -138,45 +112,4 @@ class Kernel extends BaseKernel
{
return 0 === strpos($this->getEnvironment(), 'test');
}
/**
* Remove all container references from all loaded services
*/
private function cleanupContainer(ContainerInterface $container): void
{
$containerReflection = new \ReflectionObject($container);
$containerServicesPropertyReflection = $containerReflection->getProperty('services');
$containerServicesPropertyReflection->setAccessible(true);
$services = $containerServicesPropertyReflection->getValue($container) ?: [];
foreach ($services as $serviceId => $service) {
if (null === $service) {
continue;
}
if (in_array($serviceId, self::IGNORED_SERVICES_DURING_CLEANUP, true)) {
continue;
}
$serviceReflection = new \ReflectionObject($service);
if ($serviceReflection->implementsInterface(VirtualProxyInterface::class)) {
continue;
}
$servicePropertiesReflections = $serviceReflection->getProperties();
$servicePropertiesDefaultValues = $serviceReflection->getDefaultProperties();
foreach ($servicePropertiesReflections as $servicePropertyReflection) {
$defaultPropertyValue = null;
if (isset($servicePropertiesDefaultValues[$servicePropertyReflection->getName()])) {
$defaultPropertyValue = $servicePropertiesDefaultValues[$servicePropertyReflection->getName()];
}
$servicePropertyReflection->setAccessible(true);
$servicePropertyReflection->setValue($service, $defaultPropertyValue);
}
}
$containerServicesPropertyReflection->setValue($container, []);
}
}