Permalink
Browse files

Fixed error in adapter paginator DbTableGateway, the condition was be…

…ing added as the table name.

I added a third parameter to the ordination
  • Loading branch information...
1 parent 0433db6 commit 0ebf5acccf618cd5a9882cc53445e60f075c2dda @moura137 committed Apr 2, 2013
@@ -20,9 +20,12 @@ class DbTableGateway extends DbSelect
* @param TableGateway $tableGateway
* @param Where|\Closure|string|array $where
*/
- public function __construct(TableGateway $tableGateway, $where = null)
+ public function __construct(TableGateway $tableGateway, $where = null, $order = null)
{
- $select = $tableGateway->getSql()->select($where);
+ $select = $tableGateway->getSql()->select();
+ if ($where) $select->where($where);
+ if ($order) $select->order($order);
+
$dbAdapter = $tableGateway->getAdapter();
$resultSetPrototype = $tableGateway->getResultSetPrototype();
@@ -24,7 +24,9 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase
/** @var DbTableGateway */
protected $dbTableGateway;
-
+
+ protected $mockTableGateway;
+
public function setup()
{
$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
@@ -48,11 +50,14 @@ public function setup()
);
$this->mockStatement = $mockStatement;
- $this->dbTableGateway = new DbTableGateway($mockTableGateway);
+
+ $this->mockTableGateway = $mockTableGateway;
}
public function testGetItems()
{
+ $this->dbTableGateway = new DbTableGateway($this->mockTableGateway);
+
$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
$this->mockStatement
->expects($this->any())
@@ -65,6 +70,8 @@ public function testGetItems()
public function testCount()
{
+ $this->dbTableGateway = new DbTableGateway($this->mockTableGateway);
+
$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
$mockResult->expects($this->any())
->method('current')
@@ -77,4 +84,20 @@ public function testCount()
$count = $this->dbTableGateway->count();
$this->assertEquals(10, $count);
}
+
+ public function testGetItemsWithWhereAndOrder()
+ {
+ $where = "foo = bar";
+ $order = "foo";
+ $this->dbTableGateway = new DbTableGateway($this->mockTableGateway, $where, $order);
+
+ $mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
+ $this->mockStatement
+ ->expects($this->any())
+ ->method('execute')
+ ->will($this->returnValue($mockResult));
+
+ $items = $this->dbTableGateway->getItems(2, 10);
+ $this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
+ }
}

0 comments on commit 0ebf5ac

Please sign in to comment.