diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 09913bb56a..13140a6a60 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -249,11 +249,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { - if ($fetchArgument) { - return $this->stmt->fetchAll($fetchMode, $fetchArgument); - } - - return $this->stmt->fetchAll($fetchMode); + return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs); } /** diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index bb86e9cab3..1c0794ac4c 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\Connection as DriverConnection; +use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; @@ -28,7 +29,7 @@ class StatementTest extends DbalTestCase protected function setUp() : void { $this->pdoStatement = $this->getMockBuilder(PDOStatement::class) - ->onlyMethods(['execute', 'bindParam', 'bindValue']) + ->onlyMethods(['execute', 'bindParam', 'bindValue', 'fetchAll']) ->getMock(); $driverConnection = $this->createMock(DriverConnection::class); @@ -150,4 +151,15 @@ public function testExecuteCallsLoggerStopQueryOnException() : void $statement->execute(); } + + public function testPDOCustomClassConstructorArgs() : void + { + $statement = new Statement('', $this->conn); + + $this->pdoStatement->expects($this->once()) + ->method('fetchAll') + ->with(self::equalTo(FetchMode::CUSTOM_OBJECT), self::equalTo('Example'), self::equalTo(['arg1'])); + + $statement->fetchAll(FetchMode::CUSTOM_OBJECT, 'Example', ['arg1']); + } }