Browse Source

Update signature of DriverInterface::lastInsertId().

It now better corresponds to the signature of PDO::lastInsertId().
ADmad 4 years ago
parent
commit
1efd0f325d

+ 2 - 7
src/Database/Driver.php

@@ -330,16 +330,11 @@ abstract class Driver implements DriverInterface
     /**
      * @inheritDoc
      */
-    public function lastInsertId(?string $table = null, ?string $column = null): string|int
+    public function lastInsertId(?string $table = null): string
     {
         $this->connect();
 
-        /** @psalm-suppress RedundantCondition */
-        if ($this->_connection instanceof PDO) {
-            return $this->_connection->lastInsertId($table);
-        }
-
-        return $this->_connection->lastInsertId($table, $column);
+        return $this->_connection->lastInsertId($table);
     }
 
     /**

+ 2 - 3
src/Database/DriverInterface.php

@@ -234,10 +234,9 @@ interface DriverInterface
      * Returns last id generated for a table or sequence in database.
      *
      * @param string|null $table table name or sequence to get last insert value from.
-     * @param string|null $column the name of the column representing the primary key.
-     * @return string|int
+     * @return string
      */
-    public function lastInsertId(?string $table = null, ?string $column = null): string|int;
+    public function lastInsertId(?string $table = null): string;
 
     /**
      * Checks whether the driver is connected.

+ 1 - 1
src/Database/Statement/StatementDecorator.php

@@ -348,7 +348,7 @@ class StatementDecorator implements StatementInterface, Countable, IteratorAggre
             }
         }
 
-        return $this->_driver->lastInsertId($table, $column);
+        return $this->_driver->lastInsertId($table);
     }
 
     /**

+ 2 - 2
tests/TestCase/Database/Statement/StatementDecoratorTest.php

@@ -37,8 +37,8 @@ class StatementDecoratorTest extends TestCase
 
         $driver->expects($this->once())->method('lastInsertId')
             ->with('users')
-            ->will($this->returnValue(2));
-        $this->assertSame(2, $statement->lastInsertId('users'));
+            ->will($this->returnValue('2'));
+        $this->assertSame('2', $statement->lastInsertId('users'));
     }
 
     /**