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

Commit 177d204

Browse files
author
Ralph Schindler
committed
* added better testing for DbTableGateway paginator
1 parent 201a0dd commit 177d204

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/Adapter/DbTableGateway.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class DbTableGateway extends DbSelect
2727
*/
2828
public function __construct(TableGateway $tableGateway, $where = null, $order = null, $group = null, $having = null)
2929
{
30-
$select = $tableGateway->getSql()->select();
30+
$sql = $tableGateway->getSql();
31+
$select = $sql->select();
3132
if ($where) {
3233
$select->where($where);
3334
}
@@ -41,9 +42,7 @@ public function __construct(TableGateway $tableGateway, $where = null, $order =
4142
$select->having($having);
4243
}
4344

44-
$dbAdapter = $tableGateway->getAdapter();
4545
$resultSetPrototype = $tableGateway->getResultSetPrototype();
46-
47-
parent::__construct($select, $dbAdapter, $resultSetPrototype);
46+
parent::__construct($select, $sql, $resultSetPrototype);
4847
}
4948
}

test/Adapter/DbTableGatewayTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace ZendTest\Paginator\Adapter;
1212

13+
use Zend\Db\Adapter\Platform\Sql92;
1314
use Zend\Paginator\Adapter\DbTableGateway;
1415
use Zend\Paginator\Adapter\DbSelect;
1516
use Zend\Db\ResultSet\ResultSet;
@@ -25,6 +26,7 @@ class DbTableGatewayTest extends \PHPUnit_Framework_TestCase
2526
/** @var DbTableGateway */
2627
protected $dbTableGateway;
2728

29+
/** @var \Zend\Db\TableGateway\TableGateway */
2830
protected $mockTableGateway;
2931

3032
public function setup()
@@ -34,13 +36,12 @@ public function setup()
3436
$mockDriver->expects($this->any())
3537
->method('createStatement')
3638
->will($this->returnValue($mockStatement));
37-
$mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
38-
$mockPlatform->expects($this->any())
39-
->method('getName')
40-
->will($this->returnValue('platform'));
39+
$mockDriver->expects($this->any())
40+
->method('formatParameterName')
41+
->will($this->returnArgument(0));
4142
$mockAdapter = $this->getMockForAbstractClass(
4243
'Zend\Db\Adapter\Adapter',
43-
array($mockDriver, $mockPlatform)
44+
array($mockDriver, new Sql92())
4445
);
4546

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

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

129134
$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
130135
$this->mockStatement
131-
->expects($this->any())
132-
->method('execute')
133-
->will($this->returnValue($mockResult));
136+
->expects($this->once())
137+
->method('setSql')
138+
->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'));
139+
$this->mockStatement
140+
->expects($this->any())
141+
->method('execute')
142+
->will($this->returnValue($mockResult));
134143

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

0 commit comments

Comments
 (0)