Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the constructor arguments are passed to custom classes #3893

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/Doctrine/DBAL/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
14 changes: 13 additions & 1 deletion tests/Doctrine/Tests/DBAL/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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']);
}
}