Skip to content

Commit

Permalink
Fix Schema::getTableSequenceName() + Fix psalm issues (#254)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergei Predvoditelev <[email protected]>
  • Loading branch information
Tigrov and vjik authored Feb 3, 2024
1 parent 8e05361 commit 1d08e72
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 10 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- '8.0'
- '8.1'
- '8.2'
- '8.3'

steps:
- name: Checkout.
Expand Down Expand Up @@ -71,8 +72,10 @@ jobs:
FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }}
WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }}

- name: Install dependencies with composer.
run: composer update --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis.
if: ${{ matrix.php != '8.0' }}
run: vendor/bin/psalm --config=${{ inputs.psalm-config }} --shepherd --stats --output-format=github --php-version=${{ matrix.php }}

- name: Static analysis.
if: ${{ matrix.php == '8.0' }}
run: vendor/bin/psalm --config=psalm4.xml --shepherd --stats --output-format=github --php-version=${{ matrix.php }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Bug #250: Fix `Command::insertWithReturningPks()` method for table without primary keys (@Tigrov)
- Enh #251: Allow to use `DMLQueryBuilderInterface::batchInsert()` method with empty columns (@Tigrov)
- Bug #238: Fix execution `Query` without table(s) to select from (@Tigrov)
- Bug #254: Fix, table sequence name should be null if sequence name not found (@Tigrov)

## 1.2.0 November 12, 2023

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"rector/rector": "^0.19",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.3|^5.6",
"vimeo/psalm": "^4.30|^5.20",
"yiisoft/aliases": "^2.0",
"yiisoft/cache-file": "^3.1",
"yiisoft/var-dumper": "^1.5"
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
<RiskyTruthyFalsyComparison errorLevel="suppress" />
</issueHandlers>
</psalm>
20 changes: 20 additions & 0 deletions psalm4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
</issueHandlers>
</psalm>
7 changes: 4 additions & 3 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,11 @@ protected function findColumns(TableSchemaInterface $table): bool
* @throws InvalidConfigException
* @throws Throwable
*
* @return bool|float|int|string|null Whether the sequence exists.
* @return string|null Whether the sequence exists.
*
* @internal TableSchemaInterface `$table->getName()` The table schema.
*/
protected function getTableSequenceName(string $tableName): bool|float|int|string|null
protected function getTableSequenceName(string $tableName): string|null
{
$sequenceNameSql = <<<SQL
SELECT
Expand All @@ -441,6 +441,7 @@ protected function getTableSequenceName(string $tableName): bool|float|int|strin
SQL;
$sequenceName = $this->db->createCommand($sequenceNameSql, [':tableName' => $tableName])->queryScalar();

/** @var string|null */
return $sequenceName === false ? null : $sequenceName;
}

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

if (empty($table->getSequenceName())) {
$table->sequenceName((string) $this->getTableSequenceName($table->getName()));
$table->sequenceName($this->getTableSequenceName($table->getName()));
}
}

Expand Down
20 changes: 17 additions & 3 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,30 @@ public function testResetSequence(): void
* @throws InvalidConfigException
* @throws NotSupportedException
*/
public function testResetSequenceCompositeException(): void
public function testResetNonExistSequenceException(): void
{
$db = $this->getConnection(true);
$qb = $db->getQueryBuilder();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("There is not sequence associated with table 'default_multiple_pk'.");
$qb->resetSequence('default_multiple_pk');

$db->close();
}

public function testResetSequenceCompositeException(): void
{
self::markTestSkipped('Sequence name not found for composite primary key');

$db = $this->getConnection(true);
$qb = $db->getQueryBuilder();

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

$qb->resetSequence('default_multiple_pk');
$db->close();
}

/**
Expand Down

0 comments on commit 1d08e72

Please sign in to comment.