|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright 2011 Johannes M. Schmitt <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace JMS\SerializerBundle\Tests\DependencyInjection; |
|
20
|
|
|
|
|
21
|
|
|
use JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass; |
|
22
|
|
|
use JMS\SerializerBundle\DependencyInjection\JMSSerializerExtension; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass; |
|
24
|
|
|
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass; |
|
25
|
|
|
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; |
|
26
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
27
|
|
|
|
|
28
|
|
|
class DoctrinePassTest extends \PHPUnit_Framework_TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
* @param array $configs |
|
33
|
|
|
* @return ContainerBuilder |
|
34
|
|
|
*/ |
|
35
|
|
|
private function getContainer(array $configs = array()) |
|
36
|
|
|
{ |
|
37
|
|
|
$loader = new JMSSerializerExtension(); |
|
38
|
|
|
$container = new ContainerBuilder(); |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$container->getCompilerPassConfig()->setOptimizationPasses(array( |
|
42
|
|
|
new ResolveParameterPlaceHoldersPass(), |
|
43
|
|
|
new ResolveDefinitionTemplatesPass(), |
|
44
|
|
|
)); |
|
45
|
|
|
$container->getCompilerPassConfig()->setRemovingPasses(array(new RemoveUnusedDefinitionsPass())); |
|
46
|
|
|
|
|
47
|
|
|
$container->setParameter('kernel.debug', true); |
|
48
|
|
|
$container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer'); |
|
49
|
|
|
$container->setParameter('kernel.bundles', array()); |
|
50
|
|
|
|
|
51
|
|
|
$loader->load(['jms_serializer' => $configs], $container); |
|
52
|
|
|
return $container; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testDoctrineDisabled() |
|
56
|
|
|
{ |
|
57
|
|
|
$container = $this->getContainer(array( |
|
58
|
|
|
'metadata' => array('infer_types_from_doctrine_metadata' => false) |
|
59
|
|
|
)); |
|
60
|
|
|
$container->register('doctrine.orm.entity_manager'); |
|
61
|
|
|
|
|
62
|
|
|
$pass = new DoctrinePass(); |
|
63
|
|
|
$pass->process($container); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertEquals('jms_serializer.unserialize_object_constructor', (string)$container->getAlias('jms_serializer.object_constructor')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testOrm() |
|
69
|
|
|
{ |
|
70
|
|
|
$container = $this->getContainer(); |
|
71
|
|
|
$container->register('doctrine.orm.entity_manager'); |
|
72
|
|
|
|
|
73
|
|
|
$pass = new DoctrinePass(); |
|
74
|
|
|
$pass->process($container); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertEquals('jms_serializer.doctrine_object_constructor', (string)$container->getAlias('jms_serializer.object_constructor')); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testOdm() |
|
80
|
|
|
{ |
|
81
|
|
|
$container = $this->getContainer(); |
|
82
|
|
|
$container->register('doctrine_phpcr.odm.document_manager'); |
|
83
|
|
|
|
|
84
|
|
|
$pass = new DoctrinePass(); |
|
85
|
|
|
$pass->process($container); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals('jms_serializer.doctrine_phpcr_object_constructor', (string)$container->getAlias('jms_serializer.object_constructor')); |
|
88
|
|
|
|
|
89
|
|
|
$def = $container->getDefinition('jms_serializer.doctrine_phpcr_object_constructor'); |
|
90
|
|
|
$this->assertEquals('jms_serializer.unserialize_object_constructor', (string)$def->getArgument(1)); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testOrmAndOdm() |
|
94
|
|
|
{ |
|
95
|
|
|
$container = $this->getContainer(); |
|
96
|
|
|
|
|
97
|
|
|
$container->register('doctrine_phpcr.odm.document_manager'); |
|
98
|
|
|
$container->register('doctrine.orm.entity_manager'); |
|
99
|
|
|
|
|
100
|
|
|
$pass = new DoctrinePass(); |
|
101
|
|
|
$pass->process($container); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertEquals('jms_serializer.doctrine_object_constructor', (string)$container->getAlias('jms_serializer.object_constructor')); |
|
104
|
|
|
|
|
105
|
|
|
$def = $container->getDefinition('jms_serializer.doctrine_object_constructor'); |
|
106
|
|
|
$this->assertEquals('jms_serializer.doctrine_phpcr_object_constructor', (string)$def->getArgument(1)); |
|
107
|
|
|
|
|
108
|
|
|
$def = $container->getDefinition('jms_serializer.doctrine_phpcr_object_constructor'); |
|
109
|
|
|
$this->assertEquals('jms_serializer.unserialize_object_constructor', (string)$def->getArgument(1)); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|