1
0
mirror of synced 2025-02-09 08:49:26 +03:00

Merge pull request #5668 from petitchevalroux/many-to-many-criteria-fixes

Many to many criteria fixes
This commit is contained in:
Guilherme Blanco 2016-02-15 21:07:17 -05:00
commit d814ad7234
9 changed files with 361 additions and 21 deletions

View File

@ -236,29 +236,41 @@ class ManyToManyPersister extends AbstractCollectionPersister
$mapping = $collection->getMapping();
$owner = $collection->getOwner();
$ownerMetadata = $this->em->getClassMetadata(get_class($owner));
$id = $this->uow->getEntityIdentifier($owner);
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
$onConditions = $this->getOnConditionSQL($mapping);
$whereClauses = $params = array();
foreach ($mapping['relationToSourceKeyColumns'] as $key => $value) {
if ( ! $mapping['isOwningSide']) {
$associationSourceClass = $targetClass;
$mapping = $targetClass->associationMappings[$mapping['mappedBy']];
$sourceRelationMode = 'relationToTargetKeyColumns';
} else {
$associationSourceClass = $ownerMetadata;
$sourceRelationMode = 'relationToSourceKeyColumns';
}
foreach ($mapping[$sourceRelationMode] as $key => $value) {
$whereClauses[] = sprintf('t.%s = ?', $key);
$params[] = $ownerMetadata->getFieldValue($owner, $value);
$params[] = $ownerMetadata->containsForeignIdentifier
? $id[$ownerMetadata->getFieldForColumn($value)]
: $id[$ownerMetadata->fieldNames[$value]];
}
$parameters = $this->expandCriteriaParameters($criteria);
foreach ($parameters as $parameter) {
list($name, $value) = $parameter;
$whereClauses[] = sprintf('te.%s = ?', $name);
$field = $this->quoteStrategy->getColumnName($name, $targetClass, $this->platform);
$whereClauses[] = sprintf('te.%s = ?', $field);
$params[] = $value;
}
$mapping = $collection->getMapping();
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
$tableName = $this->quoteStrategy->getTableName($targetClass, $this->platform);
$joinTable = $this->quoteStrategy->getJoinTableName($mapping, $ownerMetadata, $this->platform);
$onConditions = $this->getOnConditionSQL($mapping);
$joinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform);
$rsm = new Query\ResultSetMappingBuilder($this->em);
$rsm->addRootEntityFromClassMetadata($mapping['targetEntity'], 'te');
$rsm->addRootEntityFromClassMetadata($targetClass->name, 'te');
$sql = 'SELECT ' . $rsm->generateSelectClause()
. ' FROM ' . $tableName . ' te'
@ -266,6 +278,10 @@ class ManyToManyPersister extends AbstractCollectionPersister
. implode(' AND ', $onConditions)
. ' WHERE ' . implode(' AND ', $whereClauses);
$sql .= $this->getOrderingSql($criteria, $targetClass);
$sql .= $this->getLimitSql($criteria);
$stmt = $this->conn->executeQuery($sql, $params);
return $this
@ -728,4 +744,43 @@ class ManyToManyPersister extends AbstractCollectionPersister
return $types;
}
/**
* @param Criteria $criteria
* @param ClassMetadata $targetClass
* @return string
*/
private function getOrderingSql(Criteria $criteria, ClassMetadata $targetClass)
{
$orderings = $criteria->getOrderings();
if ($orderings) {
$orderBy = [];
foreach ($orderings as $name => $direction) {
$field = $this->quoteStrategy->getColumnName(
$name,
$targetClass,
$this->platform
);
$orderBy[] = $field . ' ' . $direction;
}
return ' ORDER BY ' . implode(', ', $orderBy);
}
return '';
}
/**
* @param Criteria $criteria
* @return string
* @throws \Doctrine\DBAL\DBALException
*/
private function getLimitSql(Criteria $criteria)
{
$limit = $criteria->getMaxResults();
$offset = $criteria->getFirstResult();
if ($limit !== null || $offset !== null) {
return $this->platform->modifyLimitQuery('', $limit, $offset);
}
return '';
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace Doctrine\Tests\Models\CMS;
/**
* Description of CmsTag
*
* @Entity
* @Table(name="cms_tags")
*/
class CmsTag
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;
/**
* @Column(length=50, name="tag_name", nullable=true)
*/
public $name;
/**
* @ManyToMany(targetEntity="CmsUser", mappedBy="tags")
*/
public $users;
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function addUser(CmsUser $user) {
$this->users[] = $user;
}
public function getUsers() {
return $this->users;
}
}

View File

@ -162,6 +162,14 @@ class CmsUser
* )
*/
public $groups;
/**
* @ManyToMany(targetEntity="CmsTag", inversedBy="users", cascade={"all"})
* @JoinTable(name="cms_users_tags",
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="tag_id", referencedColumnName="id")}
* )
*/
public $tags;
public $nonPersistedProperty;
@ -171,6 +179,7 @@ class CmsUser
$this->phonenumbers = new ArrayCollection;
$this->articles = new ArrayCollection;
$this->groups = new ArrayCollection;
$this->tags = new ArrayCollection;
}
public function getId() {
@ -217,6 +226,15 @@ class CmsUser
return $this->groups;
}
public function addTag(CmsTag $tag) {
$this->tags[] = $tag;
$tag->addUser($this);
}
public function getTags() {
return $this->tags;
}
public function removePhonenumber($index) {
if (isset($this->phonenumbers[$index])) {
$ph = $this->phonenumbers[$index];

View File

@ -117,15 +117,18 @@ class DatabaseDriverTest extends DatabaseDriverTestCase
$this->markTestSkipped('Platform does not support foreign keys.');
}
$metadatas = $this->extractClassMetadata(array("CmsUsers", "CmsGroups"));
$metadatas = $this->extractClassMetadata(array("CmsUsers", "CmsGroups", "CmsTags"));
$this->assertArrayHasKey('CmsUsers', $metadatas, 'CmsUsers entity was not detected.');
$this->assertArrayHasKey('CmsGroups', $metadatas, 'CmsGroups entity was not detected.');
$this->assertArrayHasKey('CmsTags', $metadatas, 'CmsTags entity was not detected.');
$this->assertEquals(2, count($metadatas['CmsUsers']->associationMappings));
$this->assertEquals(3, count($metadatas['CmsUsers']->associationMappings));
$this->assertArrayHasKey('group', $metadatas['CmsUsers']->associationMappings);
$this->assertEquals(1, count($metadatas['CmsGroups']->associationMappings));
$this->assertArrayHasKey('user', $metadatas['CmsGroups']->associationMappings);
$this->assertEquals(1, count($metadatas['CmsTags']->associationMappings));
$this->assertArrayHasKey('user', $metadatas['CmsGroups']->associationMappings);
}
public function testIgnoreManyToManyTableWithoutFurtherForeignKeyDetails()

View File

@ -3,6 +3,7 @@
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Tests\Models\CMS\CmsTag;
use Doctrine\Tests\Models\CMS\CmsUser,
Doctrine\Tests\Models\CMS\CmsGroup,
Doctrine\Common\Collections\ArrayCollection;
@ -377,6 +378,154 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa
$this->assertEquals(0, count($user->groups));
}
/**
* @group DDC-3952
*/
public function testManyToManyOrderByIsNotIgnored()
{
$user = $this->addCmsUserGblancoWithGroups(1);
$group1 = new CmsGroup;
$group2 = new CmsGroup;
$group3 = new CmsGroup;
$group1->name = 'C';
$group2->name = 'A';
$group3->name = 'B';
$user->addGroup($group1);
$user->addGroup($group2);
$user->addGroup($group3);
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$user = $this->_em->find(get_class($user), $user->id);
$criteria = Criteria::create()
->orderBy(['name' => Criteria::ASC]);
$this->assertEquals(
['A', 'B', 'C', 'Developers_0'],
$user
->getGroups()
->matching($criteria)
->map(function (CmsGroup $group) {
return $group->getName();
})
->toArray()
);
}
/**
* @group DDC-3952
*/
public function testManyToManyOrderByHonorsFieldNameColumnNameAliases()
{
$user = new CmsUser;
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
$tag1 = new CmsTag;
$tag2 = new CmsTag;
$tag3 = new CmsTag;
$tag1->name = 'C';
$tag2->name = 'A';
$tag3->name = 'B';
$user->addTag($tag1);
$user->addTag($tag2);
$user->addTag($tag3);
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$user = $this->_em->find(get_class($user), $user->id);
$criteria = Criteria::create()
->orderBy(['name' => Criteria::ASC]);
$this->assertEquals(
['A', 'B', 'C'],
$user
->getTags()
->matching($criteria)
->map(function (CmsTag $tag) {
return $tag->getName();
})
->toArray()
);
}
public function testMatchingWithLimit()
{
$user = $this->addCmsUserGblancoWithGroups(2);
$this->_em->clear();
$user = $this->_em->find(get_class($user), $user->id);
$groups = $user->groups;
$this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection");
$criteria = Criteria::create()->setMaxResults(1);
$result = $groups->matching($criteria);
$this->assertCount(1, $result);
$this->assertFalse($user->groups->isInitialized(), "Post-condition: matching does not initialize collection");
}
public function testMatchingWithOffset()
{
$user = $this->addCmsUserGblancoWithGroups(2);
$this->_em->clear();
$user = $this->_em->find(get_class($user), $user->id);
$groups = $user->groups;
$this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection");
$criteria = Criteria::create()->setFirstResult(1);
$result = $groups->matching($criteria);
$this->assertCount(1, $result);
$firstGroup = $result->first();
$this->assertEquals('Developers_1', $firstGroup->name);
$this->assertFalse($user->groups->isInitialized(), "Post-condition: matching does not initialize collection");
}
public function testMatchingWithLimitAndOffset()
{
$user = $this->addCmsUserGblancoWithGroups(5);
$this->_em->clear();
$user = $this->_em->find(get_class($user), $user->id);
$groups = $user->groups;
$this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection");
$criteria = Criteria::create()->setFirstResult(1)->setMaxResults(3);
$result = $groups->matching($criteria);
$this->assertCount(3, $result);
$firstGroup = $result->first();
$this->assertEquals('Developers_1', $firstGroup->name);
$lastGroup = $result->last();
$this->assertEquals('Developers_3', $lastGroup->name);
$this->assertFalse($user->groups->isInitialized(), "Post-condition: matching does not initialize collection");
}
public function testMatching()
{
$user = $this->addCmsUserGblancoWithGroups(2);

View File

@ -19,6 +19,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$classes = array(
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'),
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsTag'),
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'),
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsEmail'),
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'),
@ -30,16 +31,20 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals("CREATE TABLE cms_groups (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[0]);
$this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, email_id INT DEFAULT NULL, status VARCHAR(50) DEFAULT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_3AF03EC5F85E0677 (username), UNIQUE INDEX UNIQ_3AF03EC5A832C1C9 (email_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[1]);
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_7EA9409AA76ED395 (user_id), INDEX IDX_7EA9409AFE54D947 (group_id), PRIMARY KEY(user_id, group_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[2]);
$this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_ACAC157BA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[3]);
$this->assertEquals("CREATE TABLE cms_emails (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(250) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[4]);
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, INDEX IDX_F21F790FA76ED395 (user_id), PRIMARY KEY(phonenumber)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[5]);
$this->assertEquals("ALTER TABLE cms_users ADD CONSTRAINT FK_3AF03EC5A832C1C9 FOREIGN KEY (email_id) REFERENCES cms_emails (id)", $sql[6]);
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[7]);
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AFE54D947 FOREIGN KEY (group_id) REFERENCES cms_groups (id)", $sql[8]);
$this->assertEquals("ALTER TABLE cms_addresses ADD CONSTRAINT FK_ACAC157BA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[9]);
$this->assertEquals("ALTER TABLE cms_phonenumbers ADD CONSTRAINT FK_F21F790FA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[10]);
$this->assertEquals("CREATE TABLE cms_users_tags (user_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_93F5A1ADA76ED395 (user_id), INDEX IDX_93F5A1ADBAD26311 (tag_id), PRIMARY KEY(user_id, tag_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[3]);
$this->assertEquals("CREATE TABLE cms_tags (id INT AUTO_INCREMENT NOT NULL, tag_name VARCHAR(50) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[4]);
$this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_ACAC157BA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[5]);
$this->assertEquals("CREATE TABLE cms_emails (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(250) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[6]);
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, INDEX IDX_F21F790FA76ED395 (user_id), PRIMARY KEY(phonenumber)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[7]);
$this->assertEquals("ALTER TABLE cms_users ADD CONSTRAINT FK_3AF03EC5A832C1C9 FOREIGN KEY (email_id) REFERENCES cms_emails (id)", $sql[8]);
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[9]);
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AFE54D947 FOREIGN KEY (group_id) REFERENCES cms_groups (id)", $sql[10]);
$this->assertEquals("ALTER TABLE cms_users_tags ADD CONSTRAINT FK_93F5A1ADA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[11]);
$this->assertEquals("ALTER TABLE cms_users_tags ADD CONSTRAINT FK_93F5A1ADBAD26311 FOREIGN KEY (tag_id) REFERENCES cms_tags (id)", $sql[12]);
$this->assertEquals("ALTER TABLE cms_addresses ADD CONSTRAINT FK_ACAC157BA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[13]);
$this->assertEquals("ALTER TABLE cms_phonenumbers ADD CONSTRAINT FK_F21F790FA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id)", $sql[14]);
$this->assertEquals(11, count($sql));
$this->assertEquals(15, count($sql));
}
public function testGetCreateSchemaSql2()

View File

@ -43,6 +43,9 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id))", array_shift($sql));
$this->assertEquals("CREATE INDEX IDX_7EA9409AA76ED395 ON cms_users_groups (user_id)", array_shift($sql));
$this->assertEquals("CREATE INDEX IDX_7EA9409AFE54D947 ON cms_users_groups (group_id)", array_shift($sql));
$this->assertEquals("CREATE TABLE cms_users_tags (user_id INT NOT NULL, tag_id INT NOT NULL, PRIMARY KEY(user_id, tag_id))", array_shift($sql));
$this->assertEquals("CREATE INDEX IDX_93F5A1ADA76ED395 ON cms_users_tags (user_id)", array_shift($sql));
$this->assertEquals("CREATE INDEX IDX_93F5A1ADBAD26311 ON cms_users_tags (tag_id)", array_shift($sql));
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber))", array_shift($sql));
$this->assertEquals("CREATE INDEX IDX_F21F790FA76ED395 ON cms_phonenumbers (user_id)", array_shift($sql));
$this->assertEquals("CREATE SEQUENCE cms_addresses_id_seq INCREMENT BY 1 MINVALUE 1 START 1", array_shift($sql));
@ -51,10 +54,12 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals("ALTER TABLE cms_users ADD CONSTRAINT FK_3AF03EC5A832C1C9 FOREIGN KEY (email_id) REFERENCES cms_emails (id) NOT DEFERRABLE INITIALLY IMMEDIATE", array_shift($sql));
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id) NOT DEFERRABLE INITIALLY IMMEDIATE", array_shift($sql));
$this->assertEquals("ALTER TABLE cms_users_groups ADD CONSTRAINT FK_7EA9409AFE54D947 FOREIGN KEY (group_id) REFERENCES cms_groups (id) NOT DEFERRABLE INITIALLY IMMEDIATE", array_shift($sql));
$this->assertEquals("ALTER TABLE cms_users_tags ADD CONSTRAINT FK_93F5A1ADA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id) NOT DEFERRABLE INITIALLY IMMEDIATE", array_shift($sql));
$this->assertEquals("ALTER TABLE cms_users_tags ADD CONSTRAINT FK_93F5A1ADBAD26311 FOREIGN KEY (tag_id) REFERENCES cms_tags (id) NOT DEFERRABLE INITIALLY IMMEDIATE", array_shift($sql));
$this->assertEquals("ALTER TABLE cms_phonenumbers ADD CONSTRAINT FK_F21F790FA76ED395 FOREIGN KEY (user_id) REFERENCES cms_users (id) NOT DEFERRABLE INITIALLY IMMEDIATE", array_shift($sql));
$this->assertEquals(array(), $sql, "SQL Array should be empty now.");
$this->assertEquals(17, $sqlCount, "Total of 17 queries should be executed");
$this->assertEquals(22, $sqlCount, "Total of 22 queries should be executed");
}
public function testGetCreateSchemaSql2()
@ -97,7 +102,7 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$tool = new SchemaTool($this->_em);
$sql = $tool->getDropSchemaSQL($classes);
$this->assertEquals(14, count($sql));
$this->assertEquals(17, count($sql));
$dropSequenceSQLs = 0;

View File

@ -0,0 +1,54 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Tests\Models\Company\CompanyFlexContract;
use Doctrine\Tests\Models\Company\CompanyManager;
/**
* @author Jean Carlo Machado <contato@jeancarlomachado.com.br>
*/
class DDC3719Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('company');
parent::setUp();
}
/**
* @group DDC-3719
*/
public function testCriteriaOnNotOwningSide()
{
$manager = new CompanyManager();
$manager->setName('Gandalf');
$manager->setSalary(666);
$manager->setTitle('Boss');
$manager->setDepartment('Marketing');
$this->_em->persist($manager);
$contractA = new CompanyFlexContract();
$contractA->markCompleted();
$contractA->addManager($manager);
$this->_em->persist($contractA);
$contractB = new CompanyFlexContract();
$contractB->addManager($manager);
$this->_em->persist($contractB);
$this->_em->flush();
$this->_em->refresh($manager);
$contracts = $manager->managedContracts;
static::assertCount(2, $contracts);
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq("completed", true));
$completedContracts = $contracts->matching($criteria);
static::assertCount(1, $completedContracts);
}
}

View File

@ -83,6 +83,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
'Doctrine\Tests\Models\CMS\CmsAddress',
'Doctrine\Tests\Models\CMS\CmsEmail',
'Doctrine\Tests\Models\CMS\CmsGroup',
'Doctrine\Tests\Models\CMS\CmsTag',
'Doctrine\Tests\Models\CMS\CmsArticle',
'Doctrine\Tests\Models\CMS\CmsComment',
),
@ -319,6 +320,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
if (isset($this->_usedModelSets['cms'])) {
$conn->executeUpdate('DELETE FROM cms_users_groups');
$conn->executeUpdate('DELETE FROM cms_groups');
$conn->executeUpdate('DELETE FROM cms_users_tags');
$conn->executeUpdate('DELETE FROM cms_tags');
$conn->executeUpdate('DELETE FROM cms_addresses');
$conn->executeUpdate('DELETE FROM cms_phonenumbers');
$conn->executeUpdate('DELETE FROM cms_comments');