Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit edfe1ec

Browse files
author
Dominik Zogg
committed
chubbyphp-mock-2.x
1 parent 0a82ba4 commit edfe1ec

File tree

3 files changed

+132
-118
lines changed

3 files changed

+132
-118
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ A simple deserialization.
2626
## Requirements
2727

2828
* php: ^8.2
29-
* chubbyphp/chubbyphp-decode-encode: ^1.1
29+
* chubbyphp/chubbyphp-decode-encode: ^1.2
3030
* psr/http-message: ^1.1|^2.0
3131
* psr/log: ^2.0|^3.0.2
3232

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@
1414
"ext-dom": "*",
1515
"ext-json": "*",
1616
"ext-mbstring": "*",
17-
"chubbyphp/chubbyphp-decode-encode": "^1.1",
17+
"chubbyphp/chubbyphp-decode-encode": "^1.2",
1818
"psr/http-message": "^1.1|^2.0",
1919
"psr/log": "^2.0|^3.0.2"
2020
},
2121
"require-dev": {
22-
"chubbyphp/chubbyphp-container": "^2.2",
22+
"chubbyphp/chubbyphp-container": "^2.3",
2323
"chubbyphp/chubbyphp-dev-helper": "dev-master",
24-
"chubbyphp/chubbyphp-laminas-config-factory": "^1.3",
25-
"chubbyphp/chubbyphp-mock": "^1.8",
24+
"chubbyphp/chubbyphp-laminas-config-factory": "^1.4",
25+
"chubbyphp/chubbyphp-mock": "^2.0@dev",
2626
"doctrine/collections": "^2.2.2",
2727
"doctrine/persistence": "^4.0",
28-
"infection/infection": "^0.29.8",
28+
"infection/infection": "^0.29.13",
2929
"php-coveralls/php-coveralls": "^2.7.0",
3030
"phpstan/extension-installer": "^1.4.3",
31-
"phpstan/phpstan": "^2.0.3",
32-
"phpunit/phpunit": "^11.5.0",
31+
"phpstan/phpstan": "^2.1.6",
32+
"phpunit/phpunit": "^11.5.10",
3333
"pimple/pimple": "^3.5",
3434
"psr/container": "^2.0.2",
3535
"symfony/config": "^5.4.46|^6.4.14|^7.2",
36-
"symfony/dependency-injection": "^5.4.46|^6.4.14|^7.2"
36+
"symfony/dependency-injection": "^5.4.48|^6.4.19|^7.2"
3737
},
3838
"autoload": {
3939
"psr-4": { "Chubbyphp\\Deserialization\\": "src/" }

tests/Unit/Denormalizer/Relation/EmbedManyFieldDenormalizerTest.php

Lines changed: 123 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
use Chubbyphp\Deserialization\Denormalizer\Relation\EmbedManyFieldDenormalizer;
1111
use Chubbyphp\Deserialization\DeserializerLogicException;
1212
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;
1516
use Doctrine\Common\Collections\Collection;
16-
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
1818

1919
/**
@@ -23,20 +23,20 @@
2323
*/
2424
final class EmbedManyFieldDenormalizerTest extends TestCase
2525
{
26-
use MockByCallsTrait;
27-
2826
public function testDenormalizeFieldWithMissingDenormalizer(): void
2927
{
3028
$this->expectException(DeserializerLogicException::class);
3129
$this->expectExceptionMessage('There is no denormalizer at path: "children"');
3230

3331
$parent = new \stdClass();
3432

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, []);
3737

38-
/** @var DenormalizerContextInterface|MockObject $context */
39-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
38+
/** @var DenormalizerContextInterface $context */
39+
$context = $builder->create(DenormalizerContextInterface::class, []);
4040

4141
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);
4242
$fieldDenormalizer->denormalizeField('children', $parent, [['name' => 'name']], $context);
@@ -49,14 +49,16 @@ public function testDenormalizeFieldWithoutArrayDenormalizer(): void
4949

5050
$parent = new \stdClass();
5151

52-
/** @var AccessorInterface|MockObject $accessor */
53-
$accessor = $this->getMockByCalls(AccessorInterface::class);
52+
$builder = new MockObjectBuilder();
5453

55-
/** @var DenormalizerContextInterface|MockObject $context */
56-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
54+
/** @var AccessorInterface $accessor */
55+
$accessor = $builder->create(AccessorInterface::class, []);
5756

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, []);
6062

6163
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);
6264
$fieldDenormalizer->denormalizeField('children', $parent, 'test', $context, $denormalizer);
@@ -69,16 +71,18 @@ public function testDenormalizeFieldWithArrayButStringChildDenormalizer(): void
6971

7072
$parent = new \stdClass();
7173

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], []),
7579
]);
7680

77-
/** @var DenormalizerContextInterface|MockObject $context */
78-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
81+
/** @var DenormalizerContextInterface $context */
82+
$context = $builder->create(DenormalizerContextInterface::class, []);
7983

80-
/** @var DenormalizerInterface|MockObject $denormalizer */
81-
$denormalizer = $this->getMockByCalls(DenormalizerInterface::class);
84+
/** @var DenormalizerInterface $denormalizer */
85+
$denormalizer = $builder->create(DenormalizerInterface::class, []);
8286

8387
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);
8488
$fieldDenormalizer->denormalizeField('children', $parent, ['test'], $context, $denormalizer);
@@ -88,17 +92,18 @@ public function testDenormalizeFieldWithNull(): void
8892
{
8993
$parent = new \stdClass();
9094

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, []]),
95100
]);
96101

97-
/** @var DenormalizerContextInterface|MockObject $context */
98-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
102+
/** @var DenormalizerContextInterface $context */
103+
$context = $builder->create(DenormalizerContextInterface::class, []);
99104

100-
/** @var DenormalizerInterface|MockObject $denormalizer */
101-
$denormalizer = $this->getMockByCalls(DenormalizerInterface::class);
105+
/** @var DenormalizerInterface $denormalizer */
106+
$denormalizer = $builder->create(DenormalizerInterface::class, []);
102107

103108
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);
104109
$fieldDenormalizer->denormalizeField('children', $parent, null, $context, $denormalizer);
@@ -107,23 +112,26 @@ public function testDenormalizeFieldWithNull(): void
107112
public function testDenormalizeFieldWithSubValueNull(): void
108113
{
109114
$parent = new \stdClass();
110-
111115
$child = new \stdClass();
112116

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]]),
117123
]);
118124

119-
/** @var DenormalizerContextInterface|MockObject $context */
120-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
125+
/** @var DenormalizerContextInterface $context */
126+
$context = $builder->create(DenormalizerContextInterface::class, []);
121127

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+
),
127135
]);
128136

129137
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);
@@ -136,20 +144,24 @@ public function testDenormalizeFieldWithNewChild(): void
136144

137145
$child = new \stdClass();
138146

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]]),
143153
]);
144154

145-
/** @var DenormalizerContextInterface|MockObject $context */
146-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
155+
/** @var DenormalizerContextInterface $context */
156+
$context = $builder->create(DenormalizerContextInterface::class, []);
147157

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+
),
153165
]);
154166

155167
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);
@@ -162,32 +174,36 @@ public function testDenormalizeFieldWithNewChildAndCollection(): void
162174

163175
$child = new \stdClass();
164176

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),
169183
]);
170184

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]),
175189
]);
176190

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]),
181195
]);
182196

183-
/** @var DenormalizerContextInterface|MockObject $context */
184-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
197+
/** @var DenormalizerContextInterface $context */
198+
$context = $builder->create(DenormalizerContextInterface::class, []);
185199

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+
),
191207
]);
192208

193209
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);
@@ -197,23 +213,22 @@ public function testDenormalizeFieldWithNewChildAndCollection(): void
197213
public function testDenormalizeFieldWithExistingChild(): void
198214
{
199215
$parent = new \stdClass();
200-
201216
$child = new \stdClass();
202217

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]]),
207224
]);
208225

209-
/** @var DenormalizerContextInterface|MockObject $context */
210-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
226+
/** @var DenormalizerContextInterface $context */
227+
$context = $builder->create(DenormalizerContextInterface::class, []);
211228

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),
217232
]);
218233

219234
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);
@@ -223,40 +238,39 @@ public function testDenormalizeFieldWithExistingChild(): void
223238
public function testDenormalizeFieldWithExistingChildAndCollection(): void
224239
{
225240
$parent = new \stdClass();
226-
227241
$child = new \stdClass();
228242

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),
237253
]);
238254

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]),
244260
]);
245261

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]),
250266
]);
251267

252-
/** @var DenormalizerContextInterface|MockObject $context */
253-
$context = $this->getMockByCalls(DenormalizerContextInterface::class);
268+
/** @var DenormalizerContextInterface $context */
269+
$context = $builder->create(DenormalizerContextInterface::class, []);
254270

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),
260274
]);
261275

262276
$fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor);

0 commit comments

Comments
 (0)