Skip to content

Commit 091737a

Browse files
authored
Update according changes in db package (#430)
1 parent 4dc4c63 commit 091737a

4 files changed

Lines changed: 24 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
- Chg #388: Change supported PHP versions to `8.1 - 8.4` (@Tigrov)
3636
- Enh #388: Minor refactoring (@Tigrov)
3737
- Chg #390: Remove `yiisoft/json` dependency (@Tigrov)
38-
- Enh #393: Refactor according changes in `db` package (@Tigrov)
38+
- Enh #393, #430: Refactor according changes in `db` package (@Tigrov)
3939
- New #391: Add `caseSensitive` option to like condition (@vjik)
4040
- Enh #396: Remove `getCacheKey()` and `getCacheTag()` methods from `Schema` class (@Tigrov)
4141
- Enh #403, #404: Use `DbArrayHelper::arrange()` instead of `DbArrayHelper::index()` method (@Tigrov)

src/Schema.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ protected function resolveTableName(string $name): TableSchemaInterface
9090
{
9191
$resolvedName = new TableSchema();
9292

93-
$parts = array_reverse($this->db->getQuoter()->getTableNameParts($name));
94-
$resolvedName->name($parts[0] ?? '');
95-
$resolvedName->schemaName($parts[1] ?? $this->defaultSchema);
93+
$parts = $this->db->getQuoter()->getTableNameParts($name);
94+
$resolvedName->name($parts['name']);
95+
$resolvedName->schemaName($parts['schemaName'] ?? $this->defaultSchema);
9696

9797
$resolvedName->fullName(
9898
$resolvedName->getSchemaName() !== $this->defaultSchema ?
99-
implode('.', array_reverse($parts)) : $resolvedName->getName()
99+
implode('.', $parts) : $resolvedName->getName()
100100
);
101101

102102
return $resolvedName;
@@ -202,10 +202,10 @@ protected function loadTableIndexes(string $tableName): array
202202
ORDER BY "i"."indkey", "ia"."attnum" ASC
203203
SQL;
204204

205-
$resolvedName = $this->resolveTableName($tableName);
205+
$nameParts = $this->db->getQuoter()->getTableNameParts($tableName);
206206
$indexes = $this->db->createCommand($sql, [
207-
':schemaName' => $resolvedName->getSchemaName(),
208-
':tableName' => $resolvedName->getName(),
207+
':schemaName' => $nameParts['schemaName'] ?? $this->defaultSchema,
208+
':tableName' => $nameParts['name'],
209209
])->queryAll();
210210

211211
$indexes = array_map(array_change_key_case(...), $indexes);
@@ -765,10 +765,10 @@ private function loadTableConstraints(string $tableName, string $returnType): ar
765765
'd' => ReferentialAction::SET_DEFAULT,
766766
];
767767

768-
$resolvedName = $this->resolveTableName($tableName);
768+
$nameParts = $this->db->getQuoter()->getTableNameParts($tableName);
769769
$constraints = $this->db->createCommand($sql, [
770-
':schemaName' => $resolvedName->getSchemaName(),
771-
':tableName' => $resolvedName->getName(),
770+
':schemaName' => $nameParts['schemaName'] ?? $this->defaultSchema,
771+
':tableName' => $nameParts['name'],
772772
])->queryAll();
773773

774774
$constraints = array_map(array_change_key_case(...), $constraints);

tests/Provider/QuoterProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ final class QuoterProvider extends \Yiisoft\Db\Tests\Provider\QuoterProvider
99
public static function tableNameParts(): array
1010
{
1111
return [
12-
['', ''],
13-
['[]', '[]'],
14-
['animal', 'animal'],
15-
['dbo.animal', 'animal', 'dbo'],
16-
['[dbo].[animal]', '[animal]', '[dbo]'],
17-
['[other].[animal2]', '[animal2]', '[other]'],
18-
['other.[animal2]', '[animal2]', 'other'],
19-
['other.animal2', 'animal2', 'other'],
12+
['', ['name' => '']],
13+
['""', ['name' => '']],
14+
['animal', ['name' => 'animal']],
15+
['"animal"', ['name' => 'animal']],
16+
['dbo.animal', ['schemaName' => 'dbo', 'name' => 'animal']],
17+
['"dbo"."animal"', ['schemaName' => 'dbo', 'name' => 'animal']],
18+
['"dbo".animal', ['schemaName' => 'dbo', 'name' => 'animal']],
19+
['dbo."animal"', ['schemaName' => 'dbo', 'name' => 'animal']],
2020
];
2121
}
2222
}

tests/QuoterTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44

55
namespace Yiisoft\Db\Pgsql\Tests;
66

7+
use PHPUnit\Framework\Attributes\DataProviderExternal;
8+
use Yiisoft\Db\Pgsql\Tests\Provider\QuoterProvider;
79
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
810
use Yiisoft\Db\Tests\AbstractQuoterTest;
911

1012
/**
1113
* @group pgsql
12-
*
13-
* @psalm-suppress PropertyNotSetInConstructor
1414
*/
1515
final class QuoterTest extends AbstractQuoterTest
1616
{
1717
use TestTrait;
1818

19-
/**
20-
* @dataProvider \Yiisoft\Db\Pgsql\Tests\Provider\QuoterProvider::tableNameParts
21-
*/
22-
public function testGetTableNameParts(string $tableName, string ...$expected): void
19+
#[DataProviderExternal(QuoterProvider::class, 'tableNameParts')]
20+
public function testGetTableNameParts(string $tableName, array $expected): void
2321
{
24-
parent::testGetTableNameParts($tableName, ...$expected);
22+
parent::testGetTableNameParts($tableName, $expected);
2523
}
2624
}

0 commit comments

Comments
 (0)