Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'AgentCoop-master'

* AgentCoop-master:
  Added unit tests for PDO bool behavior, added stub for StatementTest
  Empty string is a nonvalid literal value for the PostgreSQL boolean type. Fixed
  • Loading branch information
Ralph Schindler committed Nov 22, 2013
2 parents 51ee47f + 6904db5 commit 2c30ef6
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 4 deletions.
9 changes: 5 additions & 4 deletions library/Zend/Db/Adapter/Driver/Pdo/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ protected function bindParametersFromContainer()

$parameters = $this->parameterContainer->getNamedArray();
foreach ($parameters as $name => &$value) {
$type = \PDO::PARAM_STR;
if (is_bool($value)) {
$type = \PDO::PARAM_BOOL;
} else {
$type = \PDO::PARAM_STR;
}
if ($this->parameterContainer->offsetHasErrata($name)) {
switch ($this->parameterContainer->offsetGetErrata($name)) {
case ParameterContainer::TYPE_INTEGER:
Expand All @@ -276,9 +280,6 @@ protected function bindParametersFromContainer()
case ParameterContainer::TYPE_LOB:
$type = \PDO::PARAM_LOB;
break;
case (is_bool($value)):
$type = \PDO::PARAM_BOOL;
break;
}
}

Expand Down
67 changes: 67 additions & 0 deletions tests/ZendTest/Db/Adapter/Driver/Pdo/StatementIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Db\Adapter\Driver\Pdo;

use Zend\Db\Adapter\Driver\Pdo\Statement;

class StatementTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Statement
*/
protected $statement;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $pdoStatementMock = null;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->statement = new Statement;
$this->statement->setDriver($this->getMock('Zend\Db\Adapter\Driver\Pdo\Pdo', array('createResult'), array(), '', false));
$this->statement->initialize(new TestAsset\CtorlessPdo(
$this->pdoStatementMock = $this->getMock('PDOStatement', array('execute', 'bindParam')))
);
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}

public function testStatementExecuteWillConvertPhpBoolToPdoBoolWhenBinding()
{
$this->pdoStatementMock->expects($this->any())->method('bindParam')->with(
$this->equalTo('foo'),
$this->equalTo(false),
$this->equalTo(\PDO::PARAM_BOOL)
);
$this->statement->execute(['foo' => false]);
}

public function testStatementExecuteWillUsePdoStrByDefaultWhenBinding()
{
$this->pdoStatementMock->expects($this->any())->method('bindParam')->with(
$this->equalTo('foo'),
$this->equalTo('bar'),
$this->equalTo(\PDO::PARAM_STR)
);
$this->statement->execute(['foo' => 'bar']);
}

}
138 changes: 138 additions & 0 deletions tests/ZendTest/Db/Adapter/Driver/Pdo/StatementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Db\Adapter\Driver\Pdo;

use Zend\Db\Adapter\Driver\Pdo\Statement;
use Zend\Db\Adapter\Driver\Pdo\Pdo;
use Zend\Db\Adapter\ParameterContainer;

class StatementTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Statement
*/
protected $statement;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->statement = new Statement;
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::setDriver
*/
public function testSetDriver()
{
$this->assertEquals($this->statement, $this->statement->setDriver(new Pdo(array())));
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::setParameterContainer
*/
public function testSetParameterContainer()
{
$this->assertSame($this->statement, $this->statement->setParameterContainer(new ParameterContainer));
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::getParameterContainer
* @todo Implement testGetParameterContainer().
*/
public function testGetParameterContainer()
{
$container = new ParameterContainer;
$this->statement->setParameterContainer($container);
$this->assertSame($container, $this->statement->getParameterContainer());
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::getResource
* @todo Implement testGetResource().
*/
public function testGetResource()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::setSql
* @todo Implement testSetSql().
*/
public function testSetSql()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::getSql
* @todo Implement testGetSql().
*/
public function testGetSql()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::prepare
* @todo Implement testPrepare().
*/
public function testPrepare()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::isPrepared
* @todo Implement testIsPrepared().
*/
public function testIsPrepared()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers Zend\Db\Adapter\Driver\Pdo\Statement::execute
* @todo Implement testExecute().
*/
public function testExecute()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}
19 changes: 19 additions & 0 deletions tests/ZendTest/Db/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace ZendTest\Db\Adapter\Driver\Pdo\TestAsset;

class CtorlessPdo extends \Pdo
{
protected $mockStatement;

public function __construct($mockStatement)
{
$this->mockStatement = $mockStatement;
}

public function prepare($sql, $options = null)
{
return $this->mockStatement;
}

}

0 comments on commit 2c30ef6

Please sign in to comment.