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\Annotation as ORM; |
||
9 | use Doctrine\ORM\Event\LifecycleEventArgs; |
||
10 | use Doctrine\Tests\OrmFunctionalTestCase; |
||
11 | use function get_class; |
||
12 | |||
13 | /** |
||
14 | * @group DDC-3033 |
||
15 | */ |
||
16 | class DDC3033Test extends OrmFunctionalTestCase |
||
17 | { |
||
18 | public function testIssue() : void |
||
19 | { |
||
20 | $this->schemaTool->createSchema( |
||
21 | [ |
||
22 | $this->em->getClassMetadata(DDC3033User::class), |
||
23 | $this->em->getClassMetadata(DDC3033Product::class), |
||
24 | ] |
||
25 | ); |
||
26 | |||
27 | $user = new DDC3033User(); |
||
28 | $user->name = 'Test User'; |
||
29 | $this->em->persist($user); |
||
30 | |||
31 | $user2 = new DDC3033User(); |
||
32 | $user2->name = 'Test User 2'; |
||
33 | $this->em->persist($user2); |
||
34 | |||
35 | $product = new DDC3033Product(); |
||
36 | $product->title = 'Test product'; |
||
37 | $product->buyers[] = $user; |
||
38 | |||
39 | $this->em->persist($product); |
||
40 | $this->em->flush(); |
||
41 | |||
42 | $product->title = 'Test Change title'; |
||
43 | $product->buyers[] = $user2; |
||
44 | |||
45 | $this->em->persist($product); |
||
46 | $this->em->flush(); |
||
47 | |||
48 | $expect = [ |
||
49 | 'title' => [ |
||
50 | 0 => 'Test product', |
||
51 | 1 => 'Test Change title', |
||
52 | ], |
||
53 | ]; |
||
54 | |||
55 | self::assertEquals($expect, $product->changeSet); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @ORM\Table |
||
61 | * @ORM\Entity @ORM\HasLifecycleCallbacks |
||
62 | */ |
||
63 | class DDC3033Product |
||
64 | { |
||
65 | public $changeSet = []; |
||
66 | |||
67 | /** |
||
68 | * @ORM\Column(name="id", type="integer") |
||
69 | * @ORM\Id |
||
70 | * @ORM\GeneratedValue(strategy="AUTO") |
||
71 | * |
||
72 | * @var int $id |
||
73 | */ |
||
74 | public $id; |
||
75 | |||
76 | /** |
||
77 | * @ORM\Column(name="title", type="string", length=255) |
||
78 | * |
||
79 | * @var string $title |
||
80 | */ |
||
81 | public $title; |
||
82 | |||
83 | /** |
||
84 | * @ORM\ManyToMany(targetEntity=DDC3033User::class) |
||
85 | * @ORM\JoinTable( |
||
86 | * name="user_purchases_3033", |
||
87 | * joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")}, |
||
88 | * inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")} |
||
89 | * ) |
||
90 | */ |
||
91 | public $buyers; |
||
92 | |||
93 | /** |
||
94 | * Default constructor |
||
95 | */ |
||
96 | public function __construct() |
||
97 | { |
||
98 | $this->buyers = new ArrayCollection(); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @ORM\PreUpdate |
||
103 | */ |
||
104 | public function preUpdate(LifecycleEventArgs $eventArgs) |
||
105 | { |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @ORM\PostUpdate |
||
110 | */ |
||
111 | public function postUpdate(LifecycleEventArgs $eventArgs) |
||
112 | { |
||
113 | $em = $eventArgs->getEntityManager(); |
||
114 | $uow = $em->getUnitOfWork(); |
||
115 | $entity = $eventArgs->getEntity(); |
||
116 | $classMetadata = $em->getClassMetadata(get_class($entity)); |
||
117 | |||
118 | $uow->computeChangeSet($classMetadata, $entity); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
119 | $this->changeSet = $uow->getEntityChangeSet($entity); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @ORM\Table |
||
125 | * @ORM\Entity @ORM\HasLifecycleCallbacks |
||
126 | */ |
||
127 | class DDC3033User |
||
128 | { |
||
129 | /** |
||
130 | * @ORM\Column(name="id", type="integer") |
||
131 | * @ORM\Id |
||
132 | * @ORM\GeneratedValue(strategy="AUTO") |
||
133 | * |
||
134 | * @var int |
||
135 | */ |
||
136 | public $id; |
||
137 | |||
138 | /** |
||
139 | * @ORM\Column(name="title", type="string", length=255) |
||
140 | * |
||
141 | * @var string |
||
142 | */ |
||
143 | public $name; |
||
144 | } |
||
145 |