Skip to content
Merged
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
1 change: 0 additions & 1 deletion features/authorization/deny.feature
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,3 @@ Feature: Authorization checking
And I send a "GET" request to "/secured_dummies"
Then the response status code should be 200
And the response should contain "ownerOnlyProperty"

6 changes: 3 additions & 3 deletions src/Core/Annotation/ApiFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class ApiFilter
public $arguments = [];

/**
* @param string $filterClass
* @param mixed $filterClass
* @param string $id
* @param string $strategy
*/
Expand All @@ -65,9 +65,9 @@ public function __construct(
array $properties = [],
array $arguments = []
) {
if (\is_array($filterClass)) { /** @phpstan-ignore-line Doctrine annotations */
if (\is_array($filterClass)) {
$options = $filterClass;
$this->filterClass = $options['value'] ?? null; /* @phpstan-ignore-line Doctrine annotations */
$this->filterClass = $options['value'] ?? null;
unset($options['value']);

foreach ($options as $key => $value) {
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Annotation/ApiProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* @Annotation
*
* @Target({"METHOD", "PROPERTY"})
*
* @Attributes(
*
* @Attribute("deprecationReason", type="string"),
* @Attribute("fetchable", type="bool"),
* @Attribute("fetchEager", type="bool"),
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Annotation/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* @Annotation
*
* @Target({"CLASS"})
*
* @Attributes(
*
* @Attribute("accessControl", type="string"),
* @Attribute("accessControlMessage", type="string"),
* @Attribute("attributes", type="array"),
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Annotation/ApiSubresource.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
* @Annotation
*
* @Target({"METHOD", "PROPERTY"})
*
* @Attributes(
*
* @Attribute("maxDepth", type="int"),
* )
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Identifier/IdentifierConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function convert($data, string $class, array $context = []): array
try {
$identifiers[$parameter] = $identifierTransformer->denormalize($value, $type);
break;
} catch (InvalidIdentifierException $e) {
} catch (InvalidIdentifierException $e) { // @phpstan-ignore-line wrong choice of interface, was fixed in 3.0
throw new InvalidIdentifierException(sprintf('Identifier "%s" could not be denormalized.', $parameter), $e->getCode(), $e);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/JsonApi/Serializer/ItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ protected function normalizeRelation($propertyMetadata, $relatedObject, string $
}

$normalizedRelatedObject = $this->serializer->normalize($relatedObject, $format, $context);
// @phpstan-ignore-next-line throwing an explicit exception helps debugging
if (!\is_string($normalizedRelatedObject) && !\is_array($normalizedRelatedObject) && !$normalizedRelatedObject instanceof \ArrayObject && null !== $normalizedRelatedObject) {
throw new UnexpectedValueException('Expected normalized relation to be an IRI, array, \ArrayObject or null');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/ApiFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
$this->arguments = $arguments;
}

if (!\is_string($this->filterClass)) {
if (!\is_string($this->filterClass)) { /* @phpstan-ignore-line Doctrine annotations */
throw new InvalidArgumentException('This annotation needs a value representing the filter class.');
}

Expand Down
1 change: 0 additions & 1 deletion src/Serializer/AbstractItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,6 @@ protected function normalizeRelation($propertyMetadata, $relatedObject, string $
}

$normalizedRelatedObject = $this->serializer->normalize($relatedObject, $format, $context);
// @phpstan-ignore-next-line throwing an explicit exception helps debugging
if (!\is_string($normalizedRelatedObject) && !\is_array($normalizedRelatedObject) && !$normalizedRelatedObject instanceof \ArrayObject && null !== $normalizedRelatedObject) {
throw new UnexpectedValueException('Expected normalized relation to be an IRI, array, \ArrayObject or null');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Serializer/CacheKeyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ private function getCacheKey(?string $format, array $context)
unset($context['cache_key']); // avoid artificially different keys

try {
return hash('xxh128', $format.serialize([
return hash('md5', $format.serialize([
'context' => $context,
'ignored' => $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES],
]));
} catch (\Exception) {
} catch (\Exception $e) {
// The context cannot be serialized, skip the cache
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Core/Annotation/ApiFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ public function testInvalidConstructor()
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('This annotation needs a value representing the filter class.');

new ApiFilter(null); // @phpstan-ignore-line
new ApiFilter(null);
}

public function testInvalidFilter()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The filter class "ApiPlatform\\Tests\\Fixtures\\TestBundle\\Entity\\Dummy" does not implement "ApiPlatform\\Api\\FilterInterface". Did you forget a use statement?');

new ApiFilter(['value' => Dummy::class]); // @phpstan-ignore-line
new ApiFilter(['value' => Dummy::class]);
}

public function testInvalidProperty()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Property "foo" does not exist on the ApiFilter annotation.');

new ApiFilter(['value' => DummyFilter::class, 'foo' => 'bar']); // @phpstan-ignore-line
new ApiFilter(['value' => DummyFilter::class, 'foo' => 'bar']);
}

public function testAssignation()
{
$resource = new ApiFilter(['value' => DummyFilter::class, 'strategy' => 'test', 'properties' => ['one', 'two'], 'arguments' => ['args']]); // @phpstan-ignore-line
$resource = new ApiFilter(['value' => DummyFilter::class, 'strategy' => 'test', 'properties' => ['one', 'two'], 'arguments' => ['args']]);

$this->assertEquals($resource->filterClass, DummyFilter::class);
$this->assertEquals($resource->strategy, 'test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testCreate()
$decorated->create(Dummy::class)->willReturn(new ResourceMetadata('hello', 'blabla'))->shouldBeCalled();

$reader = $this->prophesize(Reader::class);
$reader->getClassAnnotations(Argument::type(\ReflectionClass::class))->shouldBeCalled()->willReturn([ // @phpstan-ignore-next-line
$reader->getClassAnnotations(Argument::type(\ReflectionClass::class))->shouldBeCalled()->willReturn([
new ApiFilter(['value' => DummyFilter::class]),
]);

Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/DummyAtLeastOneOfValidatedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class DummyAtLeastOneOfValidatedEntity
* @var string
*
* @Assert\AtLeastOneOf({
*
* @Assert\Regex("/#/"),
*
* @Assert\Length(min=10)
* })
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/Fixtures/DummyCollectionValidatedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ class DummyCollectionValidatedEntity
* allowExtraFields=true,
* fields={
* "name"=@Assert\Required({
*
* @Assert\NotBlank
* }),
* "email"={
*
* @Assert\NotNull,
*
* @Assert\Length(min=2, max=255),
*
* @Assert\Email(mode=Assert\Email::VALIDATION_MODE_LOOSE)
* },
* "phone"=@Assert\Optional({
*
* @Assert\Type(type="string"),
*
* @Assert\Regex(pattern="/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.\/0-9]*$/")
* }),
* "age"=@Assert\Optional({
*
* @Assert\Type(type="int")
* }),
* "social"=@Assert\Collection(
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/DummySequentiallyValidatedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class DummySequentiallyValidatedEntity
* @var string
*
* @Assert\Sequentially({
*
* @Assert\Length(min=1, max=32),
*
* @Assert\Regex(pattern="/^[a-z]$/")
* })
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/DummyValidatedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class DummyValidatedEntity
* @var string A dummy
*
* @Assert\NotBlank
*
* @Assert\Length(max="4", min="10")
*
* @Assert\Regex(pattern="/^dummy$/")
*/
public $dummy;
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/Elasticsearch/Model/Tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
* "groups"={"tweet:read"}
* }
* )
*
* @ApiFilter(OrderFilter::class, properties={"id", "author.id"})
* @ApiFilter(MatchFilter::class, properties={"message", "author.firstName"})
*/
class Tweet
{
/**
* @ApiProperty(identifier=true)
*
* @Groups({"tweet:read", "user:read"})
*/
private $id;
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/Elasticsearch/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
* "groups"={"user:read"}
* }
* )
*
* @ApiFilter(TermFilter::class, properties={"id", "gender", "age", "firstName", "tweets.id", "tweets.date"})
*/
class User
{
/**
* @ApiProperty(identifier=true)
*
* @Groups({"user:read", "tweet:read"})
*/
private $id;
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/Document/AbsoluteUrlDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* @ApiResource(urlGenerationStrategy=UrlGeneratorInterface::ABS_URL)
*
* @ODM\Document
*/
class AbsoluteUrlDummy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/**
* @ApiResource(urlGenerationStrategy=UrlGeneratorInterface::ABS_URL)
*
* @ODM\Document
*/
class AbsoluteUrlRelationDummy
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixtures/TestBundle/Document/AbstractDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
* itemOperations={"get", "put", "delete"},
* attributes={"filters"={"my_dummy.mongodb.search", "my_dummy.mongodb.order", "my_dummy.mongodb.date"}}
* )
*
* @ODM\Document
*
* @ODM\InheritanceType("SINGLE_COLLECTION")
*
* @ODM\DiscriminatorField(value="discr")
*
* @ODM\DiscriminatorMap({"concrete"=ConcreteDummy::class})
*/
abstract class AbstractDummy
Expand All @@ -46,7 +50,9 @@ abstract class AbstractDummy
* @var string The dummy name
*
* @ODM\Field
*
* @Assert\NotBlank
*
* @ApiProperty(iri="http://schema.org/name")
*/
private $name;
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/TestBundle/Document/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @ApiResource(
* attributes={"normalization_context"={"groups"={"order_read"}}}
* )
*
* @ODM\Document
*/
class Address
Expand All @@ -29,12 +30,14 @@ class Address
* @var int
*
* @ODM\Id(strategy="INCREMENT", type="int")
*
* @Groups({"order_read"})
*/
private $id;

/**
* @ODM\Field(type="string")
*
* @Groups({"order_read"})
*/
public $name;
Expand Down
5 changes: 5 additions & 0 deletions tests/Fixtures/TestBundle/Document/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Answer.
*
* @ODM\Document
*
* @ApiResource(collectionOperations={
* "get_subresource_answer"={"method"="GET", "normalization_context"={"groups"={"foobar"}}}
* })
Expand All @@ -32,24 +33,28 @@ class Answer
{
/**
* @ODM\Id(strategy="INCREMENT", type="int")
*
* @Serializer\Groups({"foobar"})
*/
private $id;

/**
* @ODM\Field(nullable=false)
*
* @Serializer\Groups({"foobar"})
*/
private $content;

/**
* @ODM\ReferenceOne(targetDocument=Question::class, mappedBy="answer")
*
* @Serializer\Groups({"foobar"})
*/
private $question;

/**
* @ODM\ReferenceMany(targetDocument=Question::class, mappedBy="answer")
*
* @Serializer\Groups({"foobar"})
*
* @ApiSubresource
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/TestBundle/Document/ArrayFilterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* ArrayRequiredFilter::class
* }
* })
*
* @ODM\Document
*/
class ArrayFilterValidator
Expand All @@ -44,6 +45,7 @@ class ArrayFilterValidator
* @var string A name
*
* @ODM\Field
*
* @ApiProperty(iri="http://schema.org/name")
*/
private $name;
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/Document/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* "get",
* "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}, "identifiers"="isbn"}
* })
*
* @ODM\Document
*/
class Book
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/TestBundle/Document/CircularReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @author Kévin Dunglas <dunglas@gmail.com>
*
* @ApiResource(attributes={"normalization_context"={"groups"={"circular"}}})
*
* @ODM\Document
*/
class CircularReference
Expand All @@ -35,12 +36,14 @@ class CircularReference

/**
* @ODM\ReferenceOne(targetDocument=CircularReference::class, inversedBy="children")
*
* @Groups({"circular"})
*/
public $parent;

/**
* @ODM\ReferenceMany(targetDocument=CircularReference::class, mappedBy="parent")
*
* @Groups({"circular"})
*/
public $children;
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/TestBundle/Document/CompositeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ class CompositeItem

/**
* @ODM\Field(type="string", nullable=true)
*
* @Groups({"default"})
*/
private $field1;

/**
* @ODM\ReferenceMany(targetDocument=CompositeRelation::class, mappedBy="compositeItem")
*
* @Groups({"default"})
*/
private $compositeValues;
Expand Down
Loading