|
1 |
| -<?php |
2 |
| - |
3 |
| -declare(strict_types=1); |
4 |
| - |
5 |
| -namespace Doctrine\Tests\ORM\Functional\Ticket; |
6 |
| - |
7 |
| -use Doctrine\Common\Collections\ArrayCollection; |
8 |
| -use Doctrine\ORM\PersistentCollection; |
9 |
| -use Doctrine\Tests\Models\ECommerce\ECommerceCategory; |
10 |
| -use Doctrine\Tests\Models\ECommerce\ECommerceProduct; |
11 |
| - |
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional\Ticket; |
| 6 | + |
| 7 | +use Doctrine\Common\Collections\ArrayCollection; |
| 8 | +use Doctrine\ORM\PersistentCollection; |
| 9 | +use Doctrine\Tests\Models\ECommerce\ECommerceCategory; |
| 10 | +use Doctrine\Tests\Models\ECommerce\ECommerceProduct; |
| 11 | + |
12 | 12 | /**
|
13 | 13 | * @group DDC-2074
|
14 |
| - */ |
15 |
| -class DDC2074Test extends \Doctrine\Tests\OrmFunctionalTestCase |
16 |
| -{ |
17 |
| - public function setUp() |
18 |
| - { |
19 |
| - $this->useModelSet('ecommerce'); |
20 |
| - parent::setUp(); |
21 |
| - } |
22 |
| - |
23 |
| - public function testShouldNotScheduleDeletionOnClonedInstances() |
24 |
| - { |
25 |
| - $class = $this->em->getClassMetadata(ECommerceProduct::class); |
26 |
| - $product = new ECommerceProduct(); |
27 |
| - $category = new ECommerceCategory(); |
28 |
| - $collection = new PersistentCollection($this->em, $class, new ArrayCollection([$category])); |
29 |
| - $collection->setOwner($product, $class->getProperty('categories')); |
30 |
| - |
31 |
| - $uow = $this->em->getUnitOfWork(); |
32 |
| - $clonedCollection = clone $collection; |
33 |
| - $clonedCollection->clear(); |
34 |
| - |
35 |
| - self::assertCount(0, $uow->getScheduledCollectionDeletions()); |
36 |
| - } |
37 |
| - |
38 |
| - public function testSavingClonedPersistentCollection() |
39 |
| - { |
40 |
| - $product = new ECommerceProduct(); |
41 |
| - $category = new ECommerceCategory(); |
42 |
| - $category->setName('foo'); |
43 |
| - $product->addCategory($category); |
44 |
| - |
45 |
| - $this->em->persist($product); |
46 |
| - $this->em->persist($category); |
47 |
| - $this->em->flush(); |
48 |
| - |
49 |
| - $newProduct = clone $product; |
50 |
| - |
51 |
| - $this->em->persist($newProduct); |
52 |
| - $this->em->flush(); |
53 |
| - $this->em->clear(); |
54 |
| - |
55 |
| - $product1 = $this->em->find(ECommerceProduct::class, $product->getId()); |
56 |
| - $product2 = $this->em->find(ECommerceProduct::class, $newProduct->getId()); |
57 |
| - |
58 |
| - self::assertCount(1, $product1->getCategories()); |
59 |
| - self::assertCount(1, $product2->getCategories()); |
60 |
| - |
61 |
| - self::assertSame($product1->getCategories()->get(0), $product2->getCategories()->get(0)); |
62 |
| - } |
63 |
| -} |
| 14 | + */ |
| 15 | +class DDC2074Test extends \Doctrine\Tests\OrmFunctionalTestCase |
| 16 | +{ |
| 17 | + public function setUp() |
| 18 | + { |
| 19 | + $this->useModelSet('ecommerce'); |
| 20 | + parent::setUp(); |
| 21 | + } |
| 22 | + |
| 23 | + public function testShouldNotScheduleDeletionOnClonedInstances() |
| 24 | + { |
| 25 | + $class = $this->em->getClassMetadata(ECommerceProduct::class); |
| 26 | + $product = new ECommerceProduct(); |
| 27 | + $category = new ECommerceCategory(); |
| 28 | + $collection = new PersistentCollection($this->em, $class, new ArrayCollection([$category])); |
| 29 | + $collection->setOwner($product, $class->getProperty('categories')); |
| 30 | + |
| 31 | + $uow = $this->em->getUnitOfWork(); |
| 32 | + $clonedCollection = clone $collection; |
| 33 | + $clonedCollection->clear(); |
| 34 | + |
| 35 | + self::assertCount(0, $uow->getScheduledCollectionDeletions()); |
| 36 | + } |
| 37 | + |
| 38 | + public function testSavingClonedPersistentCollection() |
| 39 | + { |
| 40 | + $product = new ECommerceProduct(); |
| 41 | + $category = new ECommerceCategory(); |
| 42 | + $category->setName('foo'); |
| 43 | + $product->addCategory($category); |
| 44 | + |
| 45 | + $this->em->persist($product); |
| 46 | + $this->em->persist($category); |
| 47 | + $this->em->flush(); |
| 48 | + |
| 49 | + $newProduct = clone $product; |
| 50 | + |
| 51 | + $this->em->persist($newProduct); |
| 52 | + $this->em->flush(); |
| 53 | + $this->em->clear(); |
| 54 | + |
| 55 | + $product1 = $this->em->find(ECommerceProduct::class, $product->getId()); |
| 56 | + $product2 = $this->em->find(ECommerceProduct::class, $newProduct->getId()); |
| 57 | + |
| 58 | + self::assertCount(1, $product1->getCategories()); |
| 59 | + self::assertCount(1, $product2->getCategories()); |
| 60 | + |
| 61 | + self::assertSame($product1->getCategories()->get(0), $product2->getCategories()->get(0)); |
| 62 | + } |
| 63 | +} |
0 commit comments