diff --git a/composer.json b/composer.json index 3554dd3..c6949e1 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Adapter/DbSelect.php b/src/Adapter/DbSelect.php index d4a894e..3919de1 100644 --- a/src/Adapter/DbSelect.php +++ b/src/Adapter/DbSelect.php @@ -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); diff --git a/src/AdapterPluginManager.php b/src/AdapterPluginManager.php index 30a6410..f7d5315 100644 --- a/src/AdapterPluginManager.php +++ b/src/AdapterPluginManager.php @@ -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) { diff --git a/test/Adapter/DbSelectTest.php b/test/Adapter/DbSelectTest.php index 8a4e0fa..ac21f28 100644 --- a/test/Adapter/DbSelectTest.php +++ b/test/Adapter/DbSelectTest.php @@ -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); }