From cfed92a5cf73c91ca830314b8fc8c87fcc66c477 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 24 Jan 2015 11:58:57 +0100 Subject: [PATCH] #1169 DDC-3343 - integrating tests into the existing test suite Conflicts: tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php --- .../OneToManyExtraLazyTest.php | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php new file mode 100644 index 000000000..383940f51 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php @@ -0,0 +1,147 @@ +useModelSet('tweet'); + $this->useModelSet('vct_onetomany_extralazy'); + + parent::setUp(); + + $inversed = new Entity\InversedOneToManyExtraLazyEntity(); + $inversed->id1 = 'abc'; + + $owning1 = new Entity\OwningManyToOneExtraLazyEntity(); + $owning1->id2 = 'def'; + + $owning2 = new Entity\OwningManyToOneExtraLazyEntity(); + $owning2->id2 = 'ghi'; + + $owning3 = new Entity\OwningManyToOneExtraLazyEntity(); + $owning3->id2 = 'jkl'; + + $inversed->associatedEntities->add($owning1); + $owning1->associatedEntity = $inversed; + $inversed->associatedEntities->add($owning2); + $owning2->associatedEntity = $inversed; + $inversed->associatedEntities->add($owning3); + $owning3->associatedEntity = $inversed; + + $this->_em->persist($inversed); + $this->_em->persist($owning1); + $this->_em->persist($owning2); + $this->_em->persist($owning3); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone_extralazy'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_extralazy'); + } + + public function testThatExtraLazyCollectionIsCounted() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'abc' + ); + + $this->assertEquals(3, $inversed->associatedEntities->count()); + } + + public function testThatExtraLazyCollectionContainsAnEntity() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity', + 'def' + ); + + $this->assertTrue($inversed->associatedEntities->contains($owning)); + } + + public function testThatExtraLazyCollectionContainsAnIndexbyKey() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'abc' + ); + + $this->assertTrue($inversed->associatedEntities->containsKey('def')); + } + + public function testThatASliceOfTheExtraLazyCollectionIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'abc' + ); + + $this->assertCount(2, $inversed->associatedEntities->slice(0, 2)); + } + + /** + * @group DDC-3343 + */ + public function testEntityNotDeletedWhenRemovedFromExtraLazyAssociation() + { + $user = new User(); + $tweet = new Tweet(); + + $user->name = 'ocramius'; + $tweet->content = 'The cat is on the table'; + + $user->addTweet($tweet); + + $this->_em->persist($user); + $this->_em->persist($tweet); + $this->_em->flush(); + $this->_em->clear(); + + /* @var $user User */ + $user = $this->_em->find(User::CLASSNAME, $user->id); + $tweet = $this->_em->find(Tweet::CLASSNAME, $tweet->id); + + $user->tweets->removeElement($tweet); + + $this->assertCount(0, $user->tweets); + + $this->_em->clear(); + + /* @var $tweet Tweet */ + $tweet = $this->_em->find(Tweet::CLASSNAME, $tweet->id); + $this->assertInstanceOf( + Tweet::CLASSNAME, + $tweet, + 'Even though the collection is extra lazy, the tweet should not have been deleted' + ); + + $this->assertNull($tweet->author); + } +}