mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Remove container cleanup in test environment
This commit is contained in:
parent
2401264739
commit
4f0f488b9d
2 changed files with 18 additions and 77 deletions
20
.travis.yml
20
.travis.yml
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue