This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR #2807 Added unit tests for hydrator buffer handling
Signed-off-by: Ralph Schindler <ralph.schindler@zend.com>
- Loading branch information
Ralph Schindler
committed
Jan 4, 2013
1 parent
6fc56cb
commit 020b9c1
Showing
5 changed files
with
303 additions
and
1 deletion.
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
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,210 @@ | ||
<?php | ||
namespace ZendTest\Db\ResultSet; | ||
|
||
class AbstractResultSetTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $resultSet; | ||
|
||
/** | ||
* Sets up the fixture, for example, opens a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::initialize | ||
*/ | ||
public function testInitialize() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
|
||
$this->assertSame($resultSet, $resultSet->initialize(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
|
||
$this->setExpectedException( | ||
'Zend\Db\ResultSet\Exception\InvalidArgumentException', | ||
'DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate' | ||
); | ||
$resultSet->initialize('foo'); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::buffer | ||
*/ | ||
public function testBuffer() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$this->assertSame($resultSet, $resultSet->buffer()); | ||
|
||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$resultSet->next(); // start iterator | ||
$this->setExpectedException( | ||
'Zend\Db\ResultSet\Exception\RuntimeException', | ||
'Buffering must be enabled before iteration is started' | ||
); | ||
$resultSet->buffer(); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::isBuffered | ||
*/ | ||
public function testIsBuffered() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$this->assertFalse($resultSet->isBuffered()); | ||
$resultSet->buffer(); | ||
$this->assertTrue($resultSet->isBuffered()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::getDataSource | ||
*/ | ||
public function testGetDataSource() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$this->assertInstanceOf('\ArrayIterator', $resultSet->getDataSource()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::getFieldCount | ||
*/ | ||
public function testGetFieldCount() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
))); | ||
$this->assertEquals(2, $resultSet->getFieldCount()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::next | ||
*/ | ||
public function testNext() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$this->assertNull($resultSet->next()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::key | ||
*/ | ||
public function testKey() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$resultSet->next(); | ||
$this->assertEquals(1, $resultSet->key()); | ||
$resultSet->next(); | ||
$this->assertEquals(2, $resultSet->key()); | ||
$resultSet->next(); | ||
$this->assertEquals(3, $resultSet->key()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::current | ||
*/ | ||
public function testCurrent() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$this->assertEquals(array('id' => 1, 'name' => 'one'), $resultSet->current()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::valid | ||
*/ | ||
public function testValid() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$this->assertTrue($resultSet->valid()); | ||
$resultSet->next(); $resultSet->next(); $resultSet->next(); | ||
$this->assertFalse($resultSet->valid()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::rewind | ||
*/ | ||
public function testRewind() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$this->assertNull($resultSet->rewind()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::count | ||
*/ | ||
public function testCount() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$this->assertEquals(3, $resultSet->count()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\AbstractResultSet::toArray | ||
*/ | ||
public function testToArray() | ||
{ | ||
$resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet'); | ||
$resultSet->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
))); | ||
$this->assertEquals( | ||
array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
array('id' => 3, 'name' => 'three'), | ||
), | ||
$resultSet->toArray() | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/ZendTest/Db/ResultSet/HydratingResultSetIntegrationTest.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,26 @@ | ||
<?php | ||
namespace ZendTest\Db\ResultSet; | ||
|
||
use Zend\Db\ResultSet\HydratingResultSet; | ||
|
||
class HydratingResultSetIntegrationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\HydratingResultSet::current | ||
*/ | ||
public function testCurrentWillReturnBufferedRow() | ||
{ | ||
$hydratingRs = new HydratingResultSet; | ||
$hydratingRs->initialize(new \ArrayIterator(array( | ||
array('id' => 1, 'name' => 'one'), | ||
array('id' => 2, 'name' => 'two'), | ||
))); | ||
$hydratingRs->buffer(); | ||
$obj1 = $hydratingRs->current(); | ||
$hydratingRs->rewind(); | ||
$obj2 = $hydratingRs->current(); | ||
$this->assertSame($obj1, $obj2); | ||
} | ||
|
||
} |
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,62 @@ | ||
<?php | ||
namespace ZendTest\Db\ResultSet; | ||
|
||
use Zend\Db\ResultSet\HydratingResultSet; | ||
|
||
class HydratingResultSetTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @covers Zend\Db\ResultSet\HydratingResultSet::setObjectPrototype | ||
*/ | ||
public function testSetObjectPrototype() | ||
{ | ||
$prototype = new \stdClass; | ||
$hydratingRs = new HydratingResultSet; | ||
$this->assertSame($hydratingRs, $hydratingRs->setObjectPrototype($prototype)); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\HydratingResultSet::setHydrator | ||
*/ | ||
public function testSetHydrator() | ||
{ | ||
$hydratingRs = new HydratingResultSet; | ||
$this->assertSame($hydratingRs, $hydratingRs->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods())); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\HydratingResultSet::getHydrator | ||
*/ | ||
public function testGetHydrator() | ||
{ | ||
$hydratingRs = new HydratingResultSet; | ||
$this->assertInstanceOf('Zend\Stdlib\Hydrator\ArraySerializable', $hydratingRs->getHydrator()); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\HydratingResultSet::current | ||
*/ | ||
public function testCurrent() | ||
{ | ||
$hydratingRs = new HydratingResultSet; | ||
$hydratingRs->initialize(array( | ||
array('id' => 1, 'name' => 'one') | ||
)); | ||
$obj = $hydratingRs->current(); | ||
$this->assertInstanceOf('ArrayObject', $obj); | ||
} | ||
|
||
/** | ||
* @covers Zend\Db\ResultSet\HydratingResultSet::toArray | ||
* @todo Implement testToArray(). | ||
*/ | ||
public function testToArray() | ||
{ | ||
$hydratingRs = new HydratingResultSet; | ||
$hydratingRs->initialize(array( | ||
array('id' => 1, 'name' => 'one') | ||
)); | ||
$obj = $hydratingRs->toArray(); | ||
$this->assertInternalType('array', $obj); | ||
} | ||
} |
File renamed without changes.