diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f66d06..65610609 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ - New #393: Use `DateTimeColumn` class for datetime column types (@Tigrov) - New #394, #395, #398: Implement `Command::upsertReturning()` method (@Tigrov) - Enh #394, #395: Refactor `Command::insertWithReturningPks()` method (@Tigrov) +- Chg #399: Rename `insertWithReturningPks()` to `insertReturningPks()` in `Command` and `DMLQueryBuilder` classes (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Command.php b/src/Command.php index 9f34f47f..6ba5b45e 100644 --- a/src/Command.php +++ b/src/Command.php @@ -22,7 +22,7 @@ */ final class Command extends AbstractPdoCommand { - public function insertWithReturningPks(string $table, array|QueryInterface $columns): array|false + public function insertReturningPks(string $table, array|QueryInterface $columns): array|false { $tableSchema = $this->db->getSchema()->getTableSchema($table); $primaryKeys = $tableSchema?->getPrimaryKey() ?? []; diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index fa437dca..ea9b98b6 100644 --- a/src/DMLQueryBuilder.php +++ b/src/DMLQueryBuilder.php @@ -29,7 +29,7 @@ final class DMLQueryBuilder extends AbstractDMLQueryBuilder { /** @throws NotSupportedException */ - public function insertWithReturningPks(string $table, array|QueryInterface $columns, array &$params = []): string + public function insertReturningPks(string $table, array|QueryInterface $columns, array &$params = []): string { throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.'); } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index ae683546..58063842 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -99,7 +99,7 @@ public function testGetRawSql(string $sql, array $params, string $expectedRawSql parent::testGetRawSql($sql, $params, $expectedRawSql); } - public function testInsertWithReturningPksWithSubqueryAndNoAutoincrement(): void + public function testInsertReturningPksWithSubqueryAndNoAutoincrement(): void { $db = $this->getConnection(true); $command = $db->createCommand(); @@ -108,10 +108,10 @@ public function testInsertWithReturningPksWithSubqueryAndNoAutoincrement(): void $this->expectException(NotSupportedException::class); $this->expectExceptionMessage( - 'Yiisoft\Db\Mysql\Command::insertWithReturningPks() is not supported by MySQL for tables without auto increment when inserting sub-query.' + 'Yiisoft\Db\Mysql\Command::insertReturningPks() is not supported by MySQL for tables without auto increment when inserting sub-query.' ); - $command->insertWithReturningPks('order_item', $query); + $command->insertReturningPks('order_item', $query); } #[DataProviderExternal(CommandProvider::class, 'update')] diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 25c6d89a..edcdcf80 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -408,22 +408,23 @@ public function testInsert( parent::testInsert($table, $columns, $params, $expectedSQL, $expectedParams); } - #[DataProviderExternal(QueryBuilderProvider::class, 'insertWithReturningPks')] - public function testInsertWithReturningPks( + #[DataProviderExternal(QueryBuilderProvider::class, 'insertReturningPks')] + public function testInsertReturningPks( string $table, array|QueryInterface $columns, array $params, string $expectedSQL, array $expectedParams ): void { + $db = $this->getConnection(); + $qb = $db->getQueryBuilder(); + $this->expectException(NotSupportedException::class); $this->expectExceptionMessage( - 'Yiisoft\Db\Mysql\DMLQueryBuilder::insertWithReturningPks is not supported by MySQL.' + 'Yiisoft\Db\Mysql\DMLQueryBuilder::insertReturningPks is not supported by MySQL.' ); - $db = $this->getConnection(true); - $qb = $db->getQueryBuilder(); - $qb->insertWithReturningPks($table, $columns, $params); + $qb->insertReturningPks($table, $columns, $params); $db->close(); } @@ -515,7 +516,7 @@ public function testResetSequence(): void $this->assertSame($sql, $qb->resetSequence('item')); $command->setSql($sql)->execute(); - $insertResult = $command->insertWithReturningPks('item', ['name' => '123', 'category_id' => 1]); + $insertResult = $command->insertReturningPks('item', ['name' => '123', 'category_id' => 1]); $this->assertEquals(6, $insertResult['id']); // Key as string. @@ -526,7 +527,7 @@ public function testResetSequence(): void $this->assertSame($sql, $qb->resetSequence('item', '40')); $command->setSql($sql)->execute(); - $insertResult = $command->insertWithReturningPks('item', ['name' => '123', 'category_id' => 1]); + $insertResult = $command->insertReturningPks('item', ['name' => '123', 'category_id' => 1]); $this->assertEquals(40, $insertResult['id']); // Change up, key as int. @@ -537,7 +538,7 @@ public function testResetSequence(): void $this->assertSame($sql, $qb->resetSequence('item', 43)); $db->createCommand($sql)->execute(); - $insertResult = $command->insertWithReturningPks('item', ['name' => '123', 'category_id' => 1]); + $insertResult = $command->insertReturningPks('item', ['name' => '123', 'category_id' => 1]); $this->assertEquals(43, $insertResult['id']); $command->delete('item', ['>=','id', 6])->execute(); @@ -552,7 +553,7 @@ public function testResetSequence(): void $this->assertSame($sql, $qb->resetSequence('item')); $db->createCommand($sql)->execute(); - $insertResult = $command->insertWithReturningPks('item', ['name' => '123', 'category_id' => 1]); + $insertResult = $command->insertReturningPks('item', ['name' => '123', 'category_id' => 1]); $this->assertEquals(6, $insertResult['id']); $db->close(); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index fe8a5614..3a8496f1 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -454,7 +454,7 @@ public function testTinyInt1() )->execute(); $status = 2; - $insertedRow = $db->createCommand()->insertWithReturningPks($tableName, ['status' => $status, 'bool_col' => true]); + $insertedRow = $db->createCommand()->insertReturningPks($tableName, ['status' => $status, 'bool_col' => true]); $selectedRow = $db->createCommand('SELECT * FROM ' . $tableName . ' WHERE id=:id', ['id' => $insertedRow['id']])->queryOne(); $this->assertEquals($status, $selectedRow['status']);