diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index f13a01479..1bf5f4347 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -811,8 +811,7 @@ class BasicEntityPersister implements EntityPersister } /** - * @param array|Criteria $criteria - * @return int + * {@inheritDoc} */ public function count($criteria = array()) { @@ -1082,10 +1081,7 @@ class BasicEntityPersister implements EntityPersister } /** - * Get the COUNT SQL to count entities (optionally based on a criteria) - * - * @param array|Criteria $criteria - * @return string + * {@inheritDoc} */ public function getCountSQL($criteria = array()) { diff --git a/lib/Doctrine/ORM/Persisters/EntityPersister.php b/lib/Doctrine/ORM/Persisters/EntityPersister.php index d40c2c6af..747ab5802 100644 --- a/lib/Doctrine/ORM/Persisters/EntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/EntityPersister.php @@ -74,6 +74,14 @@ interface EntityPersister */ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = null); + /** + * Get the COUNT SQL to count entities (optionally based on a criteria) + * + * @param array|\Doctrine\Common\Collections\Criteria $criteria + * @return string + */ + public function getCountSQL($criteria = array()); + /** * Expands the parameters from the given criteria and use the correct binding types if found. * @@ -149,6 +157,14 @@ interface EntityPersister */ public function delete($entity); + /** + * Count entities (optionally filtered by a criteria) + * + * @param array|\Doctrine\Common\Collections\Criteria $criteria + * @return int + */ + public function count($criteria = array()); + /** * Gets the name of the table that owns the column the given field is mapped to. * diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index bbe8875e3..b9c2ed7bb 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\ORM\Persisters; +use Doctrine\Common\Collections\Criteria; use Doctrine\DBAL\Types\Type as DBALType; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Persisters\BasicEntityPersister; use Doctrine\Tests\Models\CustomType\CustomTypeParent; use Doctrine\Tests\Models\CustomType\CustomTypeChild; @@ -139,4 +141,23 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase $this->_persister->getSelectConditionStatementSQL('id', array(123, null)) ); } + + public function testCountCondition() + { + $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\SimpleEntity')); + + // Using a criteria as array + $statement = $persister->getCountSQL(array('value' => 'bar')); + $this->assertEquals('SELECT COUNT(*) FROM "ddc-1719-simple-entity" t0 WHERE t0."simple-entity-value" = ?', $statement); + + // Using a criteria object + $criteria = new Criteria(Criteria::expr()->eq('value', 'bar')); + $statement = $persister->getCountSQL($criteria); + $this->assertEquals('SELECT COUNT(*) FROM "ddc-1719-simple-entity" t0 WHERE t0."simple-entity-value" = ?', $statement); + } + + public function testCountEntities() + { + $this->assertEquals(0, $this->_persister->count()); + } }