Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
* added better testing for DbTableGateway paginator
  • Loading branch information
Ralph Schindler committed May 9, 2013
1 parent 201a0dd commit 177d204
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/Adapter/DbTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class DbTableGateway extends DbSelect
*/
public function __construct(TableGateway $tableGateway, $where = null, $order = null, $group = null, $having = null)
{
$select = $tableGateway->getSql()->select();
$sql = $tableGateway->getSql();
$select = $sql->select();
if ($where) {
$select->where($where);
}
Expand All @@ -41,9 +42,7 @@ public function __construct(TableGateway $tableGateway, $where = null, $order =
$select->having($having);
}

$dbAdapter = $tableGateway->getAdapter();
$resultSetPrototype = $tableGateway->getResultSetPrototype();

parent::__construct($select, $dbAdapter, $resultSetPrototype);
parent::__construct($select, $sql, $resultSetPrototype);
}
}
25 changes: 17 additions & 8 deletions test/Adapter/DbTableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace ZendTest\Paginator\Adapter;

use Zend\Db\Adapter\Platform\Sql92;
use Zend\Paginator\Adapter\DbTableGateway;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Db\ResultSet\ResultSet;
Expand All @@ -25,6 +26,7 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase
/** @var DbTableGateway */
protected $dbTableGateway;

/** @var \Zend\Db\TableGateway\TableGateway */
protected $mockTableGateway;

public function setup()
Expand All @@ -34,13 +36,12 @@ public function setup()
$mockDriver->expects($this->any())
->method('createStatement')
->will($this->returnValue($mockStatement));
$mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
$mockPlatform->expects($this->any())
->method('getName')
->will($this->returnValue('platform'));
$mockDriver->expects($this->any())
->method('formatParameterName')
->will($this->returnArgument(0));
$mockAdapter = $this->getMockForAbstractClass(
'Zend\Db\Adapter\Adapter',
array($mockDriver, $mockPlatform)
array($mockDriver, new Sql92())
);

$tableName = 'foobar';
Expand Down Expand Up @@ -109,6 +110,10 @@ public function testGetItemsWithWhereAndOrderAndGroup()
$this->dbTableGateway = new DbTableGateway($this->mockTableGateway, $where, $order, $group);

$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
$this->mockStatement
->expects($this->once())
->method('setSql')
->with($this->equalTo('SELECT "foobar".* FROM "foobar" WHERE foo = bar GROUP BY "foo" ORDER BY "foo" ASC LIMIT limit OFFSET offset'));
$this->mockStatement
->expects($this->any())
->method('execute')
Expand All @@ -128,9 +133,13 @@ public function testGetItemsWithWhereAndOrderAndGroupAndHaving()

$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
$this->mockStatement
->expects($this->any())
->method('execute')
->will($this->returnValue($mockResult));
->expects($this->once())
->method('setSql')
->with($this->equalTo('SELECT "foobar".* FROM "foobar" WHERE foo = bar GROUP BY "foo" HAVING count(foo)>0 ORDER BY "foo" ASC LIMIT limit OFFSET offset'));
$this->mockStatement
->expects($this->any())
->method('execute')
->will($this->returnValue($mockResult));

$items = $this->dbTableGateway->getItems(2, 10);
$this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
Expand Down

0 comments on commit 177d204

Please # to comment.