10
10
use Chubbyphp \Deserialization \Denormalizer \Relation \EmbedManyFieldDenormalizer ;
11
11
use Chubbyphp \Deserialization \DeserializerLogicException ;
12
12
use Chubbyphp \Deserialization \DeserializerRuntimeException ;
13
- use Chubbyphp \Mock \Call ;
14
- use Chubbyphp \Mock \MockByCallsTrait ;
13
+ use Chubbyphp \Mock \MockMethod \WithoutReturn ;
14
+ use Chubbyphp \Mock \MockMethod \WithReturn ;
15
+ use Chubbyphp \Mock \MockObjectBuilder ;
15
16
use Doctrine \Common \Collections \Collection ;
16
- use PHPUnit \Framework \MockObject \MockObject ;
17
17
use PHPUnit \Framework \TestCase ;
18
18
19
19
/**
23
23
*/
24
24
final class EmbedManyFieldDenormalizerTest extends TestCase
25
25
{
26
- use MockByCallsTrait;
27
-
28
26
public function testDenormalizeFieldWithMissingDenormalizer (): void
29
27
{
30
28
$ this ->expectException (DeserializerLogicException::class);
31
29
$ this ->expectExceptionMessage ('There is no denormalizer at path: "children" ' );
32
30
33
31
$ parent = new \stdClass ();
34
32
35
- /** @var AccessorInterface|MockObject $accessor */
36
- $ accessor = $ this ->getMockByCalls (AccessorInterface::class);
33
+ $ builder = new MockObjectBuilder ();
34
+
35
+ /** @var AccessorInterface $accessor */
36
+ $ accessor = $ builder ->create (AccessorInterface::class, []);
37
37
38
- /** @var DenormalizerContextInterface|MockObject $context */
39
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface::class);
38
+ /** @var DenormalizerContextInterface $context */
39
+ $ context = $ builder -> create (DenormalizerContextInterface::class, [] );
40
40
41
41
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
42
42
$ fieldDenormalizer ->denormalizeField ('children ' , $ parent , [['name ' => 'name ' ]], $ context );
@@ -49,14 +49,16 @@ public function testDenormalizeFieldWithoutArrayDenormalizer(): void
49
49
50
50
$ parent = new \stdClass ();
51
51
52
- /** @var AccessorInterface|MockObject $accessor */
53
- $ accessor = $ this ->getMockByCalls (AccessorInterface::class);
52
+ $ builder = new MockObjectBuilder ();
54
53
55
- /** @var DenormalizerContextInterface|MockObject $context */
56
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface ::class);
54
+ /** @var AccessorInterface $accessor */
55
+ $ accessor = $ builder -> create (AccessorInterface ::class, [] );
57
56
58
- /** @var DenormalizerInterface|MockObject $denormalizer */
59
- $ denormalizer = $ this ->getMockByCalls (DenormalizerInterface::class);
57
+ /** @var DenormalizerContextInterface $context */
58
+ $ context = $ builder ->create (DenormalizerContextInterface::class, []);
59
+
60
+ /** @var DenormalizerInterface $denormalizer */
61
+ $ denormalizer = $ builder ->create (DenormalizerInterface::class, []);
60
62
61
63
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
62
64
$ fieldDenormalizer ->denormalizeField ('children ' , $ parent , 'test ' , $ context , $ denormalizer );
@@ -69,16 +71,18 @@ public function testDenormalizeFieldWithArrayButStringChildDenormalizer(): void
69
71
70
72
$ parent = new \stdClass ();
71
73
72
- /** @var AccessorInterface|MockObject $accessor */
73
- $ accessor = $ this ->getMockByCalls (AccessorInterface::class, [
74
- Call::create ('getValue ' )->with ($ parent )->willReturn ([]),
74
+ $ builder = new MockObjectBuilder ();
75
+
76
+ /** @var AccessorInterface $accessor */
77
+ $ accessor = $ builder ->create (AccessorInterface::class, [
78
+ new WithReturn ('getValue ' , [$ parent ], []),
75
79
]);
76
80
77
- /** @var DenormalizerContextInterface|MockObject $context */
78
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface::class);
81
+ /** @var DenormalizerContextInterface $context */
82
+ $ context = $ builder -> create (DenormalizerContextInterface::class, [] );
79
83
80
- /** @var DenormalizerInterface|MockObject $denormalizer */
81
- $ denormalizer = $ this -> getMockByCalls (DenormalizerInterface::class);
84
+ /** @var DenormalizerInterface $denormalizer */
85
+ $ denormalizer = $ builder -> create (DenormalizerInterface::class, [] );
82
86
83
87
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
84
88
$ fieldDenormalizer ->denormalizeField ('children ' , $ parent , ['test ' ], $ context , $ denormalizer );
@@ -88,17 +92,18 @@ public function testDenormalizeFieldWithNull(): void
88
92
{
89
93
$ parent = new \stdClass ();
90
94
91
- /** @var AccessorInterface|MockObject $accessor */
92
- $ accessor = $ this ->getMockByCalls (AccessorInterface::class, [
93
- Call::create ('getValue ' )->with ($ parent )->willReturn ([]),
94
- Call::create ('setValue ' )->with ($ parent , []),
95
+ $ builder = new MockObjectBuilder ();
96
+
97
+ $ accessor = $ builder ->create (AccessorInterface::class, [
98
+ new WithReturn ('getValue ' , [$ parent ], []),
99
+ new WithoutReturn ('setValue ' , [$ parent , []]),
95
100
]);
96
101
97
- /** @var DenormalizerContextInterface|MockObject $context */
98
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface::class);
102
+ /** @var DenormalizerContextInterface $context */
103
+ $ context = $ builder -> create (DenormalizerContextInterface::class, [] );
99
104
100
- /** @var DenormalizerInterface|MockObject $denormalizer */
101
- $ denormalizer = $ this -> getMockByCalls (DenormalizerInterface::class);
105
+ /** @var DenormalizerInterface $denormalizer */
106
+ $ denormalizer = $ builder -> create (DenormalizerInterface::class, [] );
102
107
103
108
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
104
109
$ fieldDenormalizer ->denormalizeField ('children ' , $ parent , null , $ context , $ denormalizer );
@@ -107,23 +112,26 @@ public function testDenormalizeFieldWithNull(): void
107
112
public function testDenormalizeFieldWithSubValueNull (): void
108
113
{
109
114
$ parent = new \stdClass ();
110
-
111
115
$ child = new \stdClass ();
112
116
113
- /** @var AccessorInterface|MockObject $accessor */
114
- $ accessor = $ this ->getMockByCalls (AccessorInterface::class, [
115
- Call::create ('getValue ' )->with ($ parent )->willReturn ([]),
116
- Call::create ('setValue ' )->with ($ parent , [$ child ]),
117
+ $ builder = new MockObjectBuilder ();
118
+
119
+ /** @var AccessorInterface $accessor */
120
+ $ accessor = $ builder ->create (AccessorInterface::class, [
121
+ new WithReturn ('getValue ' , [$ parent ], []),
122
+ new WithoutReturn ('setValue ' , [$ parent , [$ child ]]),
117
123
]);
118
124
119
- /** @var DenormalizerContextInterface|MockObject $context */
120
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface::class);
125
+ /** @var DenormalizerContextInterface $context */
126
+ $ context = $ builder -> create (DenormalizerContextInterface::class, [] );
121
127
122
- /** @var DenormalizerInterface|MockObject $denormalizer */
123
- $ denormalizer = $ this ->getMockByCalls (DenormalizerInterface::class, [
124
- Call::create ('denormalize ' )
125
- ->with (\stdClass::class, [], $ context , 'children[0] ' )
126
- ->willReturn ($ child ),
128
+ /** @var DenormalizerInterface $denormalizer */
129
+ $ denormalizer = $ builder ->create (DenormalizerInterface::class, [
130
+ new WithReturn (
131
+ 'denormalize ' ,
132
+ [\stdClass::class, [], $ context , 'children[0] ' ],
133
+ $ child
134
+ ),
127
135
]);
128
136
129
137
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
@@ -136,20 +144,24 @@ public function testDenormalizeFieldWithNewChild(): void
136
144
137
145
$ child = new \stdClass ();
138
146
139
- /** @var AccessorInterface|MockObject $accessor */
140
- $ accessor = $ this ->getMockByCalls (AccessorInterface::class, [
141
- Call::create ('getValue ' )->with ($ parent )->willReturn ([]),
142
- Call::create ('setValue ' )->with ($ parent , [$ child ]),
147
+ $ builder = new MockObjectBuilder ();
148
+
149
+ /** @var AccessorInterface $accessor */
150
+ $ accessor = $ builder ->create (AccessorInterface::class, [
151
+ new WithReturn ('getValue ' , [$ parent ], []),
152
+ new WithoutReturn ('setValue ' , [$ parent , [$ child ]]),
143
153
]);
144
154
145
- /** @var DenormalizerContextInterface|MockObject $context */
146
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface::class);
155
+ /** @var DenormalizerContextInterface $context */
156
+ $ context = $ builder -> create (DenormalizerContextInterface::class, [] );
147
157
148
- /** @var DenormalizerInterface|MockObject $denormalizer */
149
- $ denormalizer = $ this ->getMockByCalls (DenormalizerInterface::class, [
150
- Call::create ('denormalize ' )
151
- ->with (\stdClass::class, ['name ' => 'name ' ], $ context , 'children[0] ' )
152
- ->willReturn ($ child ),
158
+ /** @var DenormalizerInterface $denormalizer */
159
+ $ denormalizer = $ builder ->create (DenormalizerInterface::class, [
160
+ new WithReturn (
161
+ 'denormalize ' ,
162
+ [\stdClass::class, ['name ' => 'name ' ], $ context , 'children[0] ' ],
163
+ $ child
164
+ ),
153
165
]);
154
166
155
167
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
@@ -162,32 +174,36 @@ public function testDenormalizeFieldWithNewChildAndCollection(): void
162
174
163
175
$ child = new \stdClass ();
164
176
165
- /** @var \Iterator|MockObject $iterator */
166
- $ iterator = $ this ->getMockByCalls (\Iterator::class, [
167
- Call::create ('rewind ' )->with (),
168
- Call::create ('valid ' )->with ()->willReturn (false ),
177
+ $ builder = new MockObjectBuilder ();
178
+
179
+ /** @var \Iterator $iterator */
180
+ $ iterator = $ builder ->create (\Iterator::class, [
181
+ new WithoutReturn ('rewind ' , []),
182
+ new WithReturn ('valid ' , [], false ),
169
183
]);
170
184
171
- /** @var Collection|MockObject $collection */
172
- $ collection = $ this -> getMockByCalls (Collection::class, [
173
- Call:: create ('getIterator ' )-> with ()-> willReturn ( $ iterator ),
174
- Call:: create ('offsetSet ' )-> with ( 0 , $ child ),
185
+ /** @var Collection $collection */
186
+ $ collection = $ builder -> create (Collection::class, [
187
+ new WithReturn ('getIterator ' , [], $ iterator ),
188
+ new WithoutReturn ('offsetSet ' , [ 0 , $ child] ),
175
189
]);
176
190
177
- /** @var AccessorInterface|MockObject $accessor */
178
- $ accessor = $ this -> getMockByCalls (AccessorInterface::class, [
179
- Call:: create ('getValue ' )-> with ( $ parent)-> willReturn ( $ collection ),
180
- Call:: create ('setValue ' )-> with ( $ parent , $ collection ),
191
+ /** @var AccessorInterface $accessor */
192
+ $ accessor = $ builder -> create (AccessorInterface::class, [
193
+ new WithReturn ('getValue ' , [ $ parent], $ collection ),
194
+ new WithoutReturn ('setValue ' , [ $ parent , $ collection] ),
181
195
]);
182
196
183
- /** @var DenormalizerContextInterface|MockObject $context */
184
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface::class);
197
+ /** @var DenormalizerContextInterface $context */
198
+ $ context = $ builder -> create (DenormalizerContextInterface::class, [] );
185
199
186
- /** @var DenormalizerInterface|MockObject $denormalizer */
187
- $ denormalizer = $ this ->getMockByCalls (DenormalizerInterface::class, [
188
- Call::create ('denormalize ' )
189
- ->with (\stdClass::class, ['name ' => 'name ' ], $ context , 'children[0] ' )
190
- ->willReturn ($ child ),
200
+ /** @var DenormalizerInterface $denormalizer */
201
+ $ denormalizer = $ builder ->create (DenormalizerInterface::class, [
202
+ new WithReturn (
203
+ 'denormalize ' ,
204
+ [\stdClass::class, ['name ' => 'name ' ], $ context , 'children[0] ' ],
205
+ $ child
206
+ ),
191
207
]);
192
208
193
209
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
@@ -197,23 +213,22 @@ public function testDenormalizeFieldWithNewChildAndCollection(): void
197
213
public function testDenormalizeFieldWithExistingChild (): void
198
214
{
199
215
$ parent = new \stdClass ();
200
-
201
216
$ child = new \stdClass ();
202
217
203
- /** @var AccessorInterface|MockObject $accessor */
204
- $ accessor = $ this ->getMockByCalls (AccessorInterface::class, [
205
- Call::create ('getValue ' )->with ($ parent )->willReturn ([$ child ]),
206
- Call::create ('setValue ' )->with ($ parent , [$ child ]),
218
+ $ builder = new MockObjectBuilder ();
219
+
220
+ /** @var AccessorInterface $accessor */
221
+ $ accessor = $ builder ->create (AccessorInterface::class, [
222
+ new WithReturn ('getValue ' , [$ parent ], [$ child ]),
223
+ new WithoutReturn ('setValue ' , [$ parent , [$ child ]]),
207
224
]);
208
225
209
- /** @var DenormalizerContextInterface|MockObject $context */
210
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface::class);
226
+ /** @var DenormalizerContextInterface $context */
227
+ $ context = $ builder -> create (DenormalizerContextInterface::class, [] );
211
228
212
- /** @var DenormalizerInterface|MockObject $denormalizer */
213
- $ denormalizer = $ this ->getMockByCalls (DenormalizerInterface::class, [
214
- Call::create ('denormalize ' )
215
- ->with ($ child , ['name ' => 'name ' ], $ context , 'children[0] ' )
216
- ->willReturn ($ child ),
229
+ /** @var DenormalizerInterface $denormalizer */
230
+ $ denormalizer = $ builder ->create (DenormalizerInterface::class, [
231
+ new WithReturn ('denormalize ' , [$ child , ['name ' => 'name ' ], $ context , 'children[0] ' ], $ child ),
217
232
]);
218
233
219
234
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
@@ -223,40 +238,39 @@ public function testDenormalizeFieldWithExistingChild(): void
223
238
public function testDenormalizeFieldWithExistingChildAndCollection (): void
224
239
{
225
240
$ parent = new \stdClass ();
226
-
227
241
$ child = new \stdClass ();
228
242
229
- /** @var \Iterator|MockObject $iterator */
230
- $ iterator = $ this ->getMockByCalls (\Iterator::class, [
231
- Call::create ('rewind ' )->with (),
232
- Call::create ('valid ' )->with ()->willReturn (true ),
233
- Call::create ('current ' )->with ()->willReturn ($ child ),
234
- Call::create ('key ' )->with ()->willReturn (0 ),
235
- Call::create ('next ' )->with (),
236
- Call::create ('valid ' )->with ()->willReturn (false ),
243
+ $ builder = new MockObjectBuilder ();
244
+
245
+ /** @var \Iterator $iterator */
246
+ $ iterator = $ builder ->create (\Iterator::class, [
247
+ new WithoutReturn ('rewind ' , []),
248
+ new WithReturn ('valid ' , [], true ),
249
+ new WithReturn ('current ' , [], $ child ),
250
+ new WithReturn ('key ' , [], 0 ),
251
+ new WithoutReturn ('next ' , []),
252
+ new WithReturn ('valid ' , [], false ),
237
253
]);
238
254
239
- /** @var Collection|MockObject $collection */
240
- $ collection = $ this -> getMockByCalls (Collection::class, [
241
- Call:: create ('getIterator ' )-> with ()-> willReturn ( $ iterator ),
242
- Call:: create ('offsetUnset ' )-> with ( 0 ),
243
- Call:: create ('offsetSet ' )-> with ( 0 , $ child ),
255
+ /** @var Collection $collection */
256
+ $ collection = $ builder -> create (Collection::class, [
257
+ new WithReturn ('getIterator ' , [], $ iterator ),
258
+ new WithoutReturn ('offsetUnset ' , [ 0 ] ),
259
+ new WithoutReturn ('offsetSet ' , [ 0 , $ child] ),
244
260
]);
245
261
246
- /** @var AccessorInterface|MockObject $accessor */
247
- $ accessor = $ this -> getMockByCalls (AccessorInterface::class, [
248
- Call:: create ('getValue ' )-> with ( $ parent)-> willReturn ( $ collection ),
249
- Call:: create ('setValue ' )-> with ( $ parent , $ collection ),
262
+ /** @var AccessorInterface $accessor */
263
+ $ accessor = $ builder -> create (AccessorInterface::class, [
264
+ new WithReturn ('getValue ' , [ $ parent], $ collection ),
265
+ new WithoutReturn ('setValue ' , [ $ parent , $ collection] ),
250
266
]);
251
267
252
- /** @var DenormalizerContextInterface|MockObject $context */
253
- $ context = $ this -> getMockByCalls (DenormalizerContextInterface::class);
268
+ /** @var DenormalizerContextInterface $context */
269
+ $ context = $ builder -> create (DenormalizerContextInterface::class, [] );
254
270
255
- /** @var DenormalizerInterface|MockObject $denormalizer */
256
- $ denormalizer = $ this ->getMockByCalls (DenormalizerInterface::class, [
257
- Call::create ('denormalize ' )
258
- ->with ($ child , ['name ' => 'name ' ], $ context , 'children[0] ' )
259
- ->willReturn ($ child ),
271
+ /** @var DenormalizerInterface $denormalizer */
272
+ $ denormalizer = $ builder ->create (DenormalizerInterface::class, [
273
+ new WithReturn ('denormalize ' , [$ child , ['name ' => 'name ' ], $ context , 'children[0] ' ], $ child ),
260
274
]);
261
275
262
276
$ fieldDenormalizer = new EmbedManyFieldDenormalizer (\stdClass::class, $ accessor );
0 commit comments