Skip to content

Commit

Permalink
Optimize insertFixture in database test trait
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Nov 27, 2022
1 parent 0e6e183 commit ab435aa
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Traits/DatabaseTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use DomainException;
use PDO;
use PDOException;
use PDOStatement;
use UnexpectedValueException;

Expand Down Expand Up @@ -252,14 +251,9 @@ function (&$value) {
$statement = $this->createPreparedStatement(sprintf('INSERT INTO `%s` SET %s', $table, implode(',', $fields)));
$statement->execute($row);

try {
$lastInsertId = $this->getConnection()->lastInsertId();
$lastInsertId = $this->getConnection()->lastInsertId();

return !empty($lastInsertId) && is_numeric($lastInsertId) ? (int)$lastInsertId : null;
} catch (PDOException $PDOException) {
// If the PDO driver does not support this capability
return null;
}
return $lastInsertId !== false ? (int)$lastInsertId : null;
}

/**
Expand Down

0 comments on commit ab435aa

Please sign in to comment.