Skip to content

Commit

Permalink
Merge branch '1.2' into 1.3
Browse files Browse the repository at this point in the history
* 1.2:
  Remove container cleanup in test environment
  • Loading branch information
pamil committed Jan 11, 2019
2 parents b0bb533 + 22dbc5b commit 7c22e40
Showing 1 changed file with 0 additions and 68 deletions.
68 changes: 0 additions & 68 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace App;

use ProxyManager\Proxy\VirtualProxyInterface;
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\DelegatingLoader;
Expand All @@ -40,13 +39,6 @@ final 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;
Expand All @@ -67,25 +59,6 @@ public function registerBundles(): iterable
}
}

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'));
Expand Down Expand Up @@ -139,45 +112,4 @@ private function isTestEnvironment(): bool
{
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, []);
}
}

0 comments on commit 7c22e40

Please sign in to comment.