11
11
12
12
namespace Symfony \Bundle \MakerBundle \Tests \Doctrine ;
13
13
14
+ use Doctrine \Bundle \DoctrineBundle \DependencyInjection \DoctrineExtension ;
14
15
use Doctrine \Bundle \DoctrineBundle \DoctrineBundle ;
15
16
use Doctrine \Persistence \ManagerRegistry ;
16
17
use PHPUnit \Framework \TestCase ;
@@ -156,6 +157,7 @@ private function createAllButTraitsIterator(string $sourceDir): \Iterator
156
157
class TestEntityRegeneratorKernel extends Kernel
157
158
{
158
159
use MicroKernelTrait;
160
+ use OverrideUrlTraitFixture;
159
161
160
162
public function registerBundles ()
161
163
{
@@ -178,11 +180,17 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
178
180
],
179
181
]);
180
182
183
+ $ dbal = [
184
+ 'driver ' => 'pdo_sqlite ' ,
185
+ 'url ' => 'sqlite:///fake ' ,
186
+ ];
187
+
188
+ if ($ this ->canOverrideUrl ($ c )) {
189
+ $ dbal ['override_url ' ] = true ;
190
+ }
191
+
181
192
$ c ->prependExtensionConfig ('doctrine ' , [
182
- 'dbal ' => [
183
- 'driver ' => 'pdo_sqlite ' ,
184
- 'url ' => 'sqlite:///fake ' ,
185
- ],
193
+ 'dbal ' => $ dbal ,
186
194
'orm ' => [
187
195
'mappings ' => [
188
196
'EntityRegenerator ' => [
@@ -211,6 +219,7 @@ public function getRootDir()
211
219
class TestXmlEntityRegeneratorKernel extends Kernel
212
220
{
213
221
use MicroKernelTrait;
222
+ use OverrideUrlTraitFixture;
214
223
215
224
public function registerBundles ()
216
225
{
@@ -233,11 +242,17 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
233
242
],
234
243
]);
235
244
245
+ $ dbal = [
246
+ 'driver ' => 'pdo_sqlite ' ,
247
+ 'url ' => 'sqlite:///fake ' ,
248
+ ];
249
+
250
+ if ($ this ->canOverrideUrl ($ c )) {
251
+ $ dbal ['override_url ' ] = true ;
252
+ }
253
+
236
254
$ c ->prependExtensionConfig ('doctrine ' , [
237
- 'dbal ' => [
238
- 'driver ' => 'pdo_sqlite ' ,
239
- 'url ' => 'sqlite:///fake ' ,
240
- ],
255
+ 'dbal ' => $ dbal ,
241
256
'orm ' => [
242
257
'auto_generate_proxy_classes ' => true ,
243
258
'mappings ' => [
@@ -271,3 +286,21 @@ public function accept()
271
286
return !\in_array ($ this ->current ()->getFilename (), []);
272
287
}
273
288
}
289
+
290
+ trait OverrideUrlTraitFixture
291
+ {
292
+ /**
293
+ * Quick and dirty way to check if override_url is required since doctrine-bundle 2.3.
294
+ */
295
+ public function canOverrideUrl (ContainerBuilder $ builder ): bool
296
+ {
297
+ /** @var DoctrineExtension $ext */
298
+ $ ext = $ builder ->getExtension ('doctrine ' );
299
+ $ method = new \ReflectionMethod (DoctrineExtension::class, 'getConnectionOptions ' );
300
+ $ method ->setAccessible (true );
301
+
302
+ $ configOptions = $ method ->invoke ($ ext , ['override_url ' => 'string ' , 'shards ' => [], 'replicas ' => [], 'slaves ' => []]);
303
+
304
+ return \array_key_exists ('connection_override_options ' , $ configOptions );
305
+ }
306
+ }
0 commit comments