-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
IntegrationTestKernel.php
89 lines (72 loc) · 2.36 KB
/
IntegrationTestKernel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
declare(strict_types=1);
namespace Doctrine\Bundle\FixturesBundle\Tests;
use Closure;
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\FooBundle;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use function rand;
use function sys_get_temp_dir;
class IntegrationTestKernel extends Kernel
{
private ?Closure $servicesCallback = null;
private int $randomKey;
public function __construct(string $environment, bool $debug)
{
$this->randomKey = rand(10000000000, 99999999999);
parent::__construct($environment, $debug);
}
protected function getContainerClass(): string
{
return 'test' . $this->randomKey . parent::getContainerClass();
}
/**
* {@inheritDoc}
*/
public function registerBundles(): array
{
return [
new DoctrineFixturesBundle(),
new FooBundle(),
];
}
public function addServices(Closure $callback): void
{
$this->servicesCallback = $callback;
}
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(function (ContainerBuilder $c): void {
if (! $c->hasDefinition('kernel')) {
$c->register('kernel', static::class)
->setSynthetic(true)
->setPublic(true);
}
$c->register('doctrine', ManagerRegistry::class);
$callback = $this->servicesCallback;
$callback($c);
$c->addObjectResource($this);
});
}
public function getCacheDir(): string
{
return sys_get_temp_dir() . '/doctrine_fixtures_bundle' . $this->randomKey;
}
public function getLogDir(): string
{
return sys_get_temp_dir();
}
protected function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new class implements CompilerPassInterface {
public function process(ContainerBuilder $container): void
{
$container->findDefinition('doctrine')->setPublic(true);
}
});
}
}