23
23
*/
24
24
class DoctrineExtractorTest extends TestCase
25
25
{
26
- /**
27
- * @var DoctrineExtractor
28
- */
29
- private $ extractor ;
30
-
31
- protected function setUp ()
26
+ private function createExtractor (bool $ legacy = false )
32
27
{
33
28
$ config = Setup::createAnnotationMetadataConfiguration (array (__DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' ), true );
34
29
$ entityManager = EntityManager::create (array ('driver ' => 'pdo_sqlite ' ), $ config );
@@ -38,10 +33,20 @@ protected function setUp()
38
33
$ entityManager ->getConnection ()->getDatabasePlatform ()->registerDoctrineTypeMapping ('custom_foo ' , 'foo ' );
39
34
}
40
35
41
- $ this -> extractor = new DoctrineExtractor ($ entityManager ->getMetadataFactory ());
36
+ return new DoctrineExtractor ($ legacy ? $ entityManager ->getMetadataFactory () : $ entityManager );
42
37
}
43
38
44
39
public function testGetProperties ()
40
+ {
41
+ $ this ->doTestGetProperties (false );
42
+ }
43
+
44
+ public function testLegacyGetProperties ()
45
+ {
46
+ $ this ->doTestGetProperties (true );
47
+ }
48
+
49
+ private function doTestGetProperties (bool $ legacy )
45
50
{
46
51
$ this ->assertEquals (
47
52
array (
@@ -63,11 +68,21 @@ public function testGetProperties()
63
68
'indexedBar ' ,
64
69
'indexedFoo ' ,
65
70
),
66
- $ this ->extractor ->getProperties ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy ' )
71
+ $ this ->createExtractor ( $ legacy ) ->getProperties ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy ' )
67
72
);
68
73
}
69
74
70
- public function testGetPropertiesWithEmbedded ()
75
+ public function testTestGetPropertiesWithEmbedded ()
76
+ {
77
+ $ this ->doTestGetPropertiesWithEmbedded (false );
78
+ }
79
+
80
+ public function testLegacyTestGetPropertiesWithEmbedded ()
81
+ {
82
+ $ this ->doTestGetPropertiesWithEmbedded (true );
83
+ }
84
+
85
+ private function doTestGetPropertiesWithEmbedded (bool $ legacy )
71
86
{
72
87
if (!class_exists ('Doctrine\ORM\Mapping\Embedded ' )) {
73
88
$ this ->markTestSkipped ('@Embedded is not available in Doctrine ORM lower than 2.5. ' );
@@ -78,7 +93,7 @@ public function testGetPropertiesWithEmbedded()
78
93
'id ' ,
79
94
'embedded ' ,
80
95
),
81
- $ this ->extractor ->getProperties ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded ' )
96
+ $ this ->createExtractor ( $ legacy ) ->getProperties ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded ' )
82
97
);
83
98
}
84
99
@@ -87,10 +102,32 @@ public function testGetPropertiesWithEmbedded()
87
102
*/
88
103
public function testExtract ($ property , array $ type = null )
89
104
{
90
- $ this ->assertEquals ($ type , $ this ->extractor ->getTypes ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy ' , $ property , array ()));
105
+ $ this ->doTestExtract (false , $ property , $ type );
106
+ }
107
+ /**
108
+ * @dataProvider typesProvider
109
+ */
110
+ public function testLegacyExtract ($ property , array $ type = null )
111
+ {
112
+ $ this ->doTestExtract (true , $ property , $ type );
113
+ }
114
+
115
+ private function doTestExtract (bool $ legacy , $ property , array $ type = null )
116
+ {
117
+ $ this ->assertEquals ($ type , $ this ->createExtractor ($ legacy )->getTypes ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy ' , $ property , array ()));
91
118
}
92
119
93
120
public function testExtractWithEmbedded ()
121
+ {
122
+ $ this ->doTestExtractWithEmbedded (false );
123
+ }
124
+
125
+ public function testLegacyExtractWithEmbedded ()
126
+ {
127
+ $ this ->doTestExtractWithEmbedded (true );
128
+ }
129
+
130
+ private function doTestExtractWithEmbedded (bool $ legacy )
94
131
{
95
132
if (!class_exists ('Doctrine\ORM\Mapping\Embedded ' )) {
96
133
$ this ->markTestSkipped ('@Embedded is not available in Doctrine ORM lower than 2.5. ' );
@@ -102,7 +139,7 @@ public function testExtractWithEmbedded()
102
139
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineEmbeddable '
103
140
));
104
141
105
- $ actualTypes = $ this ->extractor ->getTypes (
142
+ $ actualTypes = $ this ->createExtractor ( $ legacy ) ->getTypes (
106
143
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded ' ,
107
144
'embedded ' ,
108
145
array ()
@@ -158,11 +195,31 @@ public function typesProvider()
158
195
159
196
public function testGetPropertiesCatchException ()
160
197
{
161
- $ this ->assertNull ($ this ->extractor ->getProperties ('Not\Exist ' ));
198
+ $ this ->doTestGetPropertiesCatchException (false );
199
+ }
200
+
201
+ public function testLegacyGetPropertiesCatchException ()
202
+ {
203
+ $ this ->doTestGetPropertiesCatchException (true );
204
+ }
205
+
206
+ private function doTestGetPropertiesCatchException (bool $ legacy )
207
+ {
208
+ $ this ->assertNull ($ this ->createExtractor ($ legacy )->getProperties ('Not\Exist ' ));
162
209
}
163
210
164
211
public function testGetTypesCatchException ()
165
212
{
166
- $ this ->assertNull ($ this ->extractor ->getTypes ('Not\Exist ' , 'baz ' ));
213
+ return $ this ->doTestGetTypesCatchException (false );
214
+ }
215
+
216
+ public function testLegacyGetTypesCatchException ()
217
+ {
218
+ return $ this ->doTestGetTypesCatchException (true );
219
+ }
220
+
221
+ private function doTestGetTypesCatchException (bool $ legacy )
222
+ {
223
+ $ this ->assertNull ($ this ->createExtractor ($ legacy )->getTypes ('Not\Exist ' , 'baz ' ));
167
224
}
168
225
}
0 commit comments