|
5 | 5 | namespace Yiisoft\Db\Oracle\Tests; |
6 | 6 |
|
7 | 7 | use PDO; |
| 8 | +use Yiisoft\Db\Command\CommandInterface; |
| 9 | +use Yiisoft\Db\Connection\ConnectionInterface; |
8 | 10 | use Yiisoft\Db\Constraint\CheckConstraint; |
9 | 11 | use Yiisoft\Db\Exception\Exception; |
10 | 12 | use Yiisoft\Db\Exception\InvalidConfigException; |
@@ -519,4 +521,75 @@ public function testGetSchemaDefaultValues(): void |
519 | 521 | { |
520 | 522 | $this->markTestSkipped('Oracle does not support default value constraints.'); |
521 | 523 | } |
| 524 | + |
| 525 | + /** |
| 526 | + * @dataProvider tableSchemaWithDbSchemesDataProvider |
| 527 | + */ |
| 528 | + public function testTableSchemaWithDbSchemes(string $tableName, string $expectedTableName, string $expectedSchemaName = ''): void |
| 529 | + { |
| 530 | + $db = $this->getConnection(); |
| 531 | + |
| 532 | + $commandMock = $this->createMock(CommandInterface::class); |
| 533 | + $commandMock |
| 534 | + ->method('queryAll') |
| 535 | + ->willReturn([]); |
| 536 | + |
| 537 | + $mockDb = $this->createMock(ConnectionInterface::class); |
| 538 | + |
| 539 | + $mockDb->method('getQuoter') |
| 540 | + ->willReturn($db->getQuoter()); |
| 541 | + |
| 542 | + $mockDb |
| 543 | + ->method('createCommand') |
| 544 | + ->with(self::callback(function ($sql) { |
| 545 | + return true; |
| 546 | + }), self::callback(function ($params) use ($expectedTableName, $expectedSchemaName) { |
| 547 | + $this->assertEquals($expectedTableName, $params[':tableName']); |
| 548 | + $this->assertEquals($expectedSchemaName, $params[':schemaName']); |
| 549 | + return true; |
| 550 | + })) |
| 551 | + ->willReturn($commandMock); |
| 552 | + |
| 553 | + $schema = new Schema($mockDb, $this->createSchemaCache(), 'dbo'); |
| 554 | + |
| 555 | + $schema->getTablePrimaryKey($tableName); |
| 556 | + } |
| 557 | + |
| 558 | + public function tableSchemaWithDbSchemesDataProvider(): array |
| 559 | + { |
| 560 | + return [ |
| 561 | + ['animal', 'animal', 'dbo'], |
| 562 | + ['dbo.animal', 'animal', 'dbo'], |
| 563 | + ['"dbo"."animal"', 'animal', 'dbo'], |
| 564 | + ['"other"."animal2"', 'animal2', 'other',], |
| 565 | + ['other."animal2"', 'animal2', 'other',], |
| 566 | + ['other.animal2', 'animal2', 'other',], |
| 567 | + ['catalog.other.animal2', 'animal2', 'other'], |
| 568 | + ]; |
| 569 | + } |
| 570 | + |
| 571 | + /** |
| 572 | + * @dataProvider quoterTablePartsDataProvider |
| 573 | + */ |
| 574 | + public function testQuoterTableParts(string $tableName, ...$expectedParts): void |
| 575 | + { |
| 576 | + $quoter = $this->getConnection()->getQuoter(); |
| 577 | + |
| 578 | + $parts = $quoter->getTableNameParts($tableName); |
| 579 | + |
| 580 | + $this->assertEquals($expectedParts, array_reverse($parts)); |
| 581 | + } |
| 582 | + |
| 583 | + public function quoterTablePartsDataProvider(): array |
| 584 | + { |
| 585 | + return [ |
| 586 | + ['animal', 'animal',], |
| 587 | + ['dbo.animal', 'animal', 'dbo'], |
| 588 | + ['"dbo"."animal"', 'animal', 'dbo'], |
| 589 | + ['"other"."animal2"', 'animal2', 'other'], |
| 590 | + ['other."animal2"', 'animal2', 'other'], |
| 591 | + ['other.animal2', 'animal2', 'other'], |
| 592 | + ['catalog.other.animal2', 'animal2', 'other'], |
| 593 | + ]; |
| 594 | + } |
522 | 595 | } |
0 commit comments