Skip to content

Commit 1ff93dc

Browse files
authored
Rename insertWithReturningPks() to insertReturningPks() (#399)
1 parent b980234 commit 1ff93dc

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- New #393: Use `DateTimeColumn` class for datetime column types (@Tigrov)
4242
- New #394, #395, #398: Implement `Command::upsertReturning()` method (@Tigrov)
4343
- Enh #394, #395: Refactor `Command::insertWithReturningPks()` method (@Tigrov)
44+
- Chg #399: Rename `insertWithReturningPks()` to `insertReturningPks()` in `Command` and `DMLQueryBuilder` classes (@Tigrov)
4445

4546
## 1.2.0 March 21, 2024
4647

src/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
final class Command extends AbstractPdoCommand
2424
{
25-
public function insertWithReturningPks(string $table, array|QueryInterface $columns): array|false
25+
public function insertReturningPks(string $table, array|QueryInterface $columns): array|false
2626
{
2727
$tableSchema = $this->db->getSchema()->getTableSchema($table);
2828
$primaryKeys = $tableSchema?->getPrimaryKey() ?? [];

src/DMLQueryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
final class DMLQueryBuilder extends AbstractDMLQueryBuilder
3030
{
3131
/** @throws NotSupportedException */
32-
public function insertWithReturningPks(string $table, array|QueryInterface $columns, array &$params = []): string
32+
public function insertReturningPks(string $table, array|QueryInterface $columns, array &$params = []): string
3333
{
3434
throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.');
3535
}

tests/CommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testGetRawSql(string $sql, array $params, string $expectedRawSql
9999
parent::testGetRawSql($sql, $params, $expectedRawSql);
100100
}
101101

102-
public function testInsertWithReturningPksWithSubqueryAndNoAutoincrement(): void
102+
public function testInsertReturningPksWithSubqueryAndNoAutoincrement(): void
103103
{
104104
$db = $this->getConnection(true);
105105
$command = $db->createCommand();
@@ -108,10 +108,10 @@ public function testInsertWithReturningPksWithSubqueryAndNoAutoincrement(): void
108108

109109
$this->expectException(NotSupportedException::class);
110110
$this->expectExceptionMessage(
111-
'Yiisoft\Db\Mysql\Command::insertWithReturningPks() is not supported by MySQL for tables without auto increment when inserting sub-query.'
111+
'Yiisoft\Db\Mysql\Command::insertReturningPks() is not supported by MySQL for tables without auto increment when inserting sub-query.'
112112
);
113113

114-
$command->insertWithReturningPks('order_item', $query);
114+
$command->insertReturningPks('order_item', $query);
115115
}
116116

117117
#[DataProviderExternal(CommandProvider::class, 'update')]

tests/QueryBuilderTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,22 +408,23 @@ public function testInsert(
408408
parent::testInsert($table, $columns, $params, $expectedSQL, $expectedParams);
409409
}
410410

411-
#[DataProviderExternal(QueryBuilderProvider::class, 'insertWithReturningPks')]
412-
public function testInsertWithReturningPks(
411+
#[DataProviderExternal(QueryBuilderProvider::class, 'insertReturningPks')]
412+
public function testInsertReturningPks(
413413
string $table,
414414
array|QueryInterface $columns,
415415
array $params,
416416
string $expectedSQL,
417417
array $expectedParams
418418
): void {
419+
$db = $this->getConnection();
420+
$qb = $db->getQueryBuilder();
421+
419422
$this->expectException(NotSupportedException::class);
420423
$this->expectExceptionMessage(
421-
'Yiisoft\Db\Mysql\DMLQueryBuilder::insertWithReturningPks is not supported by MySQL.'
424+
'Yiisoft\Db\Mysql\DMLQueryBuilder::insertReturningPks is not supported by MySQL.'
422425
);
423426

424-
$db = $this->getConnection(true);
425-
$qb = $db->getQueryBuilder();
426-
$qb->insertWithReturningPks($table, $columns, $params);
427+
$qb->insertReturningPks($table, $columns, $params);
427428

428429
$db->close();
429430
}
@@ -515,7 +516,7 @@ public function testResetSequence(): void
515516
$this->assertSame($sql, $qb->resetSequence('item'));
516517

517518
$command->setSql($sql)->execute();
518-
$insertResult = $command->insertWithReturningPks('item', ['name' => '123', 'category_id' => 1]);
519+
$insertResult = $command->insertReturningPks('item', ['name' => '123', 'category_id' => 1]);
519520
$this->assertEquals(6, $insertResult['id']);
520521

521522
// Key as string.
@@ -526,7 +527,7 @@ public function testResetSequence(): void
526527
$this->assertSame($sql, $qb->resetSequence('item', '40'));
527528

528529
$command->setSql($sql)->execute();
529-
$insertResult = $command->insertWithReturningPks('item', ['name' => '123', 'category_id' => 1]);
530+
$insertResult = $command->insertReturningPks('item', ['name' => '123', 'category_id' => 1]);
530531
$this->assertEquals(40, $insertResult['id']);
531532

532533
// Change up, key as int.
@@ -537,7 +538,7 @@ public function testResetSequence(): void
537538
$this->assertSame($sql, $qb->resetSequence('item', 43));
538539

539540
$db->createCommand($sql)->execute();
540-
$insertResult = $command->insertWithReturningPks('item', ['name' => '123', 'category_id' => 1]);
541+
$insertResult = $command->insertReturningPks('item', ['name' => '123', 'category_id' => 1]);
541542
$this->assertEquals(43, $insertResult['id']);
542543

543544
$command->delete('item', ['>=','id', 6])->execute();
@@ -552,7 +553,7 @@ public function testResetSequence(): void
552553
$this->assertSame($sql, $qb->resetSequence('item'));
553554

554555
$db->createCommand($sql)->execute();
555-
$insertResult = $command->insertWithReturningPks('item', ['name' => '123', 'category_id' => 1]);
556+
$insertResult = $command->insertReturningPks('item', ['name' => '123', 'category_id' => 1]);
556557
$this->assertEquals(6, $insertResult['id']);
557558

558559
$db->close();

tests/SchemaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public function testTinyInt1()
454454
)->execute();
455455

456456
$status = 2;
457-
$insertedRow = $db->createCommand()->insertWithReturningPks($tableName, ['status' => $status, 'bool_col' => true]);
457+
$insertedRow = $db->createCommand()->insertReturningPks($tableName, ['status' => $status, 'bool_col' => true]);
458458
$selectedRow = $db->createCommand('SELECT * FROM ' . $tableName . ' WHERE id=:id', ['id' => $insertedRow['id']])->queryOne();
459459

460460
$this->assertEquals($status, $selectedRow['status']);

0 commit comments

Comments
 (0)