Skip to content

Commit

Permalink
Added test covering that null should be ignored in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Sep 8, 2020
1 parent 4e0aa8a commit 95f0bd0
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
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 95f0bd0

Please sign in to comment.