Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed error in adapter paginator DbTableGateway #4169

Closed
wants to merge 1 commit into from

2 participants

@moura137

Fixed error in paging adapter DbTableGateway because the condition was being added as the table name.

I added a third parameter to the ordination

@moura137 moura137 Fixed error in adapter paginator DbTableGateway, the condition was be…
…ing added as the table name.

I added a third parameter to the ordination
0ebf5ac
@weierophinney weierophinney commented on the diff
library/Zend/Paginator/Adapter/DbTableGateway.php
((6 lines not shown))
{
- $select = $tableGateway->getSql()->select($where);
+ $select = $tableGateway->getSql()->select();
+ if ($where) $select->where($where);
+ if ($order) $select->order($order);
@weierophinney Owner

Per the ZF coding standards, the two above lines need to be rewritten to use block form:

if ($where) {
    $select->where($where);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#4169] CS fixes
- Conditionals require block format
e2e5fd7
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#4169] Additional CS fixes
- per php-cs-fixer
77fadf8
@weierophinney

I made the requested changes on merge -- thanks for the patch!

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#4169] CS fixes
- Conditionals require block format
14fa68a
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#4169] Additional CS fixes
- per php-cs-fixer
85e7076
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4169' into develop
Close #4169
d715285
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-paginator
@weierophinney weierophinney [zendframework/zf2#4169] CS fixes
- Conditionals require block format
1ee159f
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-paginator
@weierophinney weierophinney [zendframework/zf2#4169] Additional CS fixes
- per php-cs-fixer
9e14aa0
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-paginator
@weierophinney weierophinney Merge branch 'hotfix/4169' into develop 09f0424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2013
  1. @moura137

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

    moura137 authored
    …ing added as the table name.
    
    I added a third parameter to the ordination
This page is out of date. Refresh to see the latest.
View
7 library/Zend/Paginator/Adapter/DbTableGateway.php
@@ -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);
@weierophinney Owner

Per the ZF coding standards, the two above lines need to be rewritten to use block form:

if ($where) {
    $select->where($where);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
$dbAdapter = $tableGateway->getAdapter();
$resultSetPrototype = $tableGateway->getResultSetPrototype();
View
27 tests/ZendTest/Paginator/Adapter/DbTableGatewayTest.php
@@ -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);
+ }
}
Something went wrong with that request. Please try again.