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

Commit

Permalink
Merged Source/Master
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "2.5-dev"
"dev-master": "2.1-dev",
"dev-develop": "2.2-dev"
}
},
"autoload-dev": {
Expand Down
8 changes: 8 additions & 0 deletions src/Adapter/DbSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ public function count()
$select->reset(Select::LIMIT);
$select->reset(Select::OFFSET);
$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
2 changes: 1 addition & 1 deletion src/AdapterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AdapterPluginManager extends AbstractPluginManager
* @param string $canonicalName
* @param string $requestedName
* @return mixed
* @throws Exception\ServiceNotCreatedException If factory is not callable
* @throws \Zend\ServiceManager\Exception\ServiceNotCreatedException If factory is not callable
*/
protected function createFromFactory($canonicalName, $requestedName)
{
Expand Down
12 changes: 11 additions & 1 deletion test/Adapter/DbSelectTest.php
Original file line number Diff line number Diff line change
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(4))->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 e7612d4

Please sign in to comment.