Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'romulobusatto-fixture_paginator' into develop
  • Loading branch information
Ralph Schindler committed Feb 19, 2013
2 parents a5ff607 + 3ea5282 commit 35f2b8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions library/Zend/Paginator/Adapter/DbSelect.php
Expand Up @@ -109,6 +109,13 @@ public function count()
$select->reset(Select::ORDER);
$select->reset(Select::GROUP);

// get join information, clear, and repopulate without columns
$joins = $select->getRawState(Select::JOINS);
$select->reset(Select::JOINS);
foreach ($joins as $join) {
$select->join($join['name'], $join['on'], array(), $join['type']);
}

$select->columns(array('c' => new Expression('COUNT(1)')));

$statement = $this->sql->prepareStatementForSqlObject($select);
Expand Down
12 changes: 11 additions & 1 deletion tests/ZendTest/Paginator/Adapter/DbSelectTest.php
Expand Up @@ -62,7 +62,17 @@ public function testCount()
{
$this->mockSelect->expects($this->once())->method('columns')->with($this->equalTo(array('c' => new Expression('COUNT(1)'))));
$this->mockResult->expects($this->any())->method('current')->will($this->returnValue(array('c' => 5)));
$this->mockSelect->expects($this->exactly(5))->method('reset'); // called for columns, limit, offset, order

$this->mockSelect->expects($this->exactly(6))->method('reset'); // called for columns, limit, offset, order
$this->mockSelect->expects($this->once())->method('getRawState')->with($this->equalTo(Select::JOINS))
->will($this->returnValue(array(array('name' => 'Foo', 'on' => 'On Stuff', 'columns' => array('foo', 'bar'), 'type' => Select::JOIN_INNER))));
$this->mockSelect->expects($this->once())->method('join')->with(
'Foo',
'On Stuff',
array(),
Select::JOIN_INNER
);

$count = $this->dbSelect->count();
$this->assertEquals(5, $count);
}
Expand Down

0 comments on commit 35f2b8a

Please sign in to comment.