Skip to content

Commit 1d08e72

Browse files
Tigrovvjik
andauthored
Fix Schema::getTableSequenceName() + Fix psalm issues (#254)
Co-authored-by: Sergei Predvoditelev <[email protected]>
1 parent 8e05361 commit 1d08e72

File tree

7 files changed

+50
-10
lines changed

7 files changed

+50
-10
lines changed

.github/workflows/static.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- '8.0'
4545
- '8.1'
4646
- '8.2'
47+
- '8.3'
4748

4849
steps:
4950
- name: Checkout.
@@ -71,8 +72,10 @@ jobs:
7172
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
7273
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}
7374

74-
- name: Install dependencies with composer.
75-
run: composer update --no-interaction --no-progress --optimize-autoloader --ansi
76-
7775
- name: Static analysis.
76+
if: ${{ matrix.php != '8.0' }}
7877
run: vendor/bin/psalm --config=${{ inputs.psalm-config }} --shepherd --stats --output-format=github --php-version=${{ matrix.php }}
78+
79+
- name: Static analysis.
80+
if: ${{ matrix.php == '8.0' }}
81+
run: vendor/bin/psalm --config=psalm4.xml --shepherd --stats --output-format=github --php-version=${{ matrix.php }}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Bug #250: Fix `Command::insertWithReturningPks()` method for table without primary keys (@Tigrov)
77
- Enh #251: Allow to use `DMLQueryBuilderInterface::batchInsert()` method with empty columns (@Tigrov)
88
- Bug #238: Fix execution `Query` without table(s) to select from (@Tigrov)
9+
- Bug #254: Fix, table sequence name should be null if sequence name not found (@Tigrov)
910

1011
## 1.2.0 November 12, 2023
1112

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"rector/rector": "^0.19",
3131
"roave/infection-static-analysis-plugin": "^1.16",
3232
"spatie/phpunit-watcher": "^1.23",
33-
"vimeo/psalm": "^4.3|^5.6",
33+
"vimeo/psalm": "^4.30|^5.20",
3434
"yiisoft/aliases": "^2.0",
3535
"yiisoft/cache-file": "^3.1",
3636
"yiisoft/var-dumper": "^1.5"

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
</projectFiles>
1717
<issueHandlers>
1818
<MixedAssignment errorLevel="suppress" />
19+
<RiskyTruthyFalsyComparison errorLevel="suppress" />
1920
</issueHandlers>
2021
</psalm>

psalm4.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
findUnusedBaselineEntry="true"
5+
findUnusedCode="false"
6+
resolveFromConfigFile="true"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="https://getpsalm.org/schema/config"
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<ignoreFiles>
14+
<directory name="vendor" />
15+
</ignoreFiles>
16+
</projectFiles>
17+
<issueHandlers>
18+
<MixedAssignment errorLevel="suppress" />
19+
</issueHandlers>
20+
</psalm>

src/Schema.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,11 @@ protected function findColumns(TableSchemaInterface $table): bool
423423
* @throws InvalidConfigException
424424
* @throws Throwable
425425
*
426-
* @return bool|float|int|string|null Whether the sequence exists.
426+
* @return string|null Whether the sequence exists.
427427
*
428428
* @internal TableSchemaInterface `$table->getName()` The table schema.
429429
*/
430-
protected function getTableSequenceName(string $tableName): bool|float|int|string|null
430+
protected function getTableSequenceName(string $tableName): string|null
431431
{
432432
$sequenceNameSql = <<<SQL
433433
SELECT
@@ -441,6 +441,7 @@ protected function getTableSequenceName(string $tableName): bool|float|int|strin
441441
SQL;
442442
$sequenceName = $this->db->createCommand($sequenceNameSql, [':tableName' => $tableName])->queryScalar();
443443

444+
/** @var string|null */
444445
return $sequenceName === false ? null : $sequenceName;
445446
}
446447

@@ -560,7 +561,7 @@ protected function findConstraints(TableSchemaInterface $table): void
560561
$table->primaryKey($row['column_name']);
561562

562563
if (empty($table->getSequenceName())) {
563-
$table->sequenceName((string) $this->getTableSequenceName($table->getName()));
564+
$table->sequenceName($this->getTableSequenceName($table->getName()));
564565
}
565566
}
566567

tests/QueryBuilderTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,16 +566,30 @@ public function testResetSequence(): void
566566
* @throws InvalidConfigException
567567
* @throws NotSupportedException
568568
*/
569-
public function testResetSequenceCompositeException(): void
569+
public function testResetNonExistSequenceException(): void
570570
{
571571
$db = $this->getConnection(true);
572+
$qb = $db->getQueryBuilder();
573+
574+
$this->expectException(InvalidArgumentException::class);
575+
$this->expectExceptionMessage("There is not sequence associated with table 'default_multiple_pk'.");
576+
$qb->resetSequence('default_multiple_pk');
577+
578+
$db->close();
579+
}
580+
581+
public function testResetSequenceCompositeException(): void
582+
{
583+
self::markTestSkipped('Sequence name not found for composite primary key');
572584

585+
$db = $this->getConnection(true);
573586
$qb = $db->getQueryBuilder();
574587

575588
$this->expectException(InvalidArgumentException::class);
576-
$this->expectExceptionMessage("Can't reset sequence for composite primary key in table: default_multiple_pk");
589+
$this->expectExceptionMessage("Can't reset sequence for composite primary key in table: employee");
590+
$qb->resetSequence('employee');
577591

578-
$qb->resetSequence('default_multiple_pk');
592+
$db->close();
579593
}
580594

581595
/**

0 commit comments

Comments
 (0)