Skip to content

Commit 4d8404b

Browse files
committed
add tests
1 parent 116cfd0 commit 4d8404b

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/Unit/MetadataHydratorTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,41 @@ public function testExtractWithInferNormalizer2(): void
138138
);
139139
}
140140

141+
public function testExtractWithContext(): void
142+
{
143+
$object = new InferNormalizerDto(
144+
Status::Draft,
145+
new DateTimeImmutable('2015-02-13 22:34:32+01:00'),
146+
new DateTime('2015-02-13 22:34:32+01:00'),
147+
new DateTimeZone('EDT'),
148+
['foo'],
149+
);
150+
151+
$expect = [
152+
'status' => 'draft',
153+
'dateTimeImmutable' => '2015-02-13T22:34:32+01:00',
154+
'dateTime' => '2015-02-13T22:34:32+01:00',
155+
'dateTimeZone' => 'EDT',
156+
];
157+
158+
$middleware = $this->createMock(Middleware::class);
159+
$middleware
160+
->expects($this->once())
161+
->method('extract')
162+
->with(
163+
$this->isInstanceOf(ClassMetadata::class),
164+
$object,
165+
['context' => '123'],
166+
$this->isInstanceOf(Stack::class),
167+
)->willReturn($expect);
168+
169+
$hydrator = MetadataHydrator::create([$middleware]);
170+
171+
$data = $hydrator->extract($object, ['context' => '123']);
172+
173+
self::assertEquals($expect, $data);
174+
}
175+
141176
public function testHydrate(): void
142177
{
143178
$expected = new ProfileCreated(
@@ -220,6 +255,41 @@ public function testHydrateWithTypeMismatch(): void
220255
);
221256
}
222257

258+
public function testHydrateWithContext(): void
259+
{
260+
$expect = new InferNormalizerDto(
261+
Status::Draft,
262+
new DateTimeImmutable('2015-02-13 22:34:32+01:00'),
263+
new DateTime('2015-02-13 22:34:32+01:00'),
264+
new DateTimeZone('EDT'),
265+
['foo'],
266+
);
267+
268+
$data = [
269+
'status' => 'draft',
270+
'dateTimeImmutable' => '2015-02-13T22:34:32+01:00',
271+
'dateTime' => '2015-02-13T22:34:32+01:00',
272+
'dateTimeZone' => 'EDT',
273+
];
274+
275+
$middleware = $this->createMock(Middleware::class);
276+
$middleware
277+
->expects($this->once())
278+
->method('hydrate')
279+
->with(
280+
$this->isInstanceOf(ClassMetadata::class),
281+
$data,
282+
['context' => '123'],
283+
$this->isInstanceOf(Stack::class),
284+
)->willReturn($expect);
285+
286+
$hydrator = MetadataHydrator::create([$middleware]);
287+
288+
$object = $hydrator->hydrate(InferNormalizerDto::class, $data, ['context' => '123']);
289+
290+
self::assertEquals($expect, $object);
291+
}
292+
223293
public function testDenormalizationFailure(): void
224294
{
225295
$this->expectException(DenormalizationFailure::class);

0 commit comments

Comments
 (0)