From 0a6c2027f541e49d3db98610e36f9a5f38fe48c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Fri, 21 Feb 2014 10:30:41 +0100 Subject: [PATCH] Update tests --- tests/Doctrine/Tests/Models/Tweet/Tweet.php | 32 ++++++++++ tests/Doctrine/Tests/Models/Tweet/User.php | 40 ++++++++++++ .../PersistentCollectionCriteriaTest.php | 62 +++++++++---------- .../Doctrine/Tests/OrmFunctionalTestCase.php | 4 ++ 4 files changed, 104 insertions(+), 34 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/Tweet/Tweet.php create mode 100644 tests/Doctrine/Tests/Models/Tweet/User.php diff --git a/tests/Doctrine/Tests/Models/Tweet/Tweet.php b/tests/Doctrine/Tests/Models/Tweet/Tweet.php new file mode 100644 index 000000000..999677e3e --- /dev/null +++ b/tests/Doctrine/Tests/Models/Tweet/Tweet.php @@ -0,0 +1,32 @@ +author = $user; + } +} diff --git a/tests/Doctrine/Tests/Models/Tweet/User.php b/tests/Doctrine/Tests/Models/Tweet/User.php new file mode 100644 index 000000000..cb715702d --- /dev/null +++ b/tests/Doctrine/Tests/Models/Tweet/User.php @@ -0,0 +1,40 @@ +tweets = new ArrayCollection(); + } + + public function addTweet(Tweet $tweet) + { + $tweet->setAuthor($this); + $this->tweets->add($tweet); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php index 178e51fc1..2fa6d51f9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php @@ -19,12 +19,8 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Common\Collections\Criteria; -use Doctrine\Tests\Models\CMS\CmsArticle; -use Doctrine\Tests\Models\CMS\CmsComment; -use Doctrine\Tests\Models\Company\CompanyAuction; -use Doctrine\Tests\Models\Company\CompanyEmployee; -use Doctrine\Tests\Models\Company\CompanyFlexUltraContract; -use Doctrine\Tests\Models\Company\CompanyOrganization; +use Doctrine\Tests\Models\Tweet\Tweet; +use Doctrine\Tests\Models\Tweet\User; /** * @author Michaƫl Gallego @@ -33,7 +29,7 @@ class PersistentCollectionCriteriaTest extends \Doctrine\Tests\OrmFunctionalTest { protected function setUp() { - $this->useModelSet('company'); + $this->useModelSet('tweet'); parent::setUp(); } @@ -47,24 +43,23 @@ class PersistentCollectionCriteriaTest extends \Doctrine\Tests\OrmFunctionalTest public function loadFixture() { - $companyOrganization = new CompanyOrganization(); - $this->_em->persist($companyOrganization); + $author = new User(); + $author->name = 'ngal'; + $this->_em->persist($author); - $event1 = new CompanyAuction(); - $event1->setData('Foo'); - $this->_em->persist($event1); - $companyOrganization->addEvent($event1); + $tweet1 = new Tweet(); + $tweet1->content = 'Foo'; + $author->addTweet($tweet1); - $event2 = new CompanyAuction(); - $event2->setData('Bar'); - $this->_em->persist($event2); - $companyOrganization->addEvent($event2); + $tweet2 = new Tweet(); + $tweet2->content = 'Bar'; + $author->addTweet($tweet2); $this->_em->flush(); - unset($companyOrganization); - unset($event1); - unset($event2); + unset($author); + unset($tweet1); + unset($tweet2); $this->_em->clear(); } @@ -72,25 +67,24 @@ class PersistentCollectionCriteriaTest extends \Doctrine\Tests\OrmFunctionalTest public function testCanCountWithoutLoadingPersistentCollection() { $this->loadFixture(); - $repository = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyOrganization'); + $repository = $this->_em->getRepository('Doctrine\Tests\Models\Tweet\User'); - $organizations = $repository->findAll(); - $organization = $organizations[0]; - $events = $organization->events->matching(new Criteria()); + $user = $repository->findOneBy(array('name' => 'ngal')); + $tweets = $user->tweets->matching(new Criteria()); - $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $events); - $this->assertFalse($events->isInitialized()); - $this->assertCount(2, $events); - $this->assertFalse($events->isInitialized()); + $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $tweets); + $this->assertFalse($tweets->isInitialized()); + $this->assertCount(2, $tweets); + $this->assertFalse($tweets->isInitialized()); // Make sure it works with constraints - $events = $organization->events->matching(new Criteria( - Criteria::expr()->eq('id', 2) + $tweets = $user->tweets->matching(new Criteria( + Criteria::expr()->eq('content', 'Foo') )); - $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $events); - $this->assertFalse($events->isInitialized()); - $this->assertCount(1, $events); - $this->assertFalse($events->isInitialized()); + $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $tweets); + $this->assertFalse($tweets->isInitialized()); + $this->assertCount(1, $tweets); + $this->assertFalse($tweets->isInitialized()); } } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 997de8524..16d0d2573 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -183,6 +183,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Cache\AttractionContactInfo', 'Doctrine\Tests\Models\Cache\AttractionLocationInfo' ), + 'tweet' => array( + 'Doctrine\Tests\Models\Tweet\User', + 'Doctrine\Tests\Models\Tweet\Tweet' + ) ); /**