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

params not passed from execute to logger #200

Merged
merged 4 commits into from
Sep 17, 2012
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
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public function bindParam($name, &$var, $type = PDO::PARAM_STR, $length = null)
*/
public function execute($params = null)
{
if (is_array($params)) {
$this->params = $params;
}

$logger = $this->conn->getConfiguration()->getSQLLogger();
if ($logger) {
$logger->startQuery($this->sql, $this->params, $this->types);
Expand Down
91 changes: 91 additions & 0 deletions tests/Doctrine/Tests/DBAL/StatementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Doctrine\Tests\DBAL;

use Doctrine\DBAL\Statement;

class StatementTest extends \Doctrine\Tests\DbalTestCase
{
/**
*
* @var \Doctrine\DBAL\Connection
*/
private $conn;

/**
*
* @var \Doctrine\DBAL\Configuration
*/
private $configuration;

public function setUp()
{
$pdoStatement = $this->getMock('\PDOStatment', array('execute', 'bindParam', 'bindValue'));
$platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
$driverConnection = $this->getMock('\Doctrine\DBAL\Driver\Connection');
$driverConnection->expects($this->any())
->method('prepare')
->will($this->returnValue($pdoStatement));

$driver = $this->getMock('\Doctrine\DBAL\Driver');
$constructorArgs = array(
array(
'platform' => $platform
),
$driver
);
$this->conn = $this->getMock('\Doctrine\DBAL\Connection', array(), $constructorArgs);
$this->conn->expects($this->atLeastOnce())
->method('getWrappedConnection')
->will($this->returnValue($driverConnection));

$this->configuration = $this->getMock('\Doctrine\DBAL\Configuration');
$this->conn->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($this->configuration));
}

public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound()
{
$name = 'foo';
$var = 'bar';
$type = \PDO::PARAM_STR;
$values = array($name => $var);
$types = array($name => $type);
$sql = '';

$logger = $this->getMock('\Doctrine\DBAL\Logging\SQLLogger');
$logger->expects($this->once())
->method('startQuery')
->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types));

$this->configuration->expects($this->once())
->method('getSQLLogger')
->will($this->returnValue($logger));

$statement = new Statement($sql, $this->conn);
$statement->bindValue($name, $var, $type);
$statement->execute();
}

public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedToExecute()
{
$name = 'foo';
$var = 'bar';
$values = array($name => $var);
$types = array();
$sql = '';

$logger = $this->getMock('\Doctrine\DBAL\Logging\SQLLogger');
$logger->expects($this->once())
->method('startQuery')
->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types));

$this->configuration->expects($this->once())
->method('getSQLLogger')
->will($this->returnValue($logger));

$statement = new Statement($sql, $this->conn);
$statement->execute($values);
}
}