@@ -77,7 +77,10 @@ public function testAtomicUpsert()
77
77
$ this ->assertEquals ('12345678 ' , $ user ->phonenumbers [0 ]->getPhonenumber ());
78
78
}
79
79
80
- public function testAtomicCollectionUnset ()
80
+ /**
81
+ * @dataProvider provideAtomicCollectionUnset
82
+ */
83
+ public function testAtomicCollectionUnset ($ clearWith )
81
84
{
82
85
$ user = new AtomicSetUser ('Maciej ' );
83
86
$ user ->phonenumbers [] = new Phonenumber ('12345678 ' );
@@ -92,7 +95,7 @@ public function testAtomicCollectionUnset()
92
95
$ this ->assertEquals ('12345678 ' , $ user ->phonenumbers [0 ]->getPhonenumber ());
93
96
94
97
$ user ->surname = "Malarz " ;
95
- $ user ->phonenumbers = null ;
98
+ $ user ->phonenumbers = $ clearWith ;
96
99
$ this ->ql ->clear ();
97
100
$ this ->dm ->flush ();
98
101
$ this ->assertCount (1 , $ this ->ql , 'Updating a document and unsetting its embed-many collection requires one query ' );
@@ -104,6 +107,61 @@ public function testAtomicCollectionUnset()
104
107
$ this ->assertCount (0 , $ user ->phonenumbers );
105
108
}
106
109
110
+ public function provideAtomicCollectionUnset ()
111
+ {
112
+ return array (
113
+ array (null ),
114
+ array (array ()),
115
+ array (new ArrayCollection ()),
116
+ );
117
+ }
118
+
119
+ public function testAtomicCollectionClearAndUpdate ()
120
+ {
121
+ $ user = new AtomicSetUser ('Maciej ' );
122
+ $ user ->phonenumbers [] = new Phonenumber ('12345678 ' );
123
+ $ this ->dm ->persist ($ user );
124
+ $ this ->dm ->flush ();
125
+ $ this ->assertCount (1 , $ this ->ql , 'Inserting a document with an embed-many collection requires one query ' );
126
+ $ this ->dm ->clear ();
127
+
128
+ $ user = $ this ->dm ->getRepository (get_class ($ user ))->find ($ user ->id );
129
+ $ user ->phonenumbers ->clear ();
130
+ $ user ->phonenumbers [] = new Phonenumber ('87654321 ' );
131
+ $ this ->ql ->clear ();
132
+ $ this ->dm ->flush ();
133
+ $ this ->assertCount (1 , $ this ->ql , 'Updating emptied collection requires one query ' );
134
+ $ this ->dm ->clear ();
135
+
136
+ $ user = $ this ->dm ->getRepository (get_class ($ user ))->find ($ user ->id );
137
+ $ this ->assertEquals ('Maciej ' , $ user ->name );
138
+ $ this ->assertCount (1 , $ user ->phonenumbers );
139
+ $ this ->assertEquals ('87654321 ' , $ user ->phonenumbers [0 ]->getPhonenumber ());
140
+ }
141
+
142
+ public function testAtomicCollectionReplacedAndUpdated ()
143
+ {
144
+ $ user = new AtomicSetUser ('Maciej ' );
145
+ $ user ->phonenumbers [] = new Phonenumber ('12345678 ' );
146
+ $ this ->dm ->persist ($ user );
147
+ $ this ->dm ->flush ();
148
+ $ this ->assertCount (1 , $ this ->ql , 'Inserting a document with an embed-many collection requires one query ' );
149
+ $ this ->dm ->clear ();
150
+
151
+ $ user = $ this ->dm ->getRepository (get_class ($ user ))->find ($ user ->id );
152
+ $ user ->phonenumbers = new ArrayCollection ();
153
+ $ user ->phonenumbers [] = new Phonenumber ('87654321 ' );
154
+ $ this ->ql ->clear ();
155
+ $ this ->dm ->flush ();
156
+ $ this ->assertCount (1 , $ this ->ql , 'Updating emptied collection requires one query ' );
157
+ $ this ->dm ->clear ();
158
+
159
+ $ user = $ this ->dm ->getRepository (get_class ($ user ))->find ($ user ->id );
160
+ $ this ->assertEquals ('Maciej ' , $ user ->name );
161
+ $ this ->assertCount (1 , $ user ->phonenumbers );
162
+ $ this ->assertEquals ('87654321 ' , $ user ->phonenumbers [0 ]->getPhonenumber ());
163
+ }
164
+
107
165
public function testAtomicSetArray ()
108
166
{
109
167
$ user = new AtomicSetUser ('Maciej ' );
0 commit comments