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 ;
19
20
use Symfony \Cmf \Component \Testing \Functional \BaseTestCase ;
21
+ use Symfony \Cmf \Component \Testing \Functional \DbManager \PHPCR ;
20
22
use Symfony \Cmf \Component \Testing \Tests \Fixtures \TestTestCase ;
21
23
use Symfony \Component \DependencyInjection \Container ;
22
24
use Symfony \Component \HttpKernel \KernelInterface ;
@@ -53,6 +55,7 @@ protected function setUp(): void
53
55
->willReturnCallback (function ($ name ) use ($ managerRegistry , $ initializerManager ) {
54
56
$ dic = [
55
57
'test.client ' => $ this ->client ,
58
+ 'test.service_container ' => $ this ->container ,
56
59
'doctrine_phpcr ' => $ managerRegistry ,
57
60
'doctrine_phpcr.initializer_manager ' => $ initializerManager ,
58
61
];
@@ -74,6 +77,7 @@ protected function setUp(): void
74
77
$ this ->testCase ->setKernel ($ this ->kernel );
75
78
76
79
$ this ->client = $ this ->createMock (KernelBrowser::class);
80
+
77
81
$ this ->client
78
82
->method ('getContainer ' )
79
83
->willReturn ($ this ->container );
@@ -83,7 +87,6 @@ public function testGetKernel(): void
83
87
{
84
88
$ class = new \ReflectionClass (BaseTestCase::class);
85
89
$ method = $ class ->getMethod ('getKernel ' );
86
- $ method ->setAccessible (true );
87
90
88
91
$ this ->assertInstanceOf (KernelInterface::class, $ method ->invoke (null ));
89
92
}
@@ -92,8 +95,47 @@ public function testItCanProvideAFrameworkBundleClient(): void
92
95
{
93
96
$ class = new \ReflectionClass (BaseTestCase::class);
94
97
$ method = $ class ->getMethod ('getFrameworkBundleClient ' );
95
- $ method ->setAccessible (true );
96
98
97
99
$ this ->assertInstanceOf (KernelBrowser::class, $ method ->invoke ($ this ->testCase ));
98
100
}
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
+ }
99
141
}
0 commit comments