1515use Doctrine \DBAL \Sharding \PoolingShardConnection ;
1616use Doctrine \DBAL \Sharding \ShardChoser \MultiTenantShardChoser ;
1717use Doctrine \Tests \DbalTestCase ;
18- use PDO ;
1918use stdClass ;
20- use function extension_loaded ;
2119use function get_class ;
2220use function in_array ;
2321use function is_array ;
2422
2523class DriverManagerTest extends DbalTestCase
2624{
27- /**
28- * @requires extension pdo_sqlite
29- */
30- public function testInvalidPdoInstance () : void
31- {
32- $ this ->expectException (DBALException::class);
33- DriverManager::getConnection (['pdo ' => 'test ' ]);
34- }
35-
36- /**
37- * @requires extension pdo_sqlite
38- */
39- public function testValidPdoInstance () : void
40- {
41- $ conn = DriverManager::getConnection ([
42- 'pdo ' => new PDO ('sqlite::memory: ' ),
43- ]);
44-
45- self ::assertEquals ('sqlite ' , $ conn ->getDatabasePlatform ()->getName ());
46- }
47-
48- /**
49- * @group DBAL-32
50- * @requires extension pdo_sqlite
51- */
52- public function testPdoInstanceSetErrorMode () : void
53- {
54- $ pdo = new PDO ('sqlite::memory: ' );
55- $ pdo ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_SILENT );
56- $ options = ['pdo ' => $ pdo ];
57-
58- DriverManager::getConnection ($ options );
59- self ::assertEquals (PDO ::ERRMODE_EXCEPTION , $ pdo ->getAttribute (PDO ::ATTR_ERRMODE ));
60- }
61-
6225 public function testCheckParams () : void
6326 {
6427 $ this ->expectException (DBALException::class);
@@ -80,7 +43,7 @@ public function testCustomPlatform() : void
8043 {
8144 $ platform = $ this ->createMock (AbstractPlatform::class);
8245 $ options = [
83- 'pdo ' => new PDO ( 'sqlite::memory: ' ) ,
46+ 'url ' => 'sqlite::memory: ' ,
8447 'platform ' => $ platform ,
8548 ];
8649
@@ -97,7 +60,7 @@ public function testCustomWrapper() : void
9760 $ wrapperClass = get_class ($ wrapper );
9861
9962 $ options = [
100- 'pdo ' => new PDO ( 'sqlite::memory: ' ) ,
63+ 'url ' => 'sqlite::memory: ' ,
10164 'wrapperClass ' => $ wrapperClass ,
10265 ];
10366
@@ -113,7 +76,7 @@ public function testInvalidWrapperClass() : void
11376 $ this ->expectException (DBALException::class);
11477
11578 $ options = [
116- 'pdo ' => new PDO ( 'sqlite::memory: ' ) ,
79+ 'url ' => 'sqlite::memory: ' ,
11780 'wrapperClass ' => stdClass::class,
11881 ];
11982
@@ -215,16 +178,6 @@ public function testDatabaseUrl($url, $expected) : void
215178 {
216179 $ options = is_array ($ url ) ? $ url : ['url ' => $ url ];
217180
218- if (isset ($ options ['pdo ' ])) {
219- if (! extension_loaded ('pdo ' )) {
220- $ this ->markTestSkipped ('PDO is not installed ' );
221- }
222-
223- $ options ['pdo ' ] = $ this ->createMock (PDO ::class);
224- }
225-
226- $ options = is_array ($ url ) ? $ url : ['url ' => $ url ];
227-
228181 if ($ expected === false ) {
229182 $ this ->expectException (DBALException::class);
230183 }
@@ -233,7 +186,7 @@ public function testDatabaseUrl($url, $expected) : void
233186
234187 $ params = $ conn ->getParams ();
235188 foreach ($ expected as $ key => $ value ) {
236- if (in_array ($ key , ['pdo ' , ' driver ' , 'driverClass ' ], true )) {
189+ if (in_array ($ key , ['driver ' , 'driverClass ' ], true )) {
237190 self ::assertInstanceOf ($ value , $ conn ->getDriver ());
238191 } else {
239192 self ::assertEquals ($ value , $ params [$ key ]);
@@ -394,13 +347,6 @@ public function databaseUrls() : iterable
394347 ['url ' => '//foo:bar@localhost/baz ' ],
395348 false ,
396349 ],
397- 'URL without scheme but default PDO driver ' => [
398- [
399- 'url ' => '//foo:bar@localhost/baz ' ,
400- 'pdo ' => true ,
401- ],
402- false ,
403- ],
404350 'URL without scheme but default driver ' => [
405351 [
406352 'url ' => '//foo:bar@localhost/baz ' ,
@@ -427,20 +373,6 @@ public function databaseUrls() : iterable
427373 'driverClass ' => $ driverClass ,
428374 ],
429375 ],
430- 'URL without scheme but default PDO driver and default driver ' => [
431- [
432- 'url ' => '//foo:bar@localhost/baz ' ,
433- 'pdo ' => true ,
434- 'driver ' => 'pdo_mysql ' ,
435- ],
436- [
437- 'user ' => 'foo ' ,
438- 'password ' => 'bar ' ,
439- 'host ' => 'localhost ' ,
440- 'dbname ' => 'baz ' ,
441- 'driver ' => PDOMySQLDriver::class,
442- ],
443- ],
444376 'URL without scheme but driver and custom driver ' => [
445377 [
446378 'url ' => '//foo:bar@localhost/baz ' ,
@@ -455,19 +387,6 @@ public function databaseUrls() : iterable
455387 'driverClass ' => $ driverClass ,
456388 ],
457389 ],
458- 'URL with default PDO driver ' => [
459- [
460- 'url ' => 'mysql://foo:bar@localhost/baz ' ,
461- 'pdo ' => true ,
462- ],
463- [
464- 'user ' => 'foo ' ,
465- 'password ' => 'bar ' ,
466- 'host ' => 'localhost ' ,
467- 'dbname ' => 'baz ' ,
468- 'driver ' => PDOMySQLDriver::class,
469- ],
470- ],
471390 'URL with default driver ' => [
472391 [
473392 'url ' => 'mysql://foo:bar@localhost/baz ' ,
@@ -494,20 +413,6 @@ public function databaseUrls() : iterable
494413 'driver ' => PDOMySQLDriver::class,
495414 ],
496415 ],
497- 'URL with default PDO driver and default driver ' => [
498- [
499- 'url ' => 'mysql://foo:bar@localhost/baz ' ,
500- 'pdo ' => true ,
501- 'driver ' => 'sqlite ' ,
502- ],
503- [
504- 'user ' => 'foo ' ,
505- 'password ' => 'bar ' ,
506- 'host ' => 'localhost ' ,
507- 'dbname ' => 'baz ' ,
508- 'driver ' => PDOMySQLDriver::class,
509- ],
510- ],
511416 'URL with default driver and default custom driver ' => [
512417 [
513418 'url ' => 'mysql://foo:bar@localhost/baz ' ,
@@ -522,21 +427,6 @@ public function databaseUrls() : iterable
522427 'driver ' => PDOMySQLDriver::class,
523428 ],
524429 ],
525- 'URL with default PDO driver and default driver and default custom driver ' => [
526- [
527- 'url ' => 'mysql://foo:bar@localhost/baz ' ,
528- 'pdo ' => true ,
529- 'driver ' => 'sqlite ' ,
530- 'driverClass ' => $ driverClass ,
531- ],
532- [
533- 'user ' => 'foo ' ,
534- 'password ' => 'bar ' ,
535- 'host ' => 'localhost ' ,
536- 'dbname ' => 'baz ' ,
537- 'driver ' => PDOMySQLDriver::class,
538- ],
539- ],
540430 ];
541431 }
542432}
0 commit comments