| Total Complexity | 45 |
| Total Lines | 869 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ConnectionTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ConnectionTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class ConnectionTest extends TestCase |
||
| 34 | { |
||
| 35 | /** @var Connection */ |
||
| 36 | private $connection; |
||
| 37 | |||
| 38 | /** @var string[] */ |
||
| 39 | protected $params = [ |
||
| 40 | 'driver' => 'pdo_mysql', |
||
| 41 | 'host' => 'localhost', |
||
| 42 | 'user' => 'root', |
||
| 43 | 'password' => 'password', |
||
| 44 | 'port' => '1234', |
||
| 45 | ]; |
||
| 46 | |||
| 47 | protected function setUp() : void |
||
| 48 | { |
||
| 49 | $this->connection = DriverManager::getConnection($this->params); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @return Connection|MockObject |
||
| 54 | */ |
||
| 55 | private function getExecuteUpdateMockConnection() |
||
| 56 | { |
||
| 57 | $driverMock = $this->createMock(Driver::class); |
||
| 58 | |||
| 59 | $driverMock->expects($this->any()) |
||
| 60 | ->method('connect') |
||
| 61 | ->will($this->returnValue( |
||
| 62 | $this->createMock(DriverConnection::class) |
||
| 63 | )); |
||
| 64 | |||
| 65 | $platform = $this->getMockForAbstractClass(AbstractPlatform::class); |
||
| 66 | |||
| 67 | return $this->getMockBuilder(Connection::class) |
||
| 68 | ->onlyMethods(['executeUpdate']) |
||
| 69 | ->setConstructorArgs([['platform' => $platform], $driverMock]) |
||
| 70 | ->getMock(); |
||
| 71 | } |
||
| 72 | |||
| 73 | public function testIsConnected() : void |
||
| 74 | { |
||
| 75 | self::assertFalse($this->connection->isConnected()); |
||
| 76 | } |
||
| 77 | |||
| 78 | public function testNoTransactionActiveByDefault() : void |
||
| 79 | { |
||
| 80 | self::assertFalse($this->connection->isTransactionActive()); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function testCommitWithNoActiveTransactionThrowsException() : void |
||
| 84 | { |
||
| 85 | $this->expectException(ConnectionException::class); |
||
| 86 | $this->connection->commit(); |
||
| 87 | } |
||
| 88 | |||
| 89 | public function testRollbackWithNoActiveTransactionThrowsException() : void |
||
| 90 | { |
||
| 91 | $this->expectException(ConnectionException::class); |
||
| 92 | $this->connection->rollBack(); |
||
| 93 | } |
||
| 94 | |||
| 95 | public function testSetRollbackOnlyNoActiveTransactionThrowsException() : void |
||
| 96 | { |
||
| 97 | $this->expectException(ConnectionException::class); |
||
| 98 | $this->connection->setRollbackOnly(); |
||
| 99 | } |
||
| 100 | |||
| 101 | public function testIsRollbackOnlyNoActiveTransactionThrowsException() : void |
||
| 102 | { |
||
| 103 | $this->expectException(ConnectionException::class); |
||
| 104 | $this->connection->isRollbackOnly(); |
||
| 105 | } |
||
| 106 | |||
| 107 | public function testGetConfiguration() : void |
||
| 108 | { |
||
| 109 | $config = $this->connection->getConfiguration(); |
||
| 110 | |||
| 111 | self::assertInstanceOf(Configuration::class, $config); |
||
| 112 | } |
||
| 113 | |||
| 114 | public function testGetHost() : void |
||
| 115 | { |
||
| 116 | self::assertEquals('localhost', $this->connection->getHost()); |
||
|
|
|||
| 117 | } |
||
| 118 | |||
| 119 | public function testGetPort() : void |
||
| 122 | } |
||
| 123 | |||
| 124 | public function testGetUsername() : void |
||
| 125 | { |
||
| 126 | self::assertEquals('root', $this->connection->getUsername()); |
||
| 127 | } |
||
| 128 | |||
| 129 | public function testGetPassword() : void |
||
| 130 | { |
||
| 131 | self::assertEquals('password', $this->connection->getPassword()); |
||
| 132 | } |
||
| 133 | |||
| 134 | public function testGetDriver() : void |
||
| 135 | { |
||
| 136 | self::assertInstanceOf(\Doctrine\DBAL\Driver\PDOMySql\Driver::class, $this->connection->getDriver()); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function testGetEventManager() : void |
||
| 140 | { |
||
| 141 | self::assertInstanceOf(EventManager::class, $this->connection->getEventManager()); |
||
| 142 | } |
||
| 143 | |||
| 144 | public function testConnectDispatchEvent() : void |
||
| 145 | { |
||
| 146 | $listenerMock = $this->getMockBuilder($this->getMockClass('ConnectDispatchEventListener')) |
||
| 147 | ->addMethods(['postConnect']) |
||
| 148 | ->getMock(); |
||
| 149 | $listenerMock->expects($this->once())->method('postConnect'); |
||
| 150 | |||
| 151 | $eventManager = new EventManager(); |
||
| 152 | $eventManager->addEventListener([Events::postConnect], $listenerMock); |
||
| 153 | |||
| 154 | $driverMock = $this->createMock(Driver::class); |
||
| 155 | $driverMock->expects($this->at(0)) |
||
| 156 | ->method('connect'); |
||
| 157 | |||
| 158 | $conn = new Connection([], $driverMock, new Configuration(), $eventManager); |
||
| 159 | $conn->connect(); |
||
| 160 | } |
||
| 161 | |||
| 162 | public function testEventManagerPassedToPlatform() : void |
||
| 163 | { |
||
| 164 | $eventManager = new EventManager(); |
||
| 165 | |||
| 166 | /** @var AbstractPlatform|MockObject $driver */ |
||
| 167 | $platform = $this->createMock(AbstractPlatform::class); |
||
| 168 | $platform->expects($this->once()) |
||
| 169 | ->method('setEventManager') |
||
| 170 | ->with($eventManager); |
||
| 171 | |||
| 172 | /** @var Driver|MockObject $driver */ |
||
| 173 | $driver = $this->createMock(Driver::class); |
||
| 174 | $driver->expects($this->any()) |
||
| 175 | ->method('getDatabasePlatform') |
||
| 176 | ->willReturn($platform); |
||
| 177 | |||
| 178 | $connection = new Connection($this->params, $driver, null, $eventManager); |
||
| 179 | $connection->getDatabasePlatform(); |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @requires extension pdo_sqlite |
||
| 184 | * @dataProvider getQueryMethods |
||
| 185 | */ |
||
| 186 | public function testDriverExceptionIsWrapped(string $method) : void |
||
| 187 | { |
||
| 188 | $this->expectException(DBALException::class); |
||
| 189 | $this->expectExceptionMessage("An exception occurred while executing 'MUUHAAAAHAAAA':\n\nSQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); |
||
| 190 | |||
| 191 | $connection = DriverManager::getConnection([ |
||
| 192 | 'driver' => 'pdo_sqlite', |
||
| 193 | 'memory' => true, |
||
| 194 | ]); |
||
| 195 | |||
| 196 | $connection->$method('MUUHAAAAHAAAA'); |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @return array<int, array<int, mixed>> |
||
| 201 | */ |
||
| 202 | public static function getQueryMethods() : iterable |
||
| 203 | { |
||
| 204 | return [ |
||
| 205 | ['exec'], |
||
| 206 | ['query'], |
||
| 207 | ['executeQuery'], |
||
| 208 | ['executeUpdate'], |
||
| 209 | ['prepare'], |
||
| 210 | ]; |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Pretty dumb test, however we want to check that the DebugStack correctly implements the interface. |
||
| 215 | * |
||
| 216 | * @group DBAL-11 |
||
| 217 | */ |
||
| 218 | public function testDebugSQLStack() : void |
||
| 219 | { |
||
| 220 | $logger = new DebugStack(); |
||
| 221 | $this->connection->getConfiguration()->setSQLLogger($logger); |
||
| 222 | self::assertSame($logger, $this->connection->getConfiguration()->getSQLLogger()); |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @group DBAL-81 |
||
| 227 | */ |
||
| 228 | public function testIsAutoCommit() : void |
||
| 229 | { |
||
| 230 | self::assertTrue($this->connection->isAutoCommit()); |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @group DBAL-81 |
||
| 235 | */ |
||
| 236 | public function testSetAutoCommit() : void |
||
| 237 | { |
||
| 238 | $this->connection->setAutoCommit(false); |
||
| 239 | self::assertFalse($this->connection->isAutoCommit()); |
||
| 240 | $this->connection->setAutoCommit(0); |
||
| 241 | self::assertFalse($this->connection->isAutoCommit()); |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @group DBAL-81 |
||
| 246 | */ |
||
| 247 | public function testConnectStartsTransactionInNoAutoCommitMode() : void |
||
| 248 | { |
||
| 249 | $driverMock = $this->createMock(Driver::class); |
||
| 250 | $driverMock->expects($this->any()) |
||
| 251 | ->method('connect') |
||
| 252 | ->will($this->returnValue( |
||
| 253 | $this->createMock(DriverConnection::class) |
||
| 254 | )); |
||
| 255 | $conn = new Connection([], $driverMock); |
||
| 256 | |||
| 257 | $conn->setAutoCommit(false); |
||
| 258 | |||
| 259 | self::assertFalse($conn->isTransactionActive()); |
||
| 260 | |||
| 261 | $conn->connect(); |
||
| 262 | |||
| 263 | self::assertTrue($conn->isTransactionActive()); |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @group DBAL-81 |
||
| 268 | */ |
||
| 269 | public function testCommitStartsTransactionInNoAutoCommitMode() : void |
||
| 270 | { |
||
| 271 | $driverMock = $this->createMock(Driver::class); |
||
| 272 | $driverMock->expects($this->any()) |
||
| 273 | ->method('connect') |
||
| 274 | ->will($this->returnValue( |
||
| 275 | $this->createMock(DriverConnection::class) |
||
| 276 | )); |
||
| 277 | $conn = new Connection([], $driverMock); |
||
| 278 | |||
| 279 | $conn->setAutoCommit(false); |
||
| 280 | $conn->connect(); |
||
| 281 | $conn->commit(); |
||
| 282 | |||
| 283 | self::assertTrue($conn->isTransactionActive()); |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @dataProvider resultProvider |
||
| 288 | */ |
||
| 289 | public function testCommitReturn(bool $expectedResult) : void |
||
| 290 | { |
||
| 291 | $driverConnection = $this->createMock(DriverConnection::class); |
||
| 292 | $driverConnection->expects($this->once()) |
||
| 293 | ->method('commit')->willReturn($expectedResult); |
||
| 294 | |||
| 295 | $driverMock = $this->createMock(Driver::class); |
||
| 296 | $driverMock->expects($this->any()) |
||
| 297 | ->method('connect') |
||
| 298 | ->will($this->returnValue($driverConnection)); |
||
| 299 | |||
| 300 | $conn = new Connection([], $driverMock); |
||
| 301 | |||
| 302 | $conn->connect(); |
||
| 303 | $conn->beginTransaction(); |
||
| 304 | |||
| 305 | self::assertSame($expectedResult, $conn->commit()); |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @return bool[][] |
||
| 310 | */ |
||
| 311 | public function resultProvider() : array |
||
| 312 | { |
||
| 313 | return [[true], [false]]; |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @group DBAL-81 |
||
| 318 | */ |
||
| 319 | public function testRollBackStartsTransactionInNoAutoCommitMode() : void |
||
| 320 | { |
||
| 321 | $driverMock = $this->createMock(Driver::class); |
||
| 322 | $driverMock->expects($this->any()) |
||
| 323 | ->method('connect') |
||
| 324 | ->will($this->returnValue( |
||
| 325 | $this->createMock(DriverConnection::class) |
||
| 326 | )); |
||
| 327 | $conn = new Connection([], $driverMock); |
||
| 328 | |||
| 329 | $conn->setAutoCommit(false); |
||
| 330 | $conn->connect(); |
||
| 331 | $conn->rollBack(); |
||
| 332 | |||
| 333 | self::assertTrue($conn->isTransactionActive()); |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @group DBAL-81 |
||
| 338 | */ |
||
| 339 | public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() : void |
||
| 340 | { |
||
| 341 | $driverMock = $this->createMock(Driver::class); |
||
| 342 | $driverMock->expects($this->any()) |
||
| 343 | ->method('connect') |
||
| 344 | ->will($this->returnValue( |
||
| 345 | $this->createMock(DriverConnection::class) |
||
| 346 | )); |
||
| 347 | $conn = new Connection([], $driverMock); |
||
| 348 | |||
| 349 | $conn->connect(); |
||
| 350 | $conn->beginTransaction(); |
||
| 351 | $conn->beginTransaction(); |
||
| 352 | $conn->setAutoCommit(false); |
||
| 353 | |||
| 354 | self::assertSame(1, $conn->getTransactionNestingLevel()); |
||
| 355 | |||
| 356 | $conn->beginTransaction(); |
||
| 357 | $conn->beginTransaction(); |
||
| 358 | $conn->setAutoCommit(true); |
||
| 359 | |||
| 360 | self::assertFalse($conn->isTransactionActive()); |
||
| 361 | } |
||
| 362 | |||
| 363 | public function testEmptyInsert() : void |
||
| 364 | { |
||
| 365 | $conn = $this->getExecuteUpdateMockConnection(); |
||
| 366 | |||
| 367 | $conn->expects($this->once()) |
||
| 368 | ->method('executeUpdate') |
||
| 369 | ->with('INSERT INTO footable () VALUES ()'); |
||
| 370 | |||
| 371 | $conn->insert('footable', []); |
||
| 372 | } |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @group DBAL-2511 |
||
| 376 | */ |
||
| 377 | public function testUpdateWithDifferentColumnsInDataAndIdentifiers() : void |
||
| 414 | ] |
||
| 415 | ); |
||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @group DBAL-2511 |
||
| 420 | */ |
||
| 421 | public function testUpdateWithSameColumnInDataAndIdentifiers() : void |
||
| 422 | { |
||
| 423 | $conn = $this->getExecuteUpdateMockConnection(); |
||
| 424 | |||
| 425 | $conn->expects($this->once()) |
||
| 426 | ->method('executeUpdate') |
||
| 427 | ->with( |
||
| 428 | 'UPDATE TestTable SET text = ?, is_edited = ? WHERE id = ? AND is_edited = ?', |
||
| 429 | [ |
||
| 430 | 'some text', |
||
| 431 | true, |
||
| 432 | 1, |
||
| 433 | false, |
||
| 434 | ], |
||
| 435 | [ |
||
| 436 | 'string', |
||
| 437 | 'boolean', |
||
| 438 | 'integer', |
||
| 439 | 'boolean', |
||
| 440 | ] |
||
| 441 | ); |
||
| 442 | |||
| 443 | $conn->update( |
||
| 444 | 'TestTable', |
||
| 445 | [ |
||
| 446 | 'text' => 'some text', |
||
| 447 | 'is_edited' => true, |
||
| 448 | ], |
||
| 449 | [ |
||
| 450 | 'id' => 1, |
||
| 451 | 'is_edited' => false, |
||
| 452 | ], |
||
| 453 | [ |
||
| 454 | 'text' => 'string', |
||
| 455 | 'is_edited' => 'boolean', |
||
| 456 | 'id' => 'integer', |
||
| 457 | ] |
||
| 458 | ); |
||
| 459 | } |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @group DBAL-2688 |
||
| 463 | */ |
||
| 464 | public function testUpdateWithIsNull() : void |
||
| 465 | { |
||
| 466 | $conn = $this->getExecuteUpdateMockConnection(); |
||
| 467 | |||
| 468 | $conn->expects($this->once()) |
||
| 469 | ->method('executeUpdate') |
||
| 470 | ->with( |
||
| 471 | 'UPDATE TestTable SET text = ?, is_edited = ? WHERE id IS NULL AND name = ?', |
||
| 472 | [ |
||
| 473 | 'some text', |
||
| 474 | null, |
||
| 475 | 'foo', |
||
| 476 | ], |
||
| 477 | [ |
||
| 478 | 'string', |
||
| 479 | 'boolean', |
||
| 480 | 'string', |
||
| 481 | ] |
||
| 482 | ); |
||
| 483 | |||
| 484 | $conn->update( |
||
| 485 | 'TestTable', |
||
| 486 | [ |
||
| 487 | 'text' => 'some text', |
||
| 488 | 'is_edited' => null, |
||
| 489 | ], |
||
| 490 | [ |
||
| 491 | 'id' => null, |
||
| 492 | 'name' => 'foo', |
||
| 493 | ], |
||
| 494 | [ |
||
| 495 | 'text' => 'string', |
||
| 496 | 'is_edited' => 'boolean', |
||
| 497 | 'id' => 'integer', |
||
| 498 | 'name' => 'string', |
||
| 499 | ] |
||
| 500 | ); |
||
| 501 | } |
||
| 502 | |||
| 503 | /** |
||
| 504 | * @group DBAL-2688 |
||
| 505 | */ |
||
| 506 | public function testDeleteWithIsNull() : void |
||
| 507 | { |
||
| 508 | $conn = $this->getExecuteUpdateMockConnection(); |
||
| 509 | |||
| 510 | $conn->expects($this->once()) |
||
| 511 | ->method('executeUpdate') |
||
| 512 | ->with( |
||
| 513 | 'DELETE FROM TestTable WHERE id IS NULL AND name = ?', |
||
| 514 | ['foo'], |
||
| 515 | ['string'] |
||
| 516 | ); |
||
| 517 | |||
| 518 | $conn->delete( |
||
| 519 | 'TestTable', |
||
| 520 | [ |
||
| 521 | 'id' => null, |
||
| 522 | 'name' => 'foo', |
||
| 523 | ], |
||
| 524 | [ |
||
| 525 | 'id' => 'integer', |
||
| 526 | 'name' => 'string', |
||
| 527 | ] |
||
| 528 | ); |
||
| 529 | } |
||
| 530 | |||
| 531 | public function testFetchAssoc() : void |
||
| 565 | } |
||
| 566 | |||
| 567 | public function testFetchArray() : void |
||
| 601 | } |
||
| 602 | |||
| 603 | public function testFetchColumn() : void |
||
| 604 | { |
||
| 605 | $statement = 'SELECT * FROM foo WHERE bar = ?'; |
||
| 606 | $params = [666]; |
||
| 607 | $types = [ParameterType::INTEGER]; |
||
| 608 | $column = 0; |
||
| 609 | $result = []; |
||
| 610 | |||
| 611 | $driverMock = $this->createMock(Driver::class); |
||
| 612 | |||
| 613 | $driverMock->expects($this->any()) |
||
| 614 | ->method('connect') |
||
| 615 | ->will($this->returnValue( |
||
| 616 | $this->createMock(DriverConnection::class) |
||
| 617 | )); |
||
| 618 | |||
| 619 | $driverStatementMock = $this->createMock(Statement::class); |
||
| 620 | |||
| 621 | $driverStatementMock->expects($this->once()) |
||
| 622 | ->method('fetchColumn') |
||
| 623 | ->with($column) |
||
| 624 | ->will($this->returnValue($result)); |
||
| 625 | |||
| 626 | /** @var Connection|MockObject $conn */ |
||
| 627 | $conn = $this->getMockBuilder(Connection::class) |
||
| 628 | ->onlyMethods(['executeQuery']) |
||
| 629 | ->setConstructorArgs([[], $driverMock]) |
||
| 630 | ->getMock(); |
||
| 631 | |||
| 632 | $conn->expects($this->once()) |
||
| 633 | ->method('executeQuery') |
||
| 634 | ->with($statement, $params, $types) |
||
| 635 | ->will($this->returnValue($driverStatementMock)); |
||
| 636 | |||
| 637 | self::assertSame($result, $conn->fetchColumn($statement, $params, $column, $types)); |
||
| 638 | } |
||
| 639 | |||
| 640 | public function testFetchAll() : void |
||
| 641 | { |
||
| 642 | $statement = 'SELECT * FROM foo WHERE bar = ?'; |
||
| 643 | $params = [666]; |
||
| 644 | $types = [ParameterType::INTEGER]; |
||
| 645 | $result = []; |
||
| 646 | |||
| 647 | $driverMock = $this->createMock(Driver::class); |
||
| 648 | |||
| 649 | $driverMock->expects($this->any()) |
||
| 650 | ->method('connect') |
||
| 651 | ->will($this->returnValue( |
||
| 652 | $this->createMock(DriverConnection::class) |
||
| 653 | )); |
||
| 654 | |||
| 655 | $driverStatementMock = $this->createMock(Statement::class); |
||
| 656 | |||
| 657 | $driverStatementMock->expects($this->once()) |
||
| 658 | ->method('fetchAll') |
||
| 659 | ->will($this->returnValue($result)); |
||
| 660 | |||
| 661 | /** @var Connection|MockObject $conn */ |
||
| 662 | $conn = $this->getMockBuilder(Connection::class) |
||
| 663 | ->onlyMethods(['executeQuery']) |
||
| 664 | ->setConstructorArgs([[], $driverMock]) |
||
| 665 | ->getMock(); |
||
| 666 | |||
| 667 | $conn->expects($this->once()) |
||
| 668 | ->method('executeQuery') |
||
| 669 | ->with($statement, $params, $types) |
||
| 670 | ->will($this->returnValue($driverStatementMock)); |
||
| 671 | |||
| 672 | self::assertSame($result, $conn->fetchAll($statement, $params, $types)); |
||
| 673 | } |
||
| 674 | |||
| 675 | public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() : void |
||
| 676 | { |
||
| 677 | /** @var Driver $driver */ |
||
| 678 | $driver = $this->createMock(Driver::class); |
||
| 679 | $conn = new Connection([], $driver); |
||
| 680 | |||
| 681 | $this->expectException(InvalidArgumentException::class); |
||
| 682 | $conn->delete('kittens', []); |
||
| 683 | } |
||
| 684 | |||
| 685 | public function testCallConnectOnce() : void |
||
| 697 | } |
||
| 698 | |||
| 699 | /** |
||
| 700 | * @group DBAL-1127 |
||
| 701 | */ |
||
| 702 | public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() : void |
||
| 703 | { |
||
| 704 | /** @var VersionAwarePlatformDriver|MockObject $driverMock */ |
||
| 705 | $driverMock = $this->createMock(VersionAwarePlatformDriver::class); |
||
| 706 | |||
| 707 | /** @var ServerInfoAwareConnection|MockObject $driverConnectionMock */ |
||
| 708 | $driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class); |
||
| 709 | |||
| 710 | /** @var AbstractPlatform|MockObject $platformMock */ |
||
| 711 | $platformMock = $this->getMockForAbstractClass(AbstractPlatform::class); |
||
| 712 | |||
| 713 | $connection = new Connection([], $driverMock); |
||
| 714 | |||
| 715 | $driverMock->expects($this->once()) |
||
| 716 | ->method('connect') |
||
| 717 | ->will($this->returnValue($driverConnectionMock)); |
||
| 718 | |||
| 719 | $driverConnectionMock->expects($this->once()) |
||
| 720 | ->method('requiresQueryForServerVersion') |
||
| 721 | ->will($this->returnValue(false)); |
||
| 722 | |||
| 723 | $driverConnectionMock->expects($this->once()) |
||
| 724 | ->method('getServerVersion') |
||
| 725 | ->will($this->returnValue('6.6.6')); |
||
| 726 | |||
| 727 | $driverMock->expects($this->once()) |
||
| 728 | ->method('createDatabasePlatformForVersion') |
||
| 729 | ->with('6.6.6') |
||
| 730 | ->will($this->returnValue($platformMock)); |
||
| 731 | |||
| 732 | self::assertSame($platformMock, $connection->getDatabasePlatform()); |
||
| 733 | } |
||
| 734 | |||
| 735 | public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCacheQuery() : void |
||
| 770 | ); |
||
| 771 | } |
||
| 772 | |||
| 773 | /** |
||
| 774 | * @group #2821 |
||
| 775 | */ |
||
| 776 | public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecuteCacheQuery() : void |
||
| 810 | } |
||
| 811 | |||
| 812 | /** |
||
| 813 | * @group #2821 |
||
| 814 | */ |
||
| 815 | public function testThrowsExceptionWhenInValidPlatformSpecified() : void |
||
| 816 | { |
||
| 817 | $connectionParams = $this->params; |
||
| 818 | $connectionParams['platform'] = new stdClass(); |
||
| 819 | |||
| 820 | /** @var Driver $driver */ |
||
| 821 | $driver = $this->createMock(Driver::class); |
||
| 822 | |||
| 823 | $this->expectException(DBALException::class); |
||
| 824 | |||
| 825 | new Connection($connectionParams, $driver); |
||
| 826 | } |
||
| 827 | |||
| 828 | /** |
||
| 829 | * @group DBAL-990 |
||
| 830 | */ |
||
| 831 | public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() : void |
||
| 832 | { |
||
| 833 | /** @var VersionAwarePlatformDriver|MockObject $driverMock */ |
||
| 834 | $driverMock = $this->createMock(VersionAwarePlatformDriver::class); |
||
| 835 | |||
| 836 | $connection = new Connection(['dbname' => 'foo'], $driverMock); |
||
| 837 | $originalException = new Exception('Original exception'); |
||
| 838 | $fallbackException = new Exception('Fallback exception'); |
||
| 839 | |||
| 840 | $driverMock->expects($this->at(0)) |
||
| 841 | ->method('connect') |
||
| 842 | ->willThrowException($originalException); |
||
| 843 | |||
| 844 | $driverMock->expects($this->at(1)) |
||
| 845 | ->method('connect') |
||
| 846 | ->willThrowException($fallbackException); |
||
| 847 | |||
| 848 | $this->expectExceptionMessage($originalException->getMessage()); |
||
| 849 | |||
| 850 | $connection->getDatabasePlatform(); |
||
| 851 | } |
||
| 852 | |||
| 853 | /** |
||
| 854 | * @group #3194 |
||
| 855 | */ |
||
| 856 | public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGeneratingCacheKeys() : void |
||
| 902 | } |
||
| 903 | } |
||
| 904 |