Skip to content

Commit 2899344

Browse files
committed
Fix PHPUnit tests
1 parent 905aca7 commit 2899344

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/Serializer/AbstractItemNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ protected function getAttributeValue($object, $attribute, $format = null, array
428428
*
429429
* @return string|array
430430
*/
431-
private function normalizeRelation(PropertyMetadata $propertyMetadata, $relatedObject, string $resourceClass, string $format = null, array &$context)
431+
private function normalizeRelation(PropertyMetadata $propertyMetadata, $relatedObject, string $resourceClass, string $format = null, array $context)
432432
{
433433
if ($propertyMetadata->isReadableLink()) {
434434
return $this->serializer->normalize($relatedObject, $format, $this->createRelationSerializationContext($resourceClass, $context));

tests/Serializer/AbstractItemNormalizerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function testNormalize()
108108
)->shouldBeCalled();
109109

110110
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
111+
$iriConverterProphecy->getIriFromItem($dummy)->willReturn('/dummies/1')->shouldBeCalled();
111112
$iriConverterProphecy->getIriFromItem($relatedDummy)->willReturn('/dummies/2')->shouldBeCalled();
112113

113114
$propertyAccesorProphecy = $this->prophesize(PropertyAccessorInterface::class);
@@ -177,6 +178,7 @@ public function testNormalizeReadableLinks()
177178
)->shouldBeCalled();
178179

179180
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
181+
$iriConverterProphecy->getIriFromItem($dummy)->willReturn('/dummies/1')->shouldBeCalled();
180182

181183
$propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
182184
$propertyAccessorProphecy->getValue($dummy, 'relatedDummy')->willReturn($relatedDummy)->shouldBeCalled();
@@ -609,6 +611,7 @@ public function testChildInheritedProperty()
609611
)->shouldBeCalled();
610612

611613
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
614+
$iriConverterProphecy->getIriFromItem($dummy)->willReturn('/dummies/1')->shouldBeCalled();
612615

613616
$propertyAccesorProphecy = $this->prophesize(PropertyAccessorInterface::class);
614617
$propertyAccesorProphecy->getValue($dummy, 'name')->willReturn('foo')->shouldBeCalled();

tests/Serializer/ItemNormalizerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function testNormalize()
7878
$propertyMetadataFactoryProphecy->create(Dummy::class, 'name', [])->willReturn($propertyMetadataFactory)->shouldBeCalled();
7979

8080
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
81+
$iriConverterProphecy->getIriFromItem($dummy)->willReturn('/dummies/1')->shouldBeCalled();
8182

8283
$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
8384
$resourceClassResolverProphecy->getResourceClass($dummy, null, true)->willReturn(Dummy::class)->shouldBeCalled();

tests/Serializer/SerializerContextBuilderTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ protected function setUp()
4848
public function testCreateFromRequest()
4949
{
5050
$request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_item_operation_name' => 'get', '_api_format' => 'xml', '_api_mime_type' => 'text/xml']);
51-
$expected = ['foo' => 'bar', 'item_operation_name' => 'get', 'resource_class' => 'Foo', 'request_uri' => '', 'operation_type' => 'item'];
51+
$expected = ['foo' => 'bar', 'item_operation_name' => 'get', 'resource_class' => 'Foo', 'request_uri' => '', 'operation_type' => 'item', 'request' => $request];
5252
$this->assertEquals($expected, $this->builder->createFromRequest($request, true));
5353

5454
$request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'pot', '_api_format' => 'xml', '_api_mime_type' => 'text/xml']);
55-
$expected = ['foo' => 'bar', 'collection_operation_name' => 'pot', 'resource_class' => 'Foo', 'request_uri' => '', 'operation_type' => 'collection'];
55+
$expected = ['foo' => 'bar', 'collection_operation_name' => 'pot', 'resource_class' => 'Foo', 'request_uri' => '', 'operation_type' => 'collection', 'request' => $request];
5656
$this->assertEquals($expected, $this->builder->createFromRequest($request, true));
5757

5858
$request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_item_operation_name' => 'get', '_api_format' => 'xml', '_api_mime_type' => 'text/xml']);
59-
$expected = ['bar' => 'baz', 'item_operation_name' => 'get', 'resource_class' => 'Foo', 'request_uri' => '', 'api_allow_update' => false, 'operation_type' => 'item'];
59+
$expected = ['bar' => 'baz', 'item_operation_name' => 'get', 'resource_class' => 'Foo', 'request_uri' => '', 'api_allow_update' => false, 'operation_type' => 'item', 'request' => $request];
6060
$this->assertEquals($expected, $this->builder->createFromRequest($request, false));
6161

6262
$request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'post', '_api_format' => 'xml', '_api_mime_type' => 'text/xml'], [], [], ['REQUEST_METHOD' => 'POST']);
63-
$expected = ['bar' => 'baz', 'collection_operation_name' => 'post', 'resource_class' => 'Foo', 'request_uri' => '', 'api_allow_update' => false, 'operation_type' => 'collection'];
63+
$expected = ['bar' => 'baz', 'collection_operation_name' => 'post', 'resource_class' => 'Foo', 'request_uri' => '', 'api_allow_update' => false, 'operation_type' => 'collection', 'request' => $request];
6464
$this->assertEquals($expected, $this->builder->createFromRequest($request, false));
6565

6666
$request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'put', '_api_format' => 'xml', '_api_mime_type' => 'text/xml'], [], [], ['REQUEST_METHOD' => 'PUT']);
67-
$expected = ['bar' => 'baz', 'collection_operation_name' => 'put', 'resource_class' => 'Foo', 'request_uri' => '', 'api_allow_update' => true, 'operation_type' => 'collection'];
67+
$expected = ['bar' => 'baz', 'collection_operation_name' => 'put', 'resource_class' => 'Foo', 'request_uri' => '', 'api_allow_update' => true, 'operation_type' => 'collection', 'request' => $request];
6868
$this->assertEquals($expected, $this->builder->createFromRequest($request, false));
6969

7070
$request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_subresource_operation_name' => 'get', '_api_format' => 'xml', '_api_mime_type' => 'text/xml'], [], [], ['REQUEST_METHOD' => 'GET']);
71-
$expected = ['bar' => 'baz', 'subresource_operation_name' => 'get', 'resource_class' => 'Foo', 'request_uri' => '', 'operation_type' => 'subresource', 'api_allow_update' => false];
71+
$expected = ['bar' => 'baz', 'subresource_operation_name' => 'get', 'resource_class' => 'Foo', 'request_uri' => '', 'operation_type' => 'subresource', 'api_allow_update' => false, 'request' => $request];
7272
$this->assertEquals($expected, $this->builder->createFromRequest($request, false));
7373
}
7474

@@ -82,7 +82,9 @@ public function testThrowExceptionOnInvalidRequest()
8282

8383
public function testReuseExistingAttributes()
8484
{
85-
$expected = ['bar' => 'baz', 'item_operation_name' => 'get', 'resource_class' => 'Foo', 'request_uri' => '', 'api_allow_update' => false, 'operation_type' => 'item'];
86-
$this->assertEquals($expected, $this->builder->createFromRequest(new Request(), false, ['resource_class' => 'Foo', 'item_operation_name' => 'get']));
85+
$request = new Request();
86+
87+
$expected = ['bar' => 'baz', 'item_operation_name' => 'get', 'resource_class' => 'Foo', 'request_uri' => '', 'api_allow_update' => false, 'operation_type' => 'item', 'request' => $request];
88+
$this->assertEquals($expected, $this->builder->createFromRequest($request, false, ['resource_class' => 'Foo', 'item_operation_name' => 'get']));
8789
}
8890
}

0 commit comments

Comments
 (0)