Remove container cleanup in test environment

This commit is contained in:
Mateusz Zalewski 2019-01-11 08:56:19 +01:00
parent 2401264739
commit 4f0f488b9d
No known key found for this signature in database
GPG key ID: 0545A7503DD474B8
2 changed files with 18 additions and 77 deletions

View file

@ -55,13 +55,20 @@ matrix:
- SYMFONY_VERSION="3.4.*"
services:
- memcached
-
- if: type IN (cron, api) OR tag IS present
php: 7.2
env:
- SYLIUS_SUITE="application"
- SYMFONY_VERSION="4.1.*"
services:
- memcached
-
php: 7.2
env:
- SYLIUS_SUITE="application"
- SYMFONY_VERSION="4.2.*"
services:
- memcached
-
if: type IN (cron, api) OR tag IS present
php: 7.2
@ -72,7 +79,7 @@ matrix:
apt:
packages:
- parallel
-
- if: type IN (cron, api) OR tag IS present
php: 7.2
env:
- SYLIUS_SUITE="packages"
@ -81,6 +88,15 @@ matrix:
apt:
packages:
- parallel
-
php: 7.2
env:
- SYLIUS_SUITE="packages"
- SYMFONY_VERSION="4.2.*"
addons:
apt:
packages:
- parallel
cache:
yarn: true

View file

@ -13,87 +13,12 @@ declare(strict_types=1);
require_once __DIR__ . '/AppKernel.php';
use ProxyManager\Proxy\VirtualProxyInterface;
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TestAppKernel extends AppKernel
{
/**
* {@inheritdoc}
*/
public function shutdown(): void
{
if (false === $this->booted) {
return;
}
if (!in_array($this->getEnvironment(), ['test', 'test_cached'], true)) {
parent::shutdown();
return;
}
$container = $this->getContainer();
parent::shutdown();
$this->cleanupContainer($container);
}
/**
* Remove all container references from all loaded services
*
* @param ContainerInterface $container
*/
protected 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, $this->getServicesToIgnoreDuringContainerCleanup(), 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, null);
}
protected function getContainerBaseClass(): string
{
return MockerContainer::class;
}
protected function getServicesToIgnoreDuringContainerCleanup(): array
{
return [
'kernel',
'http_kernel',
'liip_imagine.mime_type_guesser',
'liip_imagine.extension_guesser',
];
}
}