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 ;
@@ -53,6 +54,7 @@ protected function setUp(): void
5354 ->willReturnCallback (function ($ name ) use ($ managerRegistry , $ initializerManager ) {
5455 $ dic = [
5556 'test.client ' => $ this ->client ,
57+ 'test.service_container ' => $ this ->container ,
5658 'doctrine_phpcr ' => $ managerRegistry ,
5759 'doctrine_phpcr.initializer_manager ' => $ initializerManager ,
5860 ];
@@ -74,6 +76,7 @@ protected function setUp(): void
7476 $ this ->testCase ->setKernel ($ this ->kernel );
7577
7678 $ this ->client = $ this ->createMock (KernelBrowser::class);
79+
7780 $ this ->client
7881 ->method ('getContainer ' )
7982 ->willReturn ($ this ->container );
@@ -96,4 +99,45 @@ public function testItCanProvideAFrameworkBundleClient(): void
9699
97100 $ this ->assertInstanceOf (KernelBrowser::class, $ method ->invoke ($ this ->testCase ));
98101 }
102+
103+ public function provideTestDb ()
104+ {
105+ return [
106+ ['PHPCR ' , 'PHPCR ' ],
107+ ['Phpcr ' , 'PHPCR ' ],
108+ ['ORM ' , 'ORM ' ],
109+ ['foobar ' , null ],
110+ ];
111+ }
112+
113+ /**
114+ * @dataProvider provideTestDb
115+ */
116+ public function testDb ($ dbName , $ expected )
117+ {
118+ $ class = new \ReflectionClass (BaseTestCase::class);
119+ $ method = $ class ->getMethod ('getDbManager ' );
120+ $ method ->setAccessible (true );
121+
122+ if (null === $ expected ) {
123+ $ this ->expectException ('InvalidArgumentException ' );
124+ $ this ->expectExceptionMessage ($ dbName .'" does not exist ' );
125+ }
126+
127+ $ res = $ method ->invoke ($ this ->testCase , $ dbName );
128+ if (null === $ expected ) {
129+ // do not do assertions if the expected exception has not been thrown.
130+ return ;
131+ }
132+
133+ $ className = sprintf (
134+ 'Symfony\Cmf\Component\Testing\Functional\DbManager\%s ' ,
135+ $ expected
136+ );
137+ if (PHPCR ::class === $ className && class_exists (RepositoryManager::class)) {
138+ $ className = RepositoryManager::class;
139+ }
140+
141+ $ this ->assertInstanceOf ($ className , $ res );
142+ }
99143}
0 commit comments