Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ private function createWith(ResourceMetadata $resourceMetadata, string $property
$upperProperty = ucfirst($property);
$getter = "get$upperProperty";

if (null !== $resourceMetadata->{$getter}()) {
return $resourceMetadata;
$currentValue = $resourceMetadata->{$getter}();
if (null !== $currentValue) {
if (null === $value) {
$value = $currentValue;
} elseif (is_array($currentValue)) {
$value = array_merge_recursive($currentValue, $value);
}
}

$wither = "with$upperProperty";
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],
];
}
}