-
-
Notifications
You must be signed in to change notification settings - Fork 447
/
TestCase.php
93 lines (83 loc) · 3.93 KB
/
TestCase.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
90
91
92
93
<?php
namespace Doctrine\Bundle\DoctrineBundle\Tests;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheCompatibilityPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType;
use Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\Security\Core\User\UserInterface;
use function class_exists;
use function sys_get_temp_dir;
use function uniqid;
class TestCase extends BaseTestCase
{
public function createXmlBundleTestContainer(): ContainerBuilder
{
$container = new ContainerBuilder(new ParameterBag([
'kernel.debug' => false,
'kernel.bundles' => ['XmlBundle' => 'Fixtures\Bundles\XmlBundle\XmlBundle'],
'kernel.cache_dir' => sys_get_temp_dir(),
'kernel.environment' => 'test',
'kernel.root_dir' => __DIR__ . '/../../../../', // src dir
'kernel.project_dir' => __DIR__ . '/../../../../', // src dir
'kernel.bundles_metadata' => [],
'container.build_id' => uniqid(),
]));
if (class_exists(AnnotationReader::class)) {
$container->set('annotation_reader', new AnnotationReader());
}
$extension = new DoctrineExtension();
$container->registerExtension($extension);
$extension->load([
[
'dbal' => [
'connections' => [
'default' => [
'driver' => 'pdo_sqlite',
'charset' => 'UTF8',
'schema_manager_factory' => 'doctrine.dbal.default_schema_manager_factory',
],
],
'default_connection' => 'default',
'types' => [
'test' => [
'class' => TestType::class,
],
],
],
'orm' => [
'default_entity_manager' => 'default',
'entity_managers' => [
'default' => [
'validate_xml_mapping' => true,
'mappings' => [
'XmlBundle' => [
'type' => 'xml',
'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine',
'prefix' => 'Fixtures\Bundles\XmlBundle\Entity',
],
],
],
],
'resolve_target_entities' => [UserInterface::class => 'stdClass'],
],
],
], $container);
// Register dummy cache services so we don't have to load the FrameworkExtension
$container->setDefinition('cache.system', (new Definition(ArrayAdapter::class))->setPublic(true));
$container->setDefinition('cache.app', (new Definition(ArrayAdapter::class))->setPublic(true));
$compilerPassConfig = $container->getCompilerPassConfig();
$compilerPassConfig->setOptimizationPasses([new ResolveChildDefinitionsPass()]);
$compilerPassConfig->setRemovingPasses([]);
$compilerPassConfig->addPass(new CacheCompatibilityPass());
// make all Doctrine services public, so we can fetch them in the test
$compilerPassConfig->addPass(new TestCaseAllPublicCompilerPass());
$container->compile();
return $container;
}
}