1
0
mirror of synced 2025-01-08 10:07:10 +03:00

Add tests

This commit is contained in:
Michaël Gallego 2013-12-22 15:01:16 +01:00 committed by Marco Pivetta
parent 0fa7b45a0e
commit 9813c2d5f1
3 changed files with 39 additions and 6 deletions

View File

@ -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())
{

View File

@ -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.
*

View File

@ -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());
}
}