1313
1414use Doctrine \Bundle \PHPCRBundle \Initializer \InitializerManager ;
1515use Doctrine \Bundle \PHPCRBundle \ManagerRegistryInterface ;
16+ use Doctrine \Bundle \PHPCRBundle \Test \RepositoryManager ;
1617use PHPUnit \Framework \MockObject \MockObject ;
1718use PHPUnit \Framework \TestCase ;
1819use Symfony \Bundle \FrameworkBundle \KernelBrowser ;
1920use Symfony \Cmf \Component \Testing \Functional \BaseTestCase ;
21+ use Symfony \Cmf \Component \Testing \Functional \DbManager \PHPCR ;
2022use Symfony \Cmf \Component \Testing \Tests \Fixtures \TestTestCase ;
2123use Symfony \Component \DependencyInjection \Container ;
2224use Symfony \Component \HttpKernel \KernelInterface ;
@@ -53,6 +55,7 @@ protected function setUp(): void
5355 ->willReturnCallback (function ($ name ) use ($ managerRegistry , $ initializerManager ) {
5456 $ dic = [
5557 'test.client ' => $ this ->client ,
58+ 'test.service_container ' => $ this ->container ,
5659 'doctrine_phpcr ' => $ managerRegistry ,
5760 'doctrine_phpcr.initializer_manager ' => $ initializerManager ,
5861 ];
@@ -74,6 +77,7 @@ protected function setUp(): void
7477 $ this ->testCase ->setKernel ($ this ->kernel );
7578
7679 $ this ->client = $ this ->createMock (KernelBrowser::class);
80+
7781 $ this ->client
7882 ->method ('getContainer ' )
7983 ->willReturn ($ this ->container );
@@ -83,7 +87,6 @@ public function testGetKernel(): void
8387 {
8488 $ class = new \ReflectionClass (BaseTestCase::class);
8589 $ method = $ class ->getMethod ('getKernel ' );
86- $ method ->setAccessible (true );
8790
8891 $ this ->assertInstanceOf (KernelInterface::class, $ method ->invoke (null ));
8992 }
@@ -92,8 +95,47 @@ public function testItCanProvideAFrameworkBundleClient(): void
9295 {
9396 $ class = new \ReflectionClass (BaseTestCase::class);
9497 $ method = $ class ->getMethod ('getFrameworkBundleClient ' );
95- $ method ->setAccessible (true );
9698
9799 $ this ->assertInstanceOf (KernelBrowser::class, $ method ->invoke ($ this ->testCase ));
98100 }
101+
102+ public function provideTestDb ()
103+ {
104+ return [
105+ ['PHPCR ' , 'PHPCR ' ],
106+ ['Phpcr ' , 'PHPCR ' ],
107+ ['ORM ' , 'ORM ' ],
108+ ['foobar ' , null ],
109+ ];
110+ }
111+
112+ /**
113+ * @dataProvider provideTestDb
114+ */
115+ public function testDb ($ dbName , $ expected )
116+ {
117+ $ class = new \ReflectionClass (BaseTestCase::class);
118+ $ method = $ class ->getMethod ('getDbManager ' );
119+
120+ if (null === $ expected ) {
121+ $ this ->expectException ('InvalidArgumentException ' );
122+ $ this ->expectExceptionMessage ($ dbName .'" does not exist ' );
123+ }
124+
125+ $ res = $ method ->invoke ($ this ->testCase , $ dbName );
126+ if (null === $ expected ) {
127+ // do not do assertions if the expected exception has not been thrown.
128+ return ;
129+ }
130+
131+ $ className = sprintf (
132+ 'Symfony\Cmf\Component\Testing\Functional\DbManager\%s ' ,
133+ $ expected
134+ );
135+ if (PHPCR ::class === $ className && class_exists (RepositoryManager::class)) {
136+ $ className = RepositoryManager::class;
137+ }
138+
139+ $ this ->assertInstanceOf ($ className , $ res );
140+ }
99141}
0 commit comments