2323 */
2424class DoctrineExtractorTestextends TestCase
2525{
26- /**
27- * @var DoctrineExtractor
28- */
29- private $ extractor ;
30-
31- protected function setUp ()
26+ private function createExtractor (bool $ legacy =false )
3227 {
3328$ config = Setup::createAnnotationMetadataConfiguration (array (__DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' ),true );
3429$ entityManager = EntityManager::create (array ('driver ' =>'pdo_sqlite ' ),$ config );
@@ -38,10 +33,20 @@ protected function setUp()
3833$ entityManager ->getConnection ()->getDatabasePlatform ()->registerDoctrineTypeMapping ('custom_foo ' ,'foo ' );
3934 }
4035
41- $ this -> extractor = new DoctrineExtractor ($ entityManager ->getMetadataFactory ());
36+ return new DoctrineExtractor ($ legacy ? $ entityManager ->getMetadataFactory () : $ entityManager );
4237 }
4338
4439public 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 )
4550 {
4651$ this ->assertEquals (
4752array (
@@ -63,11 +68,21 @@ public function testGetProperties()
6368'indexedBar ' ,
6469'indexedFoo ' ,
6570 ),
66- $ this ->extractor ->getProperties ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy ' )
71+ $ this ->createExtractor ( $ legacy ) ->getProperties ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy ' )
6772 );
6873 }
6974
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 )
7186 {
7287if (!class_exists ('Doctrine\ORM\Mapping\Embedded ' )) {
7388$ this ->markTestSkipped ('@Embedded is not available in Doctrine ORM lower than 2.5. ' );
@@ -78,7 +93,7 @@ public function testGetPropertiesWithEmbedded()
7893'id ' ,
7994'embedded ' ,
8095 ),
81- $ this ->extractor ->getProperties ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded ' )
96+ $ this ->createExtractor ( $ legacy ) ->getProperties ('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded ' )
8297 );
8398 }
8499
@@ -87,10 +102,33 @@ public function testGetPropertiesWithEmbedded()
87102 */
88103public function testExtract ($ property ,array $ type =null )
89104 {
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 ()));
91119 }
92120
93121public 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 )
94132 {
95133if (!class_exists ('Doctrine\ORM\Mapping\Embedded ' )) {
96134$ this ->markTestSkipped ('@Embedded is not available in Doctrine ORM lower than 2.5. ' );
@@ -102,7 +140,7 @@ public function testExtractWithEmbedded()
102140'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineEmbeddable '
103141 ));
104142
105- $ actualTypes =$ this ->extractor ->getTypes (
143+ $ actualTypes =$ this ->createExtractor ( $ legacy ) ->getTypes (
106144'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded ' ,
107145'embedded ' ,
108146array ()
@@ -158,11 +196,31 @@ public function typesProvider()
158196
159197public function testGetPropertiesCatchException ()
160198 {
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 ' ));
162210 }
163211
164212public function testGetTypesCatchException ()
165213 {
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 ' ));
167225 }
168226}