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
- $ config = Setup::createAnnotationMetadataConfiguration (array (__DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' ), true );
28
+ $ config = Setup::createAnnotationMetadataConfiguration (array (__DIR__ .\ DIRECTORY_SEPARATOR .'Fixtures ' ), true );
34
29
$ entityManager = EntityManager::create (array ('driver ' => 'pdo_sqlite ' ), $ config );
35
30
36
31
if (!DBALType::hasType ('foo ' )) {
37
32
DBALType::addType ('foo ' , 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineFooType ' );
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,33 @@ 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
+ /**
109
+ * @dataProvider typesProvider
110
+ */
111
+ public function testLegacyExtract ($ property , array $ type = null )
112
+ {
113
+ $ this ->doTestExtract (true , $ property , $ type );
114
+ }
115
+
116
+ private function doTestExtract (bool $ legacy , $ property , array $ type = null )
117
+ {
118
+ $ this ->assertEquals ($ type , $ this ->createExtractor ($ legacy )->getTypes ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy ' , $ property , array ()));
91
119
}
92
120
93
121
public function testExtractWithEmbedded ()
122
+ {
123
+ $ this ->doTestExtractWithEmbedded (false );
124
+ }
125
+
126
+ public function testLegacyExtractWithEmbedded ()
127
+ {
128
+ $ this ->doTestExtractWithEmbedded (true );
129
+ }
130
+
131
+ private function doTestExtractWithEmbedded (bool $ legacy )
94
132
{
95
133
if (!class_exists ('Doctrine\ORM\Mapping\Embedded ' )) {
96
134
$ this ->markTestSkipped ('@Embedded is not available in Doctrine ORM lower than 2.5. ' );
@@ -102,7 +140,7 @@ public function testExtractWithEmbedded()
102
140
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineEmbeddable '
103
141
));
104
142
105
- $ actualTypes = $ this ->extractor ->getTypes (
143
+ $ actualTypes = $ this ->createExtractor ( $ legacy ) ->getTypes (
106
144
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded ' ,
107
145
'embedded ' ,
108
146
array ()
@@ -158,11 +196,31 @@ public function typesProvider()
158
196
159
197
public function testGetPropertiesCatchException ()
160
198
{
161
- $ this ->assertNull ($ this ->extractor ->getProperties ('Not\Exist ' ));
199
+ $ this ->doTestGetPropertiesCatchException (false );
200
+ }
201
+
202
+ public function testLegacyGetPropertiesCatchException ()
203
+ {
204
+ $ this ->doTestGetPropertiesCatchException (true );
205
+ }
206
+
207
+ private function doTestGetPropertiesCatchException (bool $ legacy )
208
+ {
209
+ $ this ->assertNull ($ this ->createExtractor ($ legacy )->getProperties ('Not\Exist ' ));
162
210
}
163
211
164
212
public function testGetTypesCatchException ()
165
213
{
166
- $ this ->assertNull ($ this ->extractor ->getTypes ('Not\Exist ' , 'baz ' ));
214
+ return $ this ->doTestGetTypesCatchException (false );
215
+ }
216
+
217
+ public function testLegacyGetTypesCatchException ()
218
+ {
219
+ return $ this ->doTestGetTypesCatchException (true );
220
+ }
221
+
222
+ private function doTestGetTypesCatchException (bool $ legacy )
223
+ {
224
+ $ this ->assertNull ($ this ->createExtractor ($ legacy )->getTypes ('Not\Exist ' , 'baz ' ));
167
225
}
168
226
}
0 commit comments