|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; |
|
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType; |
|
7
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
|
8
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
|
15
|
|
|
|
|
16
|
|
|
class TestCase extends BaseTestCase |
|
17
|
|
|
{ |
|
18
|
|
|
protected function setUp() |
|
19
|
|
|
{ |
|
20
|
|
|
if (! class_exists('Doctrine\\Common\\Version')) { |
|
21
|
|
|
$this->markTestSkipped('Doctrine is not available.'); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function createYamlBundleTestContainer() |
|
26
|
|
|
{ |
|
27
|
|
|
$container = new ContainerBuilder(new ParameterBag([ |
|
28
|
|
|
'kernel.name' => 'app', |
|
29
|
|
|
'kernel.debug' => false, |
|
30
|
|
|
'kernel.bundles' => ['YamlBundle' => 'Fixtures\Bundles\YamlBundle\YamlBundle'], |
|
31
|
|
|
'kernel.cache_dir' => sys_get_temp_dir(), |
|
32
|
|
|
'kernel.environment' => 'test', |
|
33
|
|
|
'kernel.root_dir' => __DIR__ . '/../../../../', // src dir |
|
34
|
|
|
])); |
|
35
|
|
|
$container->set('annotation_reader', new AnnotationReader()); |
|
36
|
|
|
$extension = new DoctrineExtension(); |
|
37
|
|
|
$container->registerExtension($extension); |
|
38
|
|
|
$extension->load([[ |
|
39
|
|
|
'dbal' => [ |
|
40
|
|
|
'connections' => [ |
|
41
|
|
|
'default' => [ |
|
42
|
|
|
'driver' => 'pdo_mysql', |
|
43
|
|
|
'charset' => 'UTF8', |
|
44
|
|
|
'platform-service' => 'my.platform', |
|
45
|
|
|
], |
|
46
|
|
|
], |
|
47
|
|
|
'default_connection' => 'default', |
|
48
|
|
|
'types' => [ |
|
49
|
|
|
'test' => TestType::class, |
|
50
|
|
|
], |
|
51
|
|
|
], 'orm' => [ |
|
52
|
|
|
'default_entity_manager' => 'default', |
|
53
|
|
|
'entity_managers' => [ |
|
54
|
|
|
'default' => [ |
|
55
|
|
|
'mappings' => [ |
|
56
|
|
|
'YamlBundle' => [ |
|
57
|
|
|
'type' => 'yml', |
|
58
|
|
|
'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine', |
|
59
|
|
|
'prefix' => 'Fixtures\Bundles\YamlBundle\Entity', |
|
60
|
|
|
], |
|
61
|
|
|
], |
|
62
|
|
|
], |
|
63
|
|
|
], |
|
64
|
|
|
'resolve_target_entities' => ['Symfony\Component\Security\Core\User\UserInterface' => 'stdClass'], |
|
65
|
|
|
], |
|
66
|
|
|
], |
|
67
|
|
|
], $container); |
|
68
|
|
|
|
|
69
|
|
|
$container->setDefinition('my.platform', new Definition('Doctrine\DBAL\Platforms\MySqlPlatform')); |
|
70
|
|
|
|
|
71
|
|
|
$container->getCompilerPassConfig()->setOptimizationPasses([class_exists(ResolveChildDefinitionsPass::class) ? new ResolveChildDefinitionsPass() : new ResolveDefinitionTemplatesPass()]); |
|
|
|
|
|
|
72
|
|
|
$container->getCompilerPassConfig()->setRemovingPasses([]); |
|
73
|
|
|
// make all Doctrine services public, so we can fetch them in the test |
|
74
|
|
|
$container->getCompilerPassConfig()->addPass(new TestCaseAllPublicCompilerPass()); |
|
75
|
|
|
$container->compile(); |
|
76
|
|
|
|
|
77
|
|
|
return $container; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
class TestCaseAllPublicCompilerPass implements CompilerPassInterface |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
public function process(ContainerBuilder $container) |
|
84
|
|
|
{ |
|
85
|
|
|
foreach ($container->getDefinitions() as $id => $definition) { |
|
86
|
|
|
if (false !== strpos($id, 'doctrine')) { |
|
87
|
|
|
$definition->setPublic(true); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
foreach ($container->getAliases() as $id => $alias) { |
|
92
|
|
|
if (false !== strpos($id, 'doctrine')) { |
|
93
|
|
|
$alias->setPublic(true); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: