13
13
14
14
use Doctrine \Bundle \PHPCRBundle \Initializer \InitializerManager ;
15
15
use Doctrine \Bundle \PHPCRBundle \ManagerRegistryInterface ;
16
+ use Doctrine \Bundle \PHPCRBundle \Test \RepositoryManager ;
16
17
use PHPUnit \Framework \MockObject \MockObject ;
17
18
use PHPUnit \Framework \TestCase ;
18
19
use Symfony \Bundle \FrameworkBundle \KernelBrowser ;
@@ -53,6 +54,7 @@ protected function setUp(): void
53
54
->willReturnCallback (function ($ name ) use ($ managerRegistry , $ initializerManager ) {
54
55
$ dic = [
55
56
'test.client ' => $ this ->client ,
57
+ 'test.service_container ' => $ this ->container ,
56
58
'doctrine_phpcr ' => $ managerRegistry ,
57
59
'doctrine_phpcr.initializer_manager ' => $ initializerManager ,
58
60
];
@@ -74,6 +76,7 @@ protected function setUp(): void
74
76
$ this ->testCase ->setKernel ($ this ->kernel );
75
77
76
78
$ this ->client = $ this ->createMock (KernelBrowser::class);
79
+
77
80
$ this ->client
78
81
->method ('getContainer ' )
79
82
->willReturn ($ this ->container );
@@ -96,4 +99,45 @@ public function testItCanProvideAFrameworkBundleClient(): void
96
99
97
100
$ this ->assertInstanceOf (KernelBrowser::class, $ method ->invoke ($ this ->testCase ));
98
101
}
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
+ }
99
143
}
0 commit comments