forked from zendframework/zendframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
229 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
tests/ZendTest/Db/Adapter/Driver/Pdo/StatementIntegrationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
tests/ZendTest/Db/Adapter/Driver/Pdo/TestAsset/CtorlessPdo.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |