Skip to content

Commit

Permalink
Bugfix | Don't try to set null values when merging metadata (#3711)
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd authored Sep 10, 2020
1 parent 9b1013f commit 1cf1097
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ private function createWith(ResourceMetadata $resourceMetadata, string $property
return $resourceMetadata;
}

if (null === $value) {
return $resourceMetadata;
}

$wither = "with$upperProperty";

return $resourceMetadata->{$wither}($value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AnnotationResourceMetadataFactoryTest extends TestCase
/**
* @dataProvider getCreateDependencies
*/
public function testCreate($reader, $decorated, string $expectedShortName, string $expectedDescription)
public function testCreate($reader, $decorated, string $expectedShortName, ?string $expectedDescription)
{
$factory = new AnnotationResourceMetadataFactory($reader->reveal(), $decorated ? $decorated->reveal() : null);
$metadata = $factory->create(Dummy::class);
Expand Down Expand Up @@ -62,7 +62,7 @@ public function testCreateWithoutAttributes()

public function getCreateDependencies()
{
$annotation = new ApiResource([
$resourceData = [
'shortName' => 'shortName',
'description' => 'description',
'iri' => 'http://example.com',
Expand All @@ -71,21 +71,32 @@ public function getCreateDependencies()
'subresourceOperations' => ['sub' => ['bus' => false]],
'attributes' => ['a' => 1, 'route_prefix' => '/foobar'],
'graphql' => ['foo' => 'bar'],
]);
];
$annotationFull = new ApiResource($resourceData);

$reader = $this->prophesize(Reader::class);
$reader->getClassAnnotation(Argument::type(\ReflectionClass::class), ApiResource::class)->willReturn($annotation)->shouldBeCalled();
$reader->getClassAnnotation(Argument::type(\ReflectionClass::class), ApiResource::class)->willReturn($annotationFull)->shouldBeCalled();

$decoratedThrow = $this->prophesize(ResourceMetadataFactoryInterface::class);
$decoratedThrow->create(Dummy::class)->willThrow(ResourceClassNotFoundException::class);

$decoratedReturn = $this->prophesize(ResourceMetadataFactoryInterface::class);
$decoratedReturn->create(Dummy::class)->willReturn(new ResourceMetadata('hello', 'blabla'))->shouldBeCalled();

$resourceData['description'] = null;
$annotationWithNull = new ApiResource($resourceData);

$decoratedReturnWithNull = $this->prophesize(ResourceMetadataFactoryInterface::class);
$decoratedReturnWithNull->create(Dummy::class)->willReturn(new ResourceMetadata('hello'))->shouldBeCalled();

$readerWithNull = $this->prophesize(Reader::class);
$readerWithNull->getClassAnnotation(Argument::type(\ReflectionClass::class), ApiResource::class)->willReturn($annotationWithNull)->shouldBeCalled();

return [
[$reader, $decoratedThrow, 'shortName', 'description'],
[$reader, null, 'shortName', 'description'],
[$reader, $decoratedReturn, 'hello', 'blabla'],
[$readerWithNull, $decoratedReturnWithNull, 'hello', null],
];
}
}

0 comments on commit 1cf1097

Please sign in to comment.