From 40a95b560a1357cd406ea81ae2b792e72f683542 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 21 Jul 2025 12:00:03 +0200 Subject: [PATCH] chore: use class-string param type --- .../Tests/State/CollectionProviderTest.php | 2 +- .../Orm/Tests/State/ItemProviderTest.php | 2 +- .../Processor/NormalizeProcessorTest.php | 64 ++++++++-------- .../Provider/DenormalizeProviderTest.php | 16 ++-- .../Tests/State/Provider/ReadProviderTest.php | 8 +- .../State/Provider/ResolverProviderTest.php | 2 +- src/GraphQl/Tests/Type/FieldsBuilderTest.php | 72 +++++++++--------- src/GraphQl/Tests/Type/TypeBuilderTest.php | 74 +++++++++---------- .../Tests/State/AddTagsProcessorTest.php | 4 +- .../Tests/State/JsonApiProviderTest.php | 2 +- src/Metadata/ApiResource.php | 1 + src/Metadata/Metadata.php | 7 ++ ...rResourceMetadataCollectionFactoryTest.php | 6 +- .../Serializer/OpenApiNormalizerTest.php | 10 +-- .../Provider/DeserializeProviderTest.php | 24 +++--- .../SecurityParameterProviderTest.php | 6 +- .../Tests/EventListener/ReadListenerTest.php | 18 ++--- .../EventListener/RespondListenerTest.php | 14 ++-- .../EventListener/SerializeListenerTest.php | 14 ++-- .../EventListener/ValidateListenerTest.php | 26 +++---- .../Tests/EventListener/WriteListenerTest.php | 20 ++--- .../State/AccessCheckerProviderTest.php | 21 +++--- 22 files changed, 211 insertions(+), 202 deletions(-) diff --git a/src/Doctrine/Orm/Tests/State/CollectionProviderTest.php b/src/Doctrine/Orm/Tests/State/CollectionProviderTest.php index 77dbb3062ed..9837c79999d 100644 --- a/src/Doctrine/Orm/Tests/State/CollectionProviderTest.php +++ b/src/Doctrine/Orm/Tests/State/CollectionProviderTest.php @@ -138,7 +138,7 @@ public function testCannotCreateQueryBuilder(): void public function testHandleLinksCallable(): void { - $class = 'foo'; + $class = \stdClass::class; $resourceMetadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $query = $this->createStub($this->getQueryClass()); $query->method('getResult')->willReturn([]); diff --git a/src/Doctrine/Orm/Tests/State/ItemProviderTest.php b/src/Doctrine/Orm/Tests/State/ItemProviderTest.php index 35432196d42..ec730378939 100644 --- a/src/Doctrine/Orm/Tests/State/ItemProviderTest.php +++ b/src/Doctrine/Orm/Tests/State/ItemProviderTest.php @@ -328,7 +328,7 @@ class_exists(ManyToOneAssociationMapping::class) ? public function testHandleLinksCallable(): void { - $class = 'foo'; + $class = \stdClass::class; $resourceMetadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $query = $this->createStub($this->getQueryClass()); $query->method('getOneOrNullResult')->willReturn(null); diff --git a/src/GraphQl/Tests/State/Processor/NormalizeProcessorTest.php b/src/GraphQl/Tests/State/Processor/NormalizeProcessorTest.php index 3d9a23c9c30..43baca2ce1f 100644 --- a/src/GraphQl/Tests/State/Processor/NormalizeProcessorTest.php +++ b/src/GraphQl/Tests/State/Processor/NormalizeProcessorTest.php @@ -58,9 +58,9 @@ public function testProcess($body, $operation): void public static function processItems(): array { return [ - [new \stdClass(), new Query(class: 'foo')], - [new \stdClass(), new Mutation(class: 'foo', shortName: 'Foo')], - [new \stdClass(), new Subscription(class: 'foo', shortName: 'Foo')], + [new \stdClass(), new Query(class: \stdClass::class)], + [new \stdClass(), new Mutation(class: \stdClass::class, shortName: 'Foo')], + [new \stdClass(), new Subscription(class: \stdClass::class, shortName: 'Foo')], ]; } @@ -100,34 +100,34 @@ public static function processCollection(): iterable return $partialPaginatorProphecy->reveal(); }; - yield 'cursor - not paginator' => [[], new QueryCollection(class: 'foo'), [], null, [], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\PaginatorInterface or ApiPlatform\State\Pagination\PartialPaginatorInterface.']; - yield 'cursor - empty paginator' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: 'foo'), [], ['totalCount' => 0., 'edges' => [], 'pageInfo' => ['startCursor' => null, 'endCursor' => null, 'hasNextPage' => false, 'hasPreviousPage' => false]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; - yield 'cursor - paginator' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), new QueryCollection(class: 'foo'), [], ['totalCount' => 3., 'edges' => [['node' => ['normalized_item'], 'cursor' => 'MA=='], ['node' => ['normalized_item'], 'cursor' => 'MQ==']], 'pageInfo' => ['startCursor' => 'MA==', 'endCursor' => 'MQ==', 'hasNextPage' => true, 'hasPreviousPage' => false]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; - yield 'cursor - paginator with after cursor' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 1, 2), new QueryCollection(class: 'foo'), ['after' => 'MA=='], ['totalCount' => 3., 'edges' => [['node' => ['normalized_item'], 'cursor' => 'MQ=='], ['node' => ['normalized_item'], 'cursor' => 'Mg==']], 'pageInfo' => ['startCursor' => 'MQ==', 'endCursor' => 'Mg==', 'hasNextPage' => false, 'hasPreviousPage' => true]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; - yield 'cursor - paginator with bad after cursor' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: 'foo'), ['after' => '-'], null, ['edges' => ['cursor' => []]], \UnexpectedValueException::class, 'Cursor - is invalid']; - yield 'cursor - paginator with empty after cursor' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: 'foo'), ['after' => ''], null, ['edges' => ['cursor' => []]], \UnexpectedValueException::class, 'Empty cursor is invalid']; - yield 'cursor - paginator with before cursor' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 1, 1), new QueryCollection(class: 'foo'), ['before' => 'Mg=='], ['totalCount' => 3., 'edges' => [['node' => ['normalized_item'], 'cursor' => 'MQ==']], 'pageInfo' => ['startCursor' => 'MQ==', 'endCursor' => 'MQ==', 'hasNextPage' => true, 'hasPreviousPage' => true]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; - yield 'cursor - paginator with bad before cursor' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: 'foo'), ['before' => '-'], null, ['pageInfo' => ['endCursor' => true]], \UnexpectedValueException::class, 'Cursor - is invalid']; - yield 'cursor - paginator with empty before cursor' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: 'foo'), ['before' => ''], null, ['pageInfo' => ['endCursor' => true]], \UnexpectedValueException::class, 'Empty cursor is invalid']; - yield 'cursor - paginator with last' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 1, 2), new QueryCollection(class: 'foo'), ['last' => 2], ['totalCount' => 3., 'edges' => [['node' => ['normalized_item'], 'cursor' => 'MQ=='], ['node' => ['normalized_item'], 'cursor' => 'Mg==']], 'pageInfo' => ['startCursor' => 'MQ==', 'endCursor' => 'Mg==', 'hasNextPage' => false, 'hasPreviousPage' => true]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; - yield 'cursor - partial paginator' => [$partialPaginatorFactory, new QueryCollection(class: 'foo'), [], ['totalCount' => 0., 'edges' => [], 'pageInfo' => ['startCursor' => 'MA==', 'endCursor' => 'MQ==', 'hasNextPage' => false, 'hasPreviousPage' => false]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; - yield 'cursor - partial paginator with after cursor' => [$partialPaginatorFactory, new QueryCollection(class: 'foo'), ['after' => 'MA=='], ['totalCount' => 0., 'edges' => [], 'pageInfo' => ['startCursor' => 'MQ==', 'endCursor' => 'Mg==', 'hasNextPage' => false, 'hasPreviousPage' => true]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; - - yield 'page - not paginator, itemsPerPage requested' => [[], (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], [], ['paginationInfo' => ['itemsPerPage' => true]], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\PartialPaginatorInterface to return itemsPerPage field.']; - yield 'page - not paginator, lastPage requested' => [[], (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], [], ['paginationInfo' => ['lastPage' => true]], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\PaginatorInterface to return lastPage field.']; - yield 'page - not paginator, totalCount requested' => [[], (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], [], ['paginationInfo' => ['totalCount' => true]], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\PaginatorInterface to return totalCount field.']; - yield 'page - not paginator, hasNextPage requested' => [[], (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], [], ['paginationInfo' => ['hasNextPage' => true]], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\HasNextPagePaginatorInterface to return hasNextPage field.']; - yield 'page - empty paginator - itemsPerPage requested' => [new ArrayPaginator([], 0, 0), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [], 'paginationInfo' => ['itemsPerPage' => .0]], ['paginationInfo' => ['itemsPerPage' => true]]]; - yield 'page - empty paginator - lastPage requested' => [new ArrayPaginator([], 0, 0), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [], 'paginationInfo' => ['lastPage' => 1.0]], ['paginationInfo' => ['lastPage' => true]]]; - yield 'page - empty paginator - totalCount requested' => [new ArrayPaginator([], 0, 0), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [], 'paginationInfo' => ['totalCount' => .0]], ['paginationInfo' => ['totalCount' => true]]]; - yield 'page - empty paginator - hasNextPage requested' => [new ArrayPaginator([], 0, 0), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [], 'paginationInfo' => ['hasNextPage' => false]], ['paginationInfo' => ['hasNextPage' => true]]]; - yield 'page - paginator page 1 - itemsPerPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [['normalized_item'], ['normalized_item']], 'paginationInfo' => ['itemsPerPage' => 2.0]], ['paginationInfo' => ['itemsPerPage' => true]]]; - yield 'page - paginator page 1 - lastPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [['normalized_item'], ['normalized_item']], 'paginationInfo' => ['lastPage' => 2.0]], ['paginationInfo' => ['lastPage' => true]]]; - yield 'page - paginator page 1 - totalCount requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [['normalized_item'], ['normalized_item']], 'paginationInfo' => ['totalCount' => 3.0]], ['paginationInfo' => ['totalCount' => true]]]; - yield 'page - paginator page 1 - hasNextPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [['normalized_item'], ['normalized_item']], 'paginationInfo' => ['hasNextPage' => true]], ['paginationInfo' => ['hasNextPage' => true]]]; - yield 'page - paginator with page - itemsPerPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 2, 2), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [['normalized_item']], 'paginationInfo' => ['itemsPerPage' => 2.0]], ['paginationInfo' => ['itemsPerPage' => true]]]; - yield 'page - paginator with page - lastPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 2, 2), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [['normalized_item']], 'paginationInfo' => ['lastPage' => 2.0]], ['paginationInfo' => ['lastPage' => true]]]; - yield 'page - paginator with page - totalCount requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 2, 2), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [['normalized_item']], 'paginationInfo' => ['totalCount' => 3.0]], ['paginationInfo' => ['totalCount' => true]]]; - yield 'page - paginator with page - hasNextPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 2, 2), (new QueryCollection(class: 'foo'))->withPaginationType('page'), [], ['collection' => [['normalized_item']], 'paginationInfo' => ['hasNextPage' => false]], ['paginationInfo' => ['hasNextPage' => true]]]; + yield 'cursor - not paginator' => [[], new QueryCollection(class: \stdClass::class), [], null, [], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\PaginatorInterface or ApiPlatform\State\Pagination\PartialPaginatorInterface.']; + yield 'cursor - empty paginator' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: \stdClass::class), [], ['totalCount' => 0., 'edges' => [], 'pageInfo' => ['startCursor' => null, 'endCursor' => null, 'hasNextPage' => false, 'hasPreviousPage' => false]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; + yield 'cursor - paginator' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), new QueryCollection(class: \stdClass::class), [], ['totalCount' => 3., 'edges' => [['node' => ['normalized_item'], 'cursor' => 'MA=='], ['node' => ['normalized_item'], 'cursor' => 'MQ==']], 'pageInfo' => ['startCursor' => 'MA==', 'endCursor' => 'MQ==', 'hasNextPage' => true, 'hasPreviousPage' => false]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; + yield 'cursor - paginator with after cursor' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 1, 2), new QueryCollection(class: \stdClass::class), ['after' => 'MA=='], ['totalCount' => 3., 'edges' => [['node' => ['normalized_item'], 'cursor' => 'MQ=='], ['node' => ['normalized_item'], 'cursor' => 'Mg==']], 'pageInfo' => ['startCursor' => 'MQ==', 'endCursor' => 'Mg==', 'hasNextPage' => false, 'hasPreviousPage' => true]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; + yield 'cursor - paginator with bad after cursor' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: \stdClass::class), ['after' => '-'], null, ['edges' => ['cursor' => []]], \UnexpectedValueException::class, 'Cursor - is invalid']; + yield 'cursor - paginator with empty after cursor' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: \stdClass::class), ['after' => ''], null, ['edges' => ['cursor' => []]], \UnexpectedValueException::class, 'Empty cursor is invalid']; + yield 'cursor - paginator with before cursor' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 1, 1), new QueryCollection(class: \stdClass::class), ['before' => 'Mg=='], ['totalCount' => 3., 'edges' => [['node' => ['normalized_item'], 'cursor' => 'MQ==']], 'pageInfo' => ['startCursor' => 'MQ==', 'endCursor' => 'MQ==', 'hasNextPage' => true, 'hasPreviousPage' => true]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; + yield 'cursor - paginator with bad before cursor' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: \stdClass::class), ['before' => '-'], null, ['pageInfo' => ['endCursor' => true]], \UnexpectedValueException::class, 'Cursor - is invalid']; + yield 'cursor - paginator with empty before cursor' => [new ArrayPaginator([], 0, 0), new QueryCollection(class: \stdClass::class), ['before' => ''], null, ['pageInfo' => ['endCursor' => true]], \UnexpectedValueException::class, 'Empty cursor is invalid']; + yield 'cursor - paginator with last' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 1, 2), new QueryCollection(class: \stdClass::class), ['last' => 2], ['totalCount' => 3., 'edges' => [['node' => ['normalized_item'], 'cursor' => 'MQ=='], ['node' => ['normalized_item'], 'cursor' => 'Mg==']], 'pageInfo' => ['startCursor' => 'MQ==', 'endCursor' => 'Mg==', 'hasNextPage' => false, 'hasPreviousPage' => true]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; + yield 'cursor - partial paginator' => [$partialPaginatorFactory, new QueryCollection(class: \stdClass::class), [], ['totalCount' => 0., 'edges' => [], 'pageInfo' => ['startCursor' => 'MA==', 'endCursor' => 'MQ==', 'hasNextPage' => false, 'hasPreviousPage' => false]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; + yield 'cursor - partial paginator with after cursor' => [$partialPaginatorFactory, new QueryCollection(class: \stdClass::class), ['after' => 'MA=='], ['totalCount' => 0., 'edges' => [], 'pageInfo' => ['startCursor' => 'MQ==', 'endCursor' => 'Mg==', 'hasNextPage' => false, 'hasPreviousPage' => true]], ['totalCount' => true, 'edges' => ['cursor' => true], 'pageInfo' => ['startCursor' => true, 'endCursor' => true, 'hasNextPage' => true, 'hasPreviousPage' => true]]]; + + yield 'page - not paginator, itemsPerPage requested' => [[], (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], [], ['paginationInfo' => ['itemsPerPage' => true]], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\PartialPaginatorInterface to return itemsPerPage field.']; + yield 'page - not paginator, lastPage requested' => [[], (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], [], ['paginationInfo' => ['lastPage' => true]], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\PaginatorInterface to return lastPage field.']; + yield 'page - not paginator, totalCount requested' => [[], (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], [], ['paginationInfo' => ['totalCount' => true]], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\PaginatorInterface to return totalCount field.']; + yield 'page - not paginator, hasNextPage requested' => [[], (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], [], ['paginationInfo' => ['hasNextPage' => true]], \LogicException::class, 'Collection returned by the collection data provider must implement ApiPlatform\State\Pagination\HasNextPagePaginatorInterface to return hasNextPage field.']; + yield 'page - empty paginator - itemsPerPage requested' => [new ArrayPaginator([], 0, 0), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [], 'paginationInfo' => ['itemsPerPage' => .0]], ['paginationInfo' => ['itemsPerPage' => true]]]; + yield 'page - empty paginator - lastPage requested' => [new ArrayPaginator([], 0, 0), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [], 'paginationInfo' => ['lastPage' => 1.0]], ['paginationInfo' => ['lastPage' => true]]]; + yield 'page - empty paginator - totalCount requested' => [new ArrayPaginator([], 0, 0), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [], 'paginationInfo' => ['totalCount' => .0]], ['paginationInfo' => ['totalCount' => true]]]; + yield 'page - empty paginator - hasNextPage requested' => [new ArrayPaginator([], 0, 0), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [], 'paginationInfo' => ['hasNextPage' => false]], ['paginationInfo' => ['hasNextPage' => true]]]; + yield 'page - paginator page 1 - itemsPerPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [['normalized_item'], ['normalized_item']], 'paginationInfo' => ['itemsPerPage' => 2.0]], ['paginationInfo' => ['itemsPerPage' => true]]]; + yield 'page - paginator page 1 - lastPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [['normalized_item'], ['normalized_item']], 'paginationInfo' => ['lastPage' => 2.0]], ['paginationInfo' => ['lastPage' => true]]]; + yield 'page - paginator page 1 - totalCount requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [['normalized_item'], ['normalized_item']], 'paginationInfo' => ['totalCount' => 3.0]], ['paginationInfo' => ['totalCount' => true]]]; + yield 'page - paginator page 1 - hasNextPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 0, 2), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [['normalized_item'], ['normalized_item']], 'paginationInfo' => ['hasNextPage' => true]], ['paginationInfo' => ['hasNextPage' => true]]]; + yield 'page - paginator with page - itemsPerPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 2, 2), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [['normalized_item']], 'paginationInfo' => ['itemsPerPage' => 2.0]], ['paginationInfo' => ['itemsPerPage' => true]]]; + yield 'page - paginator with page - lastPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 2, 2), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [['normalized_item']], 'paginationInfo' => ['lastPage' => 2.0]], ['paginationInfo' => ['lastPage' => true]]]; + yield 'page - paginator with page - totalCount requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 2, 2), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [['normalized_item']], 'paginationInfo' => ['totalCount' => 3.0]], ['paginationInfo' => ['totalCount' => true]]]; + yield 'page - paginator with page - hasNextPage requested' => [new ArrayPaginator([(object) ['test' => 'a'], (object) ['test' => 'b'], (object) ['test' => 'c']], 2, 2), (new QueryCollection(class: \stdClass::class))->withPaginationType('page'), [], ['collection' => [['normalized_item']], 'paginationInfo' => ['hasNextPage' => false]], ['paginationInfo' => ['hasNextPage' => true]]]; } } diff --git a/src/GraphQl/Tests/State/Provider/DenormalizeProviderTest.php b/src/GraphQl/Tests/State/Provider/DenormalizeProviderTest.php index ec802d5152a..b1232566245 100644 --- a/src/GraphQl/Tests/State/Provider/DenormalizeProviderTest.php +++ b/src/GraphQl/Tests/State/Provider/DenormalizeProviderTest.php @@ -27,14 +27,14 @@ public function testProvide(): void { $objectToPopulate = null; $context = ['args' => ['input' => ['test']]]; - $operation = new Mutation(class: 'dummy'); + $operation = new Mutation(class: \stdClass::class); $serializerContext = ['resource_class' => $operation->getClass()]; $decorated = $this->createMock(ProviderInterface::class); $decorated->expects($this->once())->method('provide')->willReturn($objectToPopulate); $denormalizer = $this->createMock(DenormalizerInterface::class); $serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class); $serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, false)->willReturn($serializerContext); - $denormalizer->expects($this->once())->method('denormalize')->with(['test'], 'dummy', 'graphql', $serializerContext)->willReturn(new \stdClass()); + $denormalizer->expects($this->once())->method('denormalize')->with(['test'], \stdClass::class, 'graphql', $serializerContext)->willReturn(new \stdClass()); $provider = new DenormalizeProvider($decorated, $denormalizer, $serializerContextBuilder); $provider->provide($operation, [], $context); } @@ -43,14 +43,14 @@ public function testProvideWithObjectToPopulate(): void { $objectToPopulate = new \stdClass(); $context = ['args' => ['input' => ['test']]]; - $operation = new Mutation(class: 'dummy'); + $operation = new Mutation(class: \stdClass::class); $serializerContext = ['resource_class' => $operation->getClass(), 'object_to_populate' => $objectToPopulate]; $decorated = $this->createMock(ProviderInterface::class); $decorated->expects($this->once())->method('provide')->willReturn($objectToPopulate); $denormalizer = $this->createMock(DenormalizerInterface::class); $serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class); $serializerContextBuilder->expects($this->once())->method('create')->with($operation->getClass(), $operation, $context, false)->willReturn($serializerContext); - $denormalizer->expects($this->once())->method('denormalize')->with(['test'], 'dummy', 'graphql', $serializerContext)->willReturn(new \stdClass()); + $denormalizer->expects($this->once())->method('denormalize')->with(['test'], \stdClass::class, 'graphql', $serializerContext)->willReturn(new \stdClass()); $provider = new DenormalizeProvider($decorated, $denormalizer, $serializerContextBuilder); $provider->provide($operation, [], $context); } @@ -59,14 +59,14 @@ public function testProvideNotCalledWithQuery(): void { $objectToPopulate = new \stdClass(); $context = ['args' => ['input' => ['test']]]; - $operation = new Query(class: 'dummy'); + $operation = new Query(class: \stdClass::class); $serializerContext = ['resource_class' => $operation->getClass()]; $decorated = $this->createMock(ProviderInterface::class); $decorated->expects($this->once())->method('provide')->willReturn($objectToPopulate); $denormalizer = $this->createMock(DenormalizerInterface::class); $serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class); $serializerContextBuilder->expects($this->never())->method('create')->with($operation->getClass(), $operation, $context, false)->willReturn($serializerContext); - $denormalizer->expects($this->never())->method('denormalize')->with(['test'], 'dummy', 'graphql', $serializerContext)->willReturn(new \stdClass()); + $denormalizer->expects($this->never())->method('denormalize')->with(['test'], \stdClass::class, 'graphql', $serializerContext)->willReturn(new \stdClass()); $provider = new DenormalizeProvider($decorated, $denormalizer, $serializerContextBuilder); $provider->provide($operation, [], $context); } @@ -75,14 +75,14 @@ public function testProvideNotCalledWithoutDeserialize(): void { $objectToPopulate = new \stdClass(); $context = ['args' => ['input' => ['test']]]; - $operation = new Query(class: 'dummy', deserialize: false); + $operation = new Query(class: \stdClass::class, deserialize: false); $serializerContext = ['resource_class' => $operation->getClass()]; $decorated = $this->createMock(ProviderInterface::class); $decorated->expects($this->once())->method('provide')->willReturn($objectToPopulate); $denormalizer = $this->createMock(DenormalizerInterface::class); $serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class); $serializerContextBuilder->expects($this->never())->method('create')->with($operation->getClass(), $operation, $context, false)->willReturn($serializerContext); - $denormalizer->expects($this->never())->method('denormalize')->with(['test'], 'dummy', 'graphql', $serializerContext)->willReturn(new \stdClass()); + $denormalizer->expects($this->never())->method('denormalize')->with(['test'], \stdClass::class, 'graphql', $serializerContext)->willReturn(new \stdClass()); $provider = new DenormalizeProvider($decorated, $denormalizer, $serializerContextBuilder); $provider->provide($operation, [], $context); } diff --git a/src/GraphQl/Tests/State/Provider/ReadProviderTest.php b/src/GraphQl/Tests/State/Provider/ReadProviderTest.php index 322cc41bfe4..871cb144f7b 100644 --- a/src/GraphQl/Tests/State/Provider/ReadProviderTest.php +++ b/src/GraphQl/Tests/State/Provider/ReadProviderTest.php @@ -28,7 +28,7 @@ class ReadProviderTest extends TestCase public function testProvide(): void { $context = ['args' => ['id' => '/dummy/1']]; - $operation = new Query(class: 'dummy'); + $operation = new Query(class: \stdClass::class); $decorated = $this->createMock(ProviderInterface::class); $iriConverter = $this->createMock(IriConverterInterface::class); $iriConverter->expects($this->once())->method('getResourceFromIri')->with('/dummy/1'); @@ -45,7 +45,7 @@ public function testProvide(): void public function testProvideNotExistedResource(): void { $context = ['args' => ['id' => '/dummy/1']]; - $operation = new Query(class: 'dummy'); + $operation = new Query(class: \stdClass::class); $decorated = $this->createMock(ProviderInterface::class); $iriConverter = $this->createMock(IriConverterInterface::class); $iriConverter->expects($this->once())->method('getResourceFromIri')->with('/dummy/1'); @@ -61,8 +61,8 @@ public function testProvideCollection(): void { $info = $this->createMock(ResolveInfo::class); $info->fieldName = ''; - $context = ['root_class' => 'dummy', 'source' => [], 'info' => $info, 'filters' => []]; - $operation = new QueryCollection(class: 'dummy'); + $context = ['root_class' => \stdClass::class, 'source' => [], 'info' => $info, 'filters' => []]; + $operation = new QueryCollection(class: \stdClass::class); $decorated = $this->createMock(ProviderInterface::class); $decorated->expects($this->once())->method('provide')->with($operation, [], ['a'] + $context); $iriConverter = $this->createMock(IriConverterInterface::class); diff --git a/src/GraphQl/Tests/State/Provider/ResolverProviderTest.php b/src/GraphQl/Tests/State/Provider/ResolverProviderTest.php index 64d9e9b8220..08f32d4f75a 100644 --- a/src/GraphQl/Tests/State/Provider/ResolverProviderTest.php +++ b/src/GraphQl/Tests/State/Provider/ResolverProviderTest.php @@ -28,7 +28,7 @@ class ResolverProviderTest extends TestCase public function testProvide(): void { $res = new \stdClass(); - $operation = new QueryCollection(class: 'dummy', resolver: 'foo'); + $operation = new QueryCollection(class: \stdClass::class, resolver: 'foo'); $context = []; $decorated = $this->createMock(ProviderInterface::class); $resolverMock = $this->createMock(QueryItemResolverInterface::class); diff --git a/src/GraphQl/Tests/Type/FieldsBuilderTest.php b/src/GraphQl/Tests/Type/FieldsBuilderTest.php index 9f7053b0688..dc95924e9af 100644 --- a/src/GraphQl/Tests/Type/FieldsBuilderTest.php +++ b/src/GraphQl/Tests/Type/FieldsBuilderTest.php @@ -129,10 +129,10 @@ public function testGetItemQueryFields(string $resourceClass, Operation $operati public static function itemQueryFieldsProvider(): array { return [ - 'no resource field configuration' => ['resourceClass', (new Query())->withClass('resourceClass')->withName('action'), [], null, null, []], - 'nested item query' => ['resourceClass', (new Query())->withNested(true)->withClass('resourceClass')->withName('action')->withShortName('ShortName'), [], new ObjectType(['name' => 'item', 'fields' => []]), function (): void { + 'no resource field configuration' => [\stdClass::class, (new Query())->withClass(\stdClass::class)->withName('action'), [], null, null, []], + 'nested item query' => [\stdClass::class, (new Query())->withNested(true)->withClass(\stdClass::class)->withName('action')->withShortName('ShortName'), [], new ObjectType(['name' => 'item', 'fields' => []]), function (): void { }, []], - 'nominal standard type case with deprecation reason and description' => ['resourceClass', (new Query())->withClass('resourceClass')->withName('action')->withShortName('ShortName')->withDeprecationReason('not useful')->withDescription('Custom description.'), [], GraphQLType::string(), null, + 'nominal standard type case with deprecation reason and description' => [\stdClass::class, (new Query())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName')->withDeprecationReason('not useful')->withDescription('Custom description.'), [], GraphQLType::string(), null, [ 'actionShortName' => [ 'type' => GraphQLType::string(), @@ -145,7 +145,7 @@ public static function itemQueryFieldsProvider(): array ], ], ], - 'nominal item case' => ['resourceClass', (new Query())->withClass('resourceClass')->withName('action')->withShortName('ShortName'), [], $graphqlType = new ObjectType(['name' => 'item', 'fields' => []]), $resolver = function (): void { + 'nominal item case' => [\stdClass::class, (new Query())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName'), [], $graphqlType = new ObjectType(['name' => 'item', 'fields' => []]), $resolver = function (): void { }, [ 'actionShortName' => [ @@ -160,7 +160,7 @@ public static function itemQueryFieldsProvider(): array ], ], 'empty overridden args and add fields' => [ - 'resourceClass', (new Query())->withClass('resourceClass')->withShortName('ShortName'), ['args' => [], 'name' => 'customActionName'], GraphQLType::string(), null, + \stdClass::class, (new Query())->withClass(\stdClass::class)->withShortName('ShortName'), ['args' => [], 'name' => 'customActionName'], GraphQLType::string(), null, [ 'shortName' => [ 'type' => GraphQLType::string(), @@ -173,7 +173,7 @@ public static function itemQueryFieldsProvider(): array ], ], 'override args with custom ones' => [ - 'resourceClass', (new Query())->withClass('resourceClass')->withShortName('ShortName'), ['args' => ['customArg' => ['type' => 'a type']]], GraphQLType::string(), null, + \stdClass::class, (new Query())->withClass(\stdClass::class)->withShortName('ShortName'), ['args' => ['customArg' => ['type' => 'a type']]], GraphQLType::string(), null, [ 'shortName' => [ 'type' => GraphQLType::string(), @@ -221,10 +221,10 @@ public function testGetCollectionQueryFields(string $resourceClass, Operation $o public static function collectionQueryFieldsProvider(): array { return [ - 'no resource field configuration' => ['resourceClass', (new QueryCollection())->withClass('resourceClass')->withName('action'), [], null, null, []], - 'nested collection query' => ['resourceClass', (new QueryCollection())->withNested(true)->withClass('resourceClass')->withName('action')->withShortName('ShortName'), [], GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), function (): void { + 'no resource field configuration' => [\stdClass::class, (new QueryCollection())->withClass(\stdClass::class)->withName('action'), [], null, null, []], + 'nested collection query' => [\stdClass::class, (new QueryCollection())->withNested(true)->withClass(\stdClass::class)->withName('action')->withShortName('ShortName'), [], GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), function (): void { }, []], - 'nominal collection case with deprecation reason and description' => ['resourceClass', (new QueryCollection())->withClass('resourceClass')->withName('action')->withShortName('ShortName')->withDeprecationReason('not useful')->withDescription('Custom description.'), [], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { + 'nominal collection case with deprecation reason and description' => [\stdClass::class, (new QueryCollection())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName')->withDeprecationReason('not useful')->withDescription('Custom description.'), [], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { }, [ 'actionShortNames' => [ @@ -253,7 +253,7 @@ public static function collectionQueryFieldsProvider(): array ], ], ], - 'collection with filters' => ['resourceClass', (new QueryCollection())->withClass('resourceClass')->withName('action')->withShortName('ShortName')->withFilters(['my_filter']), [], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { + 'collection with filters' => [\stdClass::class, (new QueryCollection())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName')->withFilters(['my_filter']), [], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { }, [ 'actionShortNames' => [ @@ -287,7 +287,7 @@ public static function collectionQueryFieldsProvider(): array ], ], 'collection empty overridden args and add fields' => [ - 'resourceClass', (new QueryCollection())->withArgs([])->withClass('resourceClass')->withName('action')->withShortName('ShortName'), ['args' => [], 'name' => 'customActionName'], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { + \stdClass::class, (new QueryCollection())->withArgs([])->withClass(\stdClass::class)->withName('action')->withShortName('ShortName'), ['args' => [], 'name' => 'customActionName'], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { }, [ 'actionShortNames' => [ @@ -301,7 +301,7 @@ public static function collectionQueryFieldsProvider(): array ], ], 'collection override args with custom ones' => [ - 'resourceClass', (new QueryCollection())->withClass('resourceClass')->withName('action')->withShortName('ShortName'), ['args' => ['customArg' => ['type' => 'a type']]], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { + \stdClass::class, (new QueryCollection())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName'), ['args' => ['customArg' => ['type' => 'a type']]], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { }, [ 'actionShortNames' => [ @@ -317,7 +317,7 @@ public static function collectionQueryFieldsProvider(): array ], ], ], - 'collection with page-based pagination enabled' => ['resourceClass', (new QueryCollection())->withClass('resourceClass')->withName('action')->withShortName('ShortName')->withPaginationType('page')->withFilters(['my_filter']), [], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { + 'collection with page-based pagination enabled' => [\stdClass::class, (new QueryCollection())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName')->withPaginationType('page')->withFilters(['my_filter']), [], $graphqlType = GraphQLType::listOf(new ObjectType(['name' => 'collection', 'fields' => []])), $resolver = function (): void { }, [ 'actionShortNames' => [ @@ -357,7 +357,7 @@ public function testGetMutationFields(string $resourceClass, Operation $operatio public static function mutationFieldsProvider(): array { return [ - 'nominal case with deprecation reason' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('action')->withShortName('ShortName')->withDeprecationReason('not useful'), $graphqlType = new ObjectType(['name' => 'mutation', 'fields' => []]), $inputGraphqlType = new ObjectType(['name' => 'input', 'fields' => []]), $mutationResolver = function (): void { + 'nominal case with deprecation reason' => [\stdClass::class, (new Mutation())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName')->withDeprecationReason('not useful'), $graphqlType = new ObjectType(['name' => 'mutation', 'fields' => []]), $inputGraphqlType = new ObjectType(['name' => 'input', 'fields' => []]), $mutationResolver = function (): void { }, [ 'actionShortName' => [ @@ -377,7 +377,7 @@ public static function mutationFieldsProvider(): array ], ], ], - 'custom description' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('action')->withShortName('ShortName')->withDescription('Custom description.'), $graphqlType = new ObjectType(['name' => 'mutation', 'fields' => []]), $inputGraphqlType = new ObjectType(['name' => 'input', 'fields' => []]), $mutationResolver = function (): void { + 'custom description' => [\stdClass::class, (new Mutation())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName')->withDescription('Custom description.'), $graphqlType = new ObjectType(['name' => 'mutation', 'fields' => []]), $inputGraphqlType = new ObjectType(['name' => 'input', 'fields' => []]), $mutationResolver = function (): void { }, [ 'actionShortName' => [ @@ -417,9 +417,9 @@ public function testGetSubscriptionFields(string $resourceClass, Operation $oper public static function subscriptionFieldsProvider(): array { return [ - 'mercure not enabled' => ['resourceClass', (new Subscription())->withClass('resourceClass')->withName('action')->withShortName('ShortName'), new ObjectType(['name' => 'subscription', 'fields' => []]), new ObjectType(['name' => 'input', 'fields' => []]), null, [], + 'mercure not enabled' => [\stdClass::class, (new Subscription())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName'), new ObjectType(['name' => 'subscription', 'fields' => []]), new ObjectType(['name' => 'input', 'fields' => []]), null, [], ], - 'nominal case with deprecation reason' => ['resourceClass', (new Subscription())->withClass('resourceClass')->withName('action')->withShortName('ShortName')->withMercure(true)->withDeprecationReason('not useful'), $graphqlType = new ObjectType(['name' => 'subscription', 'fields' => []]), $inputGraphqlType = new ObjectType(['name' => 'input', 'fields' => []]), $subscriptionResolver = function (): void { + 'nominal case with deprecation reason' => [\stdClass::class, (new Subscription())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName')->withMercure(true)->withDeprecationReason('not useful'), $graphqlType = new ObjectType(['name' => 'subscription', 'fields' => []]), $inputGraphqlType = new ObjectType(['name' => 'input', 'fields' => []]), $subscriptionResolver = function (): void { }, [ 'actionShortNameSubscribe' => [ @@ -439,7 +439,7 @@ public static function subscriptionFieldsProvider(): array ], ], ], - 'custom description' => ['resourceClass', (new Subscription())->withClass('resourceClass')->withName('action')->withShortName('ShortName')->withMercure(true)->withDescription('Custom description.'), $graphqlType = new ObjectType(['name' => 'subscription', 'fields' => []]), $inputGraphqlType = new ObjectType(['name' => 'input', 'fields' => []]), $subscriptionResolver = function (): void { + 'custom description' => [\stdClass::class, (new Subscription())->withClass(\stdClass::class)->withName('action')->withShortName('ShortName')->withMercure(true)->withDescription('Custom description.'), $graphqlType = new ObjectType(['name' => 'subscription', 'fields' => []]), $inputGraphqlType = new ObjectType(['name' => 'input', 'fields' => []]), $subscriptionResolver = function (): void { }, [ 'actionShortNameSubscribe' => [ @@ -506,12 +506,12 @@ public static function resourceObjectTypeFieldsProvider(): iterable { $advancedNameConverterFactory = function (self $that): AdvancedNameConverterInterface { $advancedNameConverterProphecy = $that->prophesize(AdvancedNameConverterInterface::class); - $advancedNameConverterProphecy->normalize('field', 'resourceClass')->willReturn('normalizedField'); + $advancedNameConverterProphecy->normalize('field', \stdClass::class)->willReturn('normalizedField'); return $advancedNameConverterProphecy->reveal(); }; - yield 'query' => ['resourceClass', (new Query())->withClass('resourceClass'), + yield 'query' => [\stdClass::class, (new Query())->withClass(\stdClass::class), [ 'property' => new ApiProperty(), 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(true)->withWritable(false), @@ -539,7 +539,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable ], ], ]; - yield 'query with advanced name converter' => ['resourceClass', (new Query())->withClass('resourceClass'), + yield 'query with advanced name converter' => [\stdClass::class, (new Query())->withClass(\stdClass::class), [ 'field' => (new ApiProperty())->withNativeType(Type::string())->withReadable(true)->withWritable(false), ], @@ -558,7 +558,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable ], $advancedNameConverterFactory, ]; - yield 'query input' => ['resourceClass', (new Query())->withClass('resourceClass'), + yield 'query input' => [\stdClass::class, (new Query())->withClass(\stdClass::class), [ 'property' => new ApiProperty(), 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), @@ -578,7 +578,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable ], ], ]; - yield 'query with simple non-null string array property' => ['resourceClass', (new Query())->withClass('resourceClass'), + yield 'query with simple non-null string array property' => [\stdClass::class, (new Query())->withClass(\stdClass::class), [ 'property' => (new ApiProperty())->withNativeType(Type::list(Type::string()))->withReadable(true)->withWritable(false), ], @@ -596,7 +596,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable ], ], ]; - yield 'query with nested resources' => ['resourceClass', (new Query())->withClass('resourceClass'), + yield 'query with nested resources' => [\stdClass::class, (new Query())->withClass(\stdClass::class), [ 'propertyNestedResource' => (new ApiProperty())->withNativeType(Type::object('nestedResourceClass'))->withReadable(true)->withWritable(true), ], @@ -615,7 +615,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable ], ], ]; - yield 'mutation non input' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('mutation'), + yield 'mutation non input' => [\stdClass::class, (new Mutation())->withClass(\stdClass::class)->withName('mutation'), [ 'property' => new ApiProperty(), 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), @@ -644,7 +644,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable ], ], ]; - yield 'mutation input' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('mutation'), + yield 'mutation input' => [\stdClass::class, (new Mutation())->withClass(\stdClass::class)->withName('mutation'), [ 'property' => new ApiProperty(), 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withDescription('propertyBool description')->withReadable(false)->withWritable(true)->withDeprecationReason('not useful'), @@ -681,7 +681,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable 'clientMutationId' => GraphQLType::string(), ], ]; - yield 'custom mutation' => ['resourceClass', (new Mutation())->withResolver('resolver')->withName('mutation'), + yield 'custom mutation' => [\stdClass::class, (new Mutation())->withResolver('resolver')->withName('mutation'), [ 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withDescription('propertyBool description')->withReadable(false)->withWritable(true), ], @@ -697,7 +697,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable 'clientMutationId' => GraphQLType::string(), ], ]; - yield 'mutation nested input' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('mutation'), + yield 'mutation nested input' => [\stdClass::class, (new Mutation())->withClass(\stdClass::class)->withName('mutation'), [ 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), ], @@ -716,7 +716,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable 'clientMutationId' => GraphQLType::string(), ], ]; - yield 'delete mutation input' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('delete'), + yield 'delete mutation input' => [\stdClass::class, (new Mutation())->withClass(\stdClass::class)->withName('delete'), [ 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), ], @@ -728,7 +728,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable 'clientMutationId' => GraphQLType::string(), ], ]; - yield 'create mutation input' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('create'), + yield 'create mutation input' => [\stdClass::class, (new Mutation())->withClass(\stdClass::class)->withName('create'), [ 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), ], @@ -744,7 +744,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable 'clientMutationId' => GraphQLType::string(), ], ]; - yield 'update mutation input' => ['resourceClass', (new Mutation())->withClass('resourceClass')->withName('update'), + yield 'update mutation input' => [\stdClass::class, (new Mutation())->withClass(\stdClass::class)->withName('update'), [ 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), ], @@ -763,7 +763,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable 'clientMutationId' => GraphQLType::string(), ], ]; - yield 'subscription non input' => ['resourceClass', (new Subscription())->withClass('resourceClass'), + yield 'subscription non input' => [\stdClass::class, (new Subscription())->withClass(\stdClass::class), [ 'property' => new ApiProperty(), 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), @@ -783,7 +783,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable ], ], ]; - yield 'subscription input' => ['resourceClass', (new Subscription())->withClass('resourceClass'), + yield 'subscription input' => [\stdClass::class, (new Subscription())->withClass(\stdClass::class), [ 'property' => new ApiProperty(), 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withDescription('propertyBool description')->withReadable(false)->withWritable(true)->withDeprecationReason('not useful'), @@ -798,13 +798,13 @@ public static function resourceObjectTypeFieldsProvider(): iterable 'clientSubscriptionId' => GraphQLType::string(), ], ]; - yield 'null io metadata non input' => ['resourceClass', (new Query())->withClass('resourceClass'), + yield 'null io metadata non input' => [\stdClass::class, (new Query())->withClass(\stdClass::class), [ 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), ], false, 0, ['class' => null], [], ]; - yield 'null io metadata input' => ['resourceClass', (new Query())->withClass('resourceClass'), + yield 'null io metadata input' => [\stdClass::class, (new Query())->withClass(\stdClass::class), [ 'propertyBool' => (new ApiProperty())->withNativeType(Type::bool())->withReadable(false)->withWritable(true), ], @@ -813,7 +813,7 @@ public static function resourceObjectTypeFieldsProvider(): iterable 'clientMutationId' => GraphQLType::string(), ], ]; - yield 'invalid types' => ['resourceClass', (new Query())->withClass('resourceClass'), + yield 'invalid types' => [\stdClass::class, (new Query())->withClass(\stdClass::class), [ 'propertyInvalidType' => (new ApiProperty())->withNativeType(Type::null())->withReadable(true)->withWritable(false), 'propertyNotRegisteredType' => (new ApiProperty())->withNativeType(Type::callable())->withReadable(true)->withWritable(false), diff --git a/src/GraphQl/Tests/Type/TypeBuilderTest.php b/src/GraphQl/Tests/Type/TypeBuilderTest.php index 2bfc54760c5..2c6dbe5ad3b 100644 --- a/src/GraphQl/Tests/Type/TypeBuilderTest.php +++ b/src/GraphQl/Tests/Type/TypeBuilderTest.php @@ -78,7 +78,7 @@ protected function setUp(): void public function testGetResourceObjectType(): void { - $resourceMetadataCollection = new ResourceMetadataCollection('resourceClass', [ + $resourceMetadataCollection = new ResourceMetadataCollection(\stdClass::class, [ (new ApiResource())->withGraphQlOperations(['collection_query' => new QueryCollection()]), ]); $this->typesContainerProphecy->has('shortName')->shouldBeCalled()->willReturn(false); @@ -86,7 +86,7 @@ public function testGetResourceObjectType(): void $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Query())->withShortName('shortName')->withDescription('description')->withClass('resourceClass'); + $operation = (new Query())->withShortName('shortName')->withDescription('description')->withClass(\stdClass::class); /** @var ObjectType $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadataCollection, $operation, null, ['input' => false]); $this->assertSame('shortName', $resourceObjectType->name); @@ -96,14 +96,14 @@ public function testGetResourceObjectType(): void $this->assertArrayHasKey('fields', $resourceObjectType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, false, 0, null)->shouldBeCalled(); + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, false, 0, null)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); $resourceObjectType->config['fields'](); } public function testGetResourceObjectTypeOutputClass(): void { - $resourceMetadataCollection = new ResourceMetadataCollection('resourceClass', [ + $resourceMetadataCollection = new ResourceMetadataCollection(\stdClass::class, [ (new ApiResource())->withGraphQlOperations(['collection_query' => new QueryCollection()]), ]); $this->typesContainerProphecy->has('shortName')->shouldBeCalled()->willReturn(false); @@ -129,7 +129,7 @@ public function testGetResourceObjectTypeOutputClass(): void #[DataProvider('resourceObjectTypeQuerySerializationGroupsProvider')] public function testGetResourceObjectTypeQuerySerializationGroups(string $itemSerializationGroup, string $collectionSerializationGroup, Operation $operation, string $shortName): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', [(new ApiResource())->withGraphQlOperations([ + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, [(new ApiResource())->withGraphQlOperations([ 'item_query' => (new Query())->withShortName('shortName')->withNormalizationContext(['groups' => [$itemSerializationGroup]]), 'collection_query' => (new QueryCollection())->withShortName('shortName')->withNormalizationContext(['groups' => [$collectionSerializationGroup]]), ])]); @@ -169,13 +169,13 @@ public static function resourceObjectTypeQuerySerializationGroupsProvider(): arr public function testGetResourceObjectTypeInput(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', []); + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, []); $this->typesContainerProphecy->has('customShortNameInput')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('customShortNameInput', Argument::type(InputObjectType::class))->shouldBeCalled(); $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Mutation())->withName('custom')->withShortName('shortName')->withDescription('description')->withClass('resourceClass'); + $operation = (new Mutation())->withName('custom')->withShortName('shortName')->withDescription('description')->withClass(\stdClass::class); /** @var NonNull $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => true]); /** @var InputObjectType $wrappedType */ @@ -186,20 +186,20 @@ public function testGetResourceObjectTypeInput(): void $this->assertArrayHasKey('fields', $wrappedType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, true, 0, null)->shouldBeCalled(); + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, true, 0, null)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); $wrappedType->config['fields'](); } public function testGetResourceObjectTypeNestedInput(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', []); + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, []); $this->typesContainerProphecy->has('customShortNameNestedInput')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('customShortNameNestedInput', Argument::type(InputObjectType::class))->shouldBeCalled(); $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Mutation())->withName('custom')->withShortName('shortName')->withDescription('description')->withClass('resourceClass'); + $operation = (new Mutation())->withName('custom')->withShortName('shortName')->withDescription('description')->withClass(\stdClass::class); /** @var NonNull $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => true, 'wrapped' => false, 'depth' => 1]); /** @var InputObjectType $wrappedType */ @@ -210,20 +210,20 @@ public function testGetResourceObjectTypeNestedInput(): void $this->assertArrayHasKey('fields', $wrappedType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, true, 1, null)->shouldBeCalled(); + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, true, 1, null)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); $wrappedType->config['fields'](); } public function testGetResourceObjectTypeNestedInputNullable(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', []); + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, []); $this->typesContainerProphecy->has('customShortNameNullableNestedInput')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('customShortNameNullableNestedInput', Argument::type(InputObjectType::class))->shouldBeCalled(); $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Mutation())->withName('custom')->withShortName('shortNameNullable')->withDescription('description nullable')->withClass('resourceClass'); + $operation = (new Mutation())->withName('custom')->withShortName('shortNameNullable')->withDescription('description nullable')->withClass(\stdClass::class); $propertyMetadata = (new ApiProperty())->withRequired(false); /** @var InputObjectType $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, $propertyMetadata, [ @@ -238,20 +238,20 @@ public function testGetResourceObjectTypeNestedInputNullable(): void $this->assertArrayHasKey('fields', $resourceObjectType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, true, 1, null)->shouldBeCalled(); + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, true, 1, null)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); $resourceObjectType->config['fields'](); } public function testGetResourceObjectTypeCustomMutationInputArgs(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', []); + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, []); $this->typesContainerProphecy->has('customShortNameInput')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('customShortNameInput', Argument::type(InputObjectType::class))->shouldBeCalled(); $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Mutation())->withArgs([])->withName('custom')->withShortName('shortName')->withDescription('description')->withClass('resourceClass'); + $operation = (new Mutation())->withArgs([])->withName('custom')->withShortName('shortName')->withDescription('description')->withClass(\stdClass::class); /** @var NonNull $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => true]); /** @var InputObjectType $wrappedType */ @@ -262,7 +262,7 @@ public function testGetResourceObjectTypeCustomMutationInputArgs(): void $this->assertArrayHasKey('fields', $wrappedType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, true, 0, null) + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, true, 0, null) ->shouldBeCalled()->willReturn(['clientMutationId' => GraphQLType::string()]); $fieldsBuilderProphecy->resolveResourceArgs([], $operation)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); @@ -271,7 +271,7 @@ public function testGetResourceObjectTypeCustomMutationInputArgs(): void public function testGetResourceObjectTypeMutation(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', [(new ApiResource())->withGraphQlOperations([ + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, [(new ApiResource())->withGraphQlOperations([ 'create' => (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description'), 'item_query' => (new Query())->withShortName('shortName')->withDescription('description'), 'collection_query' => new QueryCollection(), @@ -281,7 +281,7 @@ public function testGetResourceObjectTypeMutation(): void $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withClass('resourceClass'); + $operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withClass(\stdClass::class); /** @var ObjectType $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]); $this->assertSame('createShortNamePayload', $resourceObjectType->name); @@ -303,16 +303,16 @@ public function testGetResourceObjectTypeMutation(): void public function testGetResourceObjectTypeMutationWrappedType(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', [(new ApiResource())->withGraphQlOperations([ - 'item_query' => (new Query())->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['item_query']])->withClass('resourceClass'), - 'create' => (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['create']])->withClass('resourceClass'), + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, [(new ApiResource())->withGraphQlOperations([ + 'item_query' => (new Query())->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['item_query']])->withClass(\stdClass::class), + 'create' => (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['create']])->withClass(\stdClass::class), ])]); $this->typesContainerProphecy->has('createShortNamePayload')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('createShortNamePayload', Argument::type(ObjectType::class))->shouldBeCalled(); $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['create']])->withClass('resourceClass'); + $operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['create']])->withClass(\stdClass::class); /** @var ObjectType $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]); $this->assertSame('createShortNamePayload', $resourceObjectType->name); @@ -340,20 +340,20 @@ public function testGetResourceObjectTypeMutationWrappedType(): void $this->assertArrayHasKey('fields', $wrappedType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, false, 0, null)->shouldBeCalled(); + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, false, 0, null)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); $wrappedType->config['fields'](); } public function testGetResourceObjectTypeMutationNested(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', []); + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, []); $this->typesContainerProphecy->has('createShortNameNestedPayload')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('createShortNameNestedPayload', Argument::type(ObjectType::class))->shouldBeCalled(); $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withClass('resourceClass'); + $operation = (new Mutation())->withName('create')->withShortName('shortName')->withDescription('description')->withClass(\stdClass::class); /** @var ObjectType $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false, 'wrapped' => false, 'depth' => 1]); $this->assertSame('createShortNameNestedPayload', $resourceObjectType->name); @@ -363,14 +363,14 @@ public function testGetResourceObjectTypeMutationNested(): void $this->assertArrayHasKey('fields', $resourceObjectType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, false, 1, null)->shouldBeCalled(); + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, false, 1, null)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); $resourceObjectType->config['fields'](); } public function testGetResourceObjectTypeSubscription(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', [(new ApiResource())->withGraphQlOperations([ + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, [(new ApiResource())->withGraphQlOperations([ 'update' => (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withMercure(true), 'item_query' => (new Query())->withShortName('shortName')->withDescription('description'), 'collection_query' => new QueryCollection(), @@ -380,7 +380,7 @@ public function testGetResourceObjectTypeSubscription(): void $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withMercure(true)->withClass('resourceClass'); + $operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withMercure(true)->withClass(\stdClass::class); /** @var ObjectType $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]); $this->assertSame('updateShortNameSubscriptionPayload', $resourceObjectType->name); @@ -404,16 +404,16 @@ public function testGetResourceObjectTypeSubscription(): void public function testGetResourceObjectTypeSubscriptionWrappedType(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', [(new ApiResource())->withGraphQlOperations([ - 'item_query' => (new Query())->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['item_query']])->withClass('resourceClass'), - 'update' => (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['update']])->withClass('resourceClass'), + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, [(new ApiResource())->withGraphQlOperations([ + 'item_query' => (new Query())->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['item_query']])->withClass(\stdClass::class), + 'update' => (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['update']])->withClass(\stdClass::class), ])]); $this->typesContainerProphecy->has('updateShortNameSubscriptionPayload')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('updateShortNameSubscriptionPayload', Argument::type(ObjectType::class))->shouldBeCalled(); $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['update']])->withClass('resourceClass'); + $operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withNormalizationContext(['groups' => ['update']])->withClass(\stdClass::class); /** @var ObjectType $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false]); $this->assertSame('updateShortNameSubscriptionPayload', $resourceObjectType->name); @@ -442,20 +442,20 @@ public function testGetResourceObjectTypeSubscriptionWrappedType(): void $this->assertArrayHasKey('fields', $wrappedType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, false, 0, null)->shouldBeCalled(); + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, false, 0, null)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); $wrappedType->config['fields'](); } public function testGetResourceObjectTypeSubscriptionNested(): void { - $resourceMetadata = new ResourceMetadataCollection('resourceClass', [(new ApiResource())->withGraphQlOperations([])]); + $resourceMetadata = new ResourceMetadataCollection(\stdClass::class, [(new ApiResource())->withGraphQlOperations([])]); $this->typesContainerProphecy->has('updateShortNameSubscriptionNestedPayload')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('updateShortNameSubscriptionNestedPayload', Argument::type(ObjectType::class))->shouldBeCalled(); $this->typesContainerProphecy->has('Node')->shouldBeCalled()->willReturn(false); $this->typesContainerProphecy->set('Node', Argument::type(InterfaceType::class))->shouldBeCalled(); - $operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withMercure(true)->withClass('resourceClass'); + $operation = (new Subscription())->withName('update')->withShortName('shortName')->withDescription('description')->withMercure(true)->withClass(\stdClass::class); /** @var ObjectType $resourceObjectType */ $resourceObjectType = $this->typeBuilder->getResourceObjectType($resourceMetadata, $operation, null, ['input' => false, 'wrapped' => false, 'depth' => 1]); $this->assertSame('updateShortNameSubscriptionNestedPayload', $resourceObjectType->name); @@ -465,7 +465,7 @@ public function testGetResourceObjectTypeSubscriptionNested(): void $this->assertArrayHasKey('fields', $resourceObjectType->config); $fieldsBuilderProphecy = $this->prophesize(FieldsBuilderEnumInterface::class); - $fieldsBuilderProphecy->getResourceObjectTypeFields('resourceClass', $operation, false, 1, null)->shouldBeCalled(); + $fieldsBuilderProphecy->getResourceObjectTypeFields(\stdClass::class, $operation, false, 1, null)->shouldBeCalled(); $this->fieldsBuilderLocatorProphecy->get('api_platform.graphql.fields_builder')->shouldBeCalled()->willReturn($fieldsBuilderProphecy->reveal()); $resourceObjectType->config['fields'](); } diff --git a/src/HttpCache/Tests/State/AddTagsProcessorTest.php b/src/HttpCache/Tests/State/AddTagsProcessorTest.php index 4413bda2570..210258e7622 100644 --- a/src/HttpCache/Tests/State/AddTagsProcessorTest.php +++ b/src/HttpCache/Tests/State/AddTagsProcessorTest.php @@ -51,7 +51,7 @@ public function testAddTags(): void public function testAddTagsCollection(): void { - $operation = new GetCollection(class: 'Foo', uriVariables: ['id' => new Link()]); + $operation = new GetCollection(class: \stdClass::class, uriVariables: ['id' => new Link()]); $response = $this->createMock(Response::class); $response->method('isCacheable')->willReturn(true); $response->headers = $this->createMock(ResponseHeaderBag::class); @@ -65,7 +65,7 @@ public function testAddTagsCollection(): void $decorated = $this->createMock(ProcessorInterface::class); $decorated->method('process')->willReturn($response); $iriConverter = $this->createMock(IriConverterInterface::class); - $iriConverter->expects($this->once())->method('getIriFromResource')->with('Foo', UrlGeneratorInterface::ABS_PATH, $operation, ['uri_variables' => ['id' => 1]])->willReturn('/foos/1/bars'); + $iriConverter->expects($this->once())->method('getIriFromResource')->with(\stdClass::class, UrlGeneratorInterface::ABS_PATH, $operation, ['uri_variables' => ['id' => 1]])->willReturn('/foos/1/bars'); $processor = new AddTagsProcessor($decorated, $iriConverter); $processor->process($response, $operation, [], $context); } diff --git a/src/JsonApi/Tests/State/JsonApiProviderTest.php b/src/JsonApi/Tests/State/JsonApiProviderTest.php index 180c5d5b89c..5ce94261026 100644 --- a/src/JsonApi/Tests/State/JsonApiProviderTest.php +++ b/src/JsonApi/Tests/State/JsonApiProviderTest.php @@ -31,7 +31,7 @@ public function testProvide(): void $request->attributes->expects($this->once())->method('get')->with('_api_filters', [])->willReturn([]); $request->attributes->method('set')->with($this->logicalOr('_api_filter_property', '_api_included', '_api_filters'), $this->logicalOr(['id', 'name', 'dummyFloat', 'relatedDummy' => ['id', 'name']], ['relatedDummy'], [])); $request->query = new InputBag(['fields' => ['dummy' => 'id,name,dummyFloat', 'relatedDummy' => 'id,name'], 'include' => 'relatedDummy,foo']); - $operation = new Get(class: 'dummy', shortName: 'dummy'); + $operation = new Get(class: \stdClass::class, shortName: 'dummy'); $context = ['request' => $request]; $decorated = $this->createMock(ProviderInterface::class); $provider = new JsonApiProvider($decorated); diff --git a/src/Metadata/ApiResource.php b/src/Metadata/ApiResource.php index 8fd24f20114..18e3b880ed0 100644 --- a/src/Metadata/ApiResource.php +++ b/src/Metadata/ApiResource.php @@ -42,6 +42,7 @@ class ApiResource extends Metadata /** * @param list|array|Operations|null $operations Operations is a list of HttpOperation * @param array|array|string[]|string|null $uriVariables + * @param class-string $class * @param array $headers * @param string|callable|null $provider * @param string|callable|null $processor diff --git a/src/Metadata/Metadata.php b/src/Metadata/Metadata.php index 9668b04a20b..5f5bf50b5c3 100644 --- a/src/Metadata/Metadata.php +++ b/src/Metadata/Metadata.php @@ -23,6 +23,7 @@ abstract class Metadata protected ?Parameters $parameters = null; /** + * @param class-string $class * @param string|null $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties * @param string|\Stringable|null $security https://api-platform.com/docs/core/security * @param string|\Stringable|null $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization @@ -104,11 +105,17 @@ public function withShortName(string $shortName): static return $self; } + /** + * @return class-string|null + */ public function getClass(): ?string { return $this->class; } + /** + * @param class-string $class + */ public function withClass(string $class): static { $self = clone $this; diff --git a/src/Metadata/Tests/Resource/Factory/MainControllerResourceMetadataCollectionFactoryTest.php b/src/Metadata/Tests/Resource/Factory/MainControllerResourceMetadataCollectionFactoryTest.php index 0cf7226d083..44cf84d3ab9 100644 --- a/src/Metadata/Tests/Resource/Factory/MainControllerResourceMetadataCollectionFactoryTest.php +++ b/src/Metadata/Tests/Resource/Factory/MainControllerResourceMetadataCollectionFactoryTest.php @@ -29,14 +29,14 @@ public function testCreate(): void $decorated->method('create')->willReturn(new ResourceMetadataCollection('Dummy', [ new ApiResource( shortName: 'AttributeResource', - class: 'Dummy', + class: \stdClass::class, operations: [ - 'get' => new Get(shortName: 'AttributeResource', class: 'Dummy'), + 'get' => new Get(shortName: 'AttributeResource', class: \stdClass::class), ] ), ])); - $apiResource = (new MainControllerResourceMetadataCollectionFactory($decorated))->create('Dummy'); + $apiResource = (new MainControllerResourceMetadataCollectionFactory($decorated))->create(\stdClass::class); $operation = $apiResource->getOperation(); $this->assertInstanceOf(HttpOperation::class, $operation); $this->assertEquals($operation->getController(), 'api_platform.symfony.main_controller'); diff --git a/src/OpenApi/Tests/Serializer/OpenApiNormalizerTest.php b/src/OpenApi/Tests/Serializer/OpenApiNormalizerTest.php index ae002331e7c..be36a20f288 100644 --- a/src/OpenApi/Tests/Serializer/OpenApiNormalizerTest.php +++ b/src/OpenApi/Tests/Serializer/OpenApiNormalizerTest.php @@ -98,10 +98,10 @@ public function testNormalizeWithEmptySchemas(): void public function testNormalize(): void { $resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class); - $resourceNameCollectionFactoryProphecy->create()->shouldBeCalled()->willReturn(new ResourceNameCollection([Dummy::class, 'Zorro'])); + $resourceNameCollectionFactoryProphecy->create()->shouldBeCalled()->willReturn(new ResourceNameCollection([Dummy::class, \stdClass::class])); $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); $propertyNameCollectionFactoryProphecy->create(Dummy::class, Argument::any())->shouldBeCalled()->willReturn(new PropertyNameCollection(['id', 'name', 'description', 'dummyDate'])); - $propertyNameCollectionFactoryProphecy->create('Zorro', Argument::any())->shouldBeCalled()->willReturn(new PropertyNameCollection(['id'])); + $propertyNameCollectionFactoryProphecy->create(\stdClass::class, Argument::any())->shouldBeCalled()->willReturn(new PropertyNameCollection(['id'])); $baseOperation = (new HttpOperation())->withTypes(['http://schema.example.com/Dummy']) ->withInputFormats(self::OPERATION_FORMATS['input_formats'])->withOutputFormats(self::OPERATION_FORMATS['output_formats']) @@ -127,7 +127,7 @@ public function testNormalize(): void $zorroBaseOperation = (new HttpOperation()) ->withTypes(['http://schema.example.com/Zorro']) ->withInputFormats(self::OPERATION_FORMATS['input_formats'])->withOutputFormats(self::OPERATION_FORMATS['output_formats']) - ->withClass('Zorro') + ->withClass(\stdClass::class) ->withShortName('Zorro') ->withDescription('This is zorro.'); @@ -142,7 +142,7 @@ public function testNormalize(): void $resourceCollectionMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); $resourceCollectionMetadataFactoryProphecy->create(Dummy::class)->shouldBeCalled()->willReturn($dummyMetadata); - $resourceCollectionMetadataFactoryProphecy->create('Zorro')->shouldBeCalled()->willReturn($zorroMetadata); + $resourceCollectionMetadataFactoryProphecy->create(\stdClass::class)->shouldBeCalled()->willReturn($zorroMetadata); $resourceCollectionMetadataFactoryProphecy->create(Error::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(Error::class, [])); $resourceCollectionMetadataFactoryProphecy->create(ValidationException::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(ValidationException::class, [])); @@ -193,7 +193,7 @@ public function testNormalize(): void ->withSchema(['type' => 'string', 'format' => 'date-time', 'description' => 'This is a \DateTimeInterface object.']) ); - $propertyMetadataFactoryProphecy->create('Zorro', 'id', Argument::any())->shouldBeCalled()->willReturn( + $propertyMetadataFactoryProphecy->create(\stdClass::class, 'id', Argument::any())->shouldBeCalled()->willReturn( (new ApiProperty()) ->withNativeType(Type::int()) ->withDescription('This is an id.') diff --git a/src/State/Tests/Provider/DeserializeProviderTest.php b/src/State/Tests/Provider/DeserializeProviderTest.php index 34620875df3..b0f29c11413 100644 --- a/src/State/Tests/Provider/DeserializeProviderTest.php +++ b/src/State/Tests/Provider/DeserializeProviderTest.php @@ -37,14 +37,14 @@ public function testDeserialize(): void $this->expectUserDeprecationMessage('Since api-platform/core 5.0: To assign an object to populate you should set "api_assign_object_to_populate" in your denormalizationContext, not defining it is deprecated.'); $objectToPopulate = new \stdClass(); $serializerContext = []; - $operation = new Post(deserialize: true, class: 'Test'); + $operation = new Post(deserialize: true, class: \stdClass::class); $decorated = $this->createStub(ProviderInterface::class); $decorated->method('provide')->willReturn($objectToPopulate); $serializerContextBuilder = $this->createMock(SerializerContextBuilderInterface::class); $serializerContextBuilder->expects($this->once())->method('createFromRequest')->willReturn($serializerContext); $serializer = $this->createMock(SerializerInterface::class); - $serializer->expects($this->once())->method('deserialize')->with('test', 'Test', 'format', ['uri_variables' => ['id' => 1], AbstractNormalizer::OBJECT_TO_POPULATE => $objectToPopulate] + $serializerContext)->willReturn(new \stdClass()); + $serializer->expects($this->once())->method('deserialize')->with('test', \stdClass::class, 'format', ['uri_variables' => ['id' => 1], AbstractNormalizer::OBJECT_TO_POPULATE => $objectToPopulate] + $serializerContext)->willReturn(new \stdClass()); $provider = new DeserializeProvider($decorated, $serializer, $serializerContextBuilder); $request = new Request(content: 'test'); @@ -56,7 +56,7 @@ public function testDeserialize(): void public function testDeserializeNoContentType(): void { $this->expectException(UnsupportedMediaTypeHttpException::class); - $operation = new Get(deserialize: true, class: 'Test'); + $operation = new Get(deserialize: true, class: \stdClass::class); $decorated = $this->createStub(ProviderInterface::class); $decorated->method('provide')->willReturn(null); @@ -72,7 +72,7 @@ public function testDeserializeNoContentType(): void public function testDeserializeNoInput(): void { $this->expectException(UnsupportedMediaTypeHttpException::class); - $operation = new Get(deserialize: true, class: 'Test'); + $operation = new Get(deserialize: true, class: \stdClass::class); $decorated = $this->createStub(ProviderInterface::class); $decorated->method('provide')->willReturn(null); @@ -153,7 +153,7 @@ public function testDeserializeTriggersDeprecationWhenContextNotSet(HttpOperatio $serializer = $this->createMock(SerializerInterface::class); $serializer->expects($this->once())->method('deserialize')->with( 'test', - 'Test', + \stdClass::class, 'format', ['uri_variables' => ['id' => 1], 'object_to_populate' => $objectToPopulate] + $serializerContext )->willReturn(new \stdClass()); @@ -167,16 +167,16 @@ public function testDeserializeTriggersDeprecationWhenContextNotSet(HttpOperatio public static function provideMethodsTriggeringDeprecation(): iterable { - yield 'POST method' => [new Post(deserialize: true, class: 'Test')]; - yield 'PATCH method' => [new Patch(deserialize: true, class: 'Test')]; - yield 'PUT method (non-standard)' => [new Put(deserialize: true, class: 'Test', extraProperties: ['standard_put' => false])]; + yield 'POST method' => [new Post(deserialize: true, class: \stdClass::class)]; + yield 'PATCH method' => [new Patch(deserialize: true, class: \stdClass::class)]; + yield 'PUT method (non-standard)' => [new Put(deserialize: true, class: \stdClass::class, extraProperties: ['standard_put' => false])]; } public function testDeserializeSetsObjectToPopulateWhenContextIsTrue(): void { $objectToPopulate = new \stdClass(); $serializerContext = [SerializerContextBuilderInterface::ASSIGN_OBJECT_TO_POPULATE => true]; - $operation = new Post(deserialize: true, class: 'Test'); + $operation = new Post(deserialize: true, class: \stdClass::class); $decorated = $this->createStub(ProviderInterface::class); $decorated->method('provide')->willReturn($objectToPopulate); @@ -186,7 +186,7 @@ public function testDeserializeSetsObjectToPopulateWhenContextIsTrue(): void $serializer = $this->createMock(SerializerInterface::class); $serializer->expects($this->once())->method('deserialize')->with( 'test', - 'Test', + \stdClass::class, 'format', $this->callback(function (array $context) use ($objectToPopulate) { $this->assertArrayHasKey(AbstractNormalizer::OBJECT_TO_POPULATE, $context); @@ -207,7 +207,7 @@ public function testDeserializeDoesNotSetObjectToPopulateWhenContextIsFalse(): v { $objectToPopulate = new \stdClass(); $serializerContext = [SerializerContextBuilderInterface::ASSIGN_OBJECT_TO_POPULATE => false]; - $operation = new Post(deserialize: true, class: 'Test'); + $operation = new Post(deserialize: true, class: \stdClass::class); $decorated = $this->createStub(ProviderInterface::class); $decorated->method('provide')->willReturn($objectToPopulate); @@ -217,7 +217,7 @@ public function testDeserializeDoesNotSetObjectToPopulateWhenContextIsFalse(): v $serializer = $this->createMock(SerializerInterface::class); $serializer->expects($this->once())->method('deserialize')->with( 'test', - 'Test', + \stdClass::class, 'format', $this->callback(function (array $context) { $this->assertArrayNotHasKey(AbstractNormalizer::OBJECT_TO_POPULATE, $context); diff --git a/src/State/Tests/Provider/SecurityParameterProviderTest.php b/src/State/Tests/Provider/SecurityParameterProviderTest.php index 80797ef0adf..30e59b1b995 100644 --- a/src/State/Tests/Provider/SecurityParameterProviderTest.php +++ b/src/State/Tests/Provider/SecurityParameterProviderTest.php @@ -31,7 +31,7 @@ public function testIsGrantedLink(): void $barObj = new \stdClass(); $operation = new GetCollection(uriVariables: [ 'barId' => new Link(toProperty: 'bar', fromClass: 'Bar', security: 'is_granted("some_voter", "bar")'), - ], class: 'Foo'); + ], class: \stdClass::class); $decorated = $this->createMock(ProviderInterface::class); $decorated->method('provide')->willReturn($obj); $request = $this->createMock(Request::class); @@ -52,7 +52,7 @@ public function testIsNotGrantedLink(): void $barObj = new \stdClass(); $operation = new GetCollection(uriVariables: [ 'barId' => new Link(toProperty: 'bar', fromClass: 'Bar', security: 'is_granted("some_voter", "bar")'), - ], class: 'Foo'); + ], class: \stdClass::class); $decorated = $this->createMock(ProviderInterface::class); $decorated->method('provide')->willReturn($obj); $request = $this->createMock(Request::class); @@ -74,7 +74,7 @@ public function testSecurityMessageLink(): void $barObj = new \stdClass(); $operation = new GetCollection(uriVariables: [ 'barId' => new Link(toProperty: 'bar', fromClass: 'Bar', security: 'is_granted("some_voter", "bar")', securityMessage: 'You are not admin.'), - ], class: 'Foo'); + ], class: \stdClass::class); $decorated = $this->createMock(ProviderInterface::class); $decorated->method('provide')->willReturn($obj); $request = $this->createMock(Request::class); diff --git a/src/Symfony/Tests/EventListener/ReadListenerTest.php b/src/Symfony/Tests/EventListener/ReadListenerTest.php index e50f4c67225..e25eeabc187 100644 --- a/src/Symfony/Tests/EventListener/ReadListenerTest.php +++ b/src/Symfony/Tests/EventListener/ReadListenerTest.php @@ -35,13 +35,13 @@ public function testFetchOperation(): void $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide'); $metadata = $this->createMock(ResourceMetadataCollectionFactoryInterface::class); - $metadata->expects($this->once())->method('create')->with('class')->willReturn(new ResourceMetadataCollection('class', [ + $metadata->expects($this->once())->method('create')->with(\stdClass::class)->willReturn(new ResourceMetadataCollection(\stdClass::class, [ new ApiResource(operations: [ 'operation' => new Get(), ]), ])); - $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new ReadListener($provider, $metadata); $listener->onKernelRequest( new RequestEvent( @@ -57,7 +57,7 @@ public function testCallProvider(): void $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide'); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new ReadListener($provider, $metadata); $listener->onKernelRequest( new RequestEvent( @@ -74,7 +74,7 @@ public function testNoCallProvider(...$attributes): void $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->never())->method('provide'); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $metadata->method('create')->willReturn(new ResourceMetadataCollection('class')); + $metadata->method('create')->willReturn(new ResourceMetadataCollection(\stdClass::class)); $listener = new ReadListener($provider, $metadata); $listener->onKernelRequest( new RequestEvent( @@ -99,7 +99,7 @@ public function testReadFalse(): void $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide')->with($operation); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new ReadListener($provider, $metadata); $listener->onKernelRequest( new RequestEvent( @@ -112,13 +112,13 @@ public function testReadFalse(): void public function testReadWithUriVariables(): void { - $operation = new Get(uriVariables: ['id' => new Link(identifiers: ['id'])], class: 'class'); + $operation = new Get(uriVariables: ['id' => new Link(identifiers: ['id'])], class: \stdClass::class); $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide')->with($operation->withRead(true), ['id' => 3]); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $uriVariablesConverter = $this->createMock(UriVariablesConverterInterface::class); - $uriVariablesConverter->expects($this->once())->method('convert')->with(['id' => '3'], 'class')->willReturn(['id' => 3]); - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class', 'id' => '3']); + $uriVariablesConverter->expects($this->once())->method('convert')->with(['id' => '3'], \stdClass::class)->willReturn(['id' => 3]); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, 'id' => '3']); $listener = new ReadListener($provider, $metadata, $uriVariablesConverter); $listener->onKernelRequest( new RequestEvent( @@ -135,7 +135,7 @@ public function testReadNullWithPostMethod(): void $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide')->with($operation); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $request = new Request([], [], ['_api_operation' => new Post(), '_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation' => new Post(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $request->setMethod('POST'); $listener = new ReadListener($provider, $metadata); $listener->onKernelRequest( diff --git a/src/Symfony/Tests/EventListener/RespondListenerTest.php b/src/Symfony/Tests/EventListener/RespondListenerTest.php index a78412968fd..55138d2b360 100644 --- a/src/Symfony/Tests/EventListener/RespondListenerTest.php +++ b/src/Symfony/Tests/EventListener/RespondListenerTest.php @@ -34,13 +34,13 @@ public function testFetchOperation(): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process')->willReturn(new Response()); $metadata = $this->createMock(ResourceMetadataCollectionFactoryInterface::class); - $metadata->expects($this->once())->method('create')->with('class')->willReturn(new ResourceMetadataCollection('class', [ + $metadata->expects($this->once())->method('create')->with(\stdClass::class)->willReturn(new ResourceMetadataCollection(\stdClass::class, [ new ApiResource(operations: [ 'operation' => new Get(), ]), ])); - $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new RespondListener($processor, $metadata); $listener->onKernelView( new ViewEvent( @@ -58,7 +58,7 @@ public function testCallProcessor(): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process')->willReturn(new Response()); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new RespondListener($processor, $metadata); $listener->onKernelView( new ViewEvent( @@ -72,14 +72,14 @@ public function testCallProcessor(): void public function testCallProcessorContext(): void { - $operation = new Get(class: 'class'); + $operation = new Get(class: \stdClass::class); $controllerResult = new \stdClass(); $originalData = new \stdClass(); $uriVariables = ['id' => 3]; - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class', '_api_uri_variables' => $uriVariables, 'original_data' => $originalData]); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables, 'original_data' => $originalData]); $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process') - ->with($controllerResult, $operation, $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => 'class', 'original_data' => $originalData])->willReturn(new Response()); + ->with($controllerResult, $operation, $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class, 'original_data' => $originalData])->willReturn(new Response()); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $listener = new RespondListener($processor, $metadata); $listener->onKernelView( @@ -99,7 +99,7 @@ public function testNoCallProcessor(...$attributes): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->never())->method('process')->willReturn(new Response()); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $metadata->method('create')->willReturn(new ResourceMetadataCollection('class')); + $metadata->method('create')->willReturn(new ResourceMetadataCollection(\stdClass::class)); $request = new Request([], [], $attributes); $listener = new RespondListener($processor, $metadata); $listener->onKernelView( diff --git a/src/Symfony/Tests/EventListener/SerializeListenerTest.php b/src/Symfony/Tests/EventListener/SerializeListenerTest.php index 4ad6834c34b..dc9354f0b6c 100644 --- a/src/Symfony/Tests/EventListener/SerializeListenerTest.php +++ b/src/Symfony/Tests/EventListener/SerializeListenerTest.php @@ -34,13 +34,13 @@ public function testFetchOperation(): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process')->willReturn(new Response()); $metadata = $this->createMock(ResourceMetadataCollectionFactoryInterface::class); - $metadata->expects($this->once())->method('create')->with('class')->willReturn(new ResourceMetadataCollection('class', [ + $metadata->expects($this->once())->method('create')->with(\stdClass::class)->willReturn(new ResourceMetadataCollection(\stdClass::class, [ new ApiResource(operations: [ 'operation' => new Get(), ]), ])); - $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new SerializeListener($processor, $metadata); $listener->onKernelView( new ViewEvent( @@ -58,7 +58,7 @@ public function testCallProcessor(): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process')->willReturn(new Response()); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new SerializeListener($processor, $metadata); $listener->onKernelView( new ViewEvent( @@ -72,13 +72,13 @@ public function testCallProcessor(): void public function testCallProcessorContext(): void { - $operation = new Get(class: 'class'); + $operation = new Get(class: \stdClass::class); $controllerResult = new \stdClass(); $uriVariables = ['id' => 3]; - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class', '_api_uri_variables' => $uriVariables]); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables]); $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process') - ->with($controllerResult, $operation->withSerialize(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => 'class'])->willReturn(new Response()); + ->with($controllerResult, $operation->withSerialize(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class])->willReturn(new Response()); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $listener = new SerializeListener($processor, $metadata); $listener->onKernelView( @@ -98,7 +98,7 @@ public function testNoCallProcessor(...$attributes): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->never())->method('process')->willReturn(new Response()); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $metadata->method('create')->willReturn(new ResourceMetadataCollection('class')); + $metadata->method('create')->willReturn(new ResourceMetadataCollection(\stdClass::class)); $request = new Request([], [], $attributes); $listener = new SerializeListener($processor, $metadata); $listener->onKernelView( diff --git a/src/Symfony/Tests/EventListener/ValidateListenerTest.php b/src/Symfony/Tests/EventListener/ValidateListenerTest.php index bd0e38d23f2..f367d043882 100644 --- a/src/Symfony/Tests/EventListener/ValidateListenerTest.php +++ b/src/Symfony/Tests/EventListener/ValidateListenerTest.php @@ -34,13 +34,13 @@ public function testFetchOperation(): void $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide'); $metadata = $this->createMock(ResourceMetadataCollectionFactoryInterface::class); - $metadata->expects($this->once())->method('create')->with('class')->willReturn(new ResourceMetadataCollection('class', [ + $metadata->expects($this->once())->method('create')->with(\stdClass::class)->willReturn(new ResourceMetadataCollection(\stdClass::class, [ new ApiResource(operations: [ 'operation' => new Post(), ]), ])); - $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new ValidateListener($provider, $metadata); $listener->onKernelView( new ViewEvent( @@ -58,7 +58,7 @@ public function testCallprovider(): void $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide'); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $request = new Request([], [], ['_api_operation' => new Post(), '_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation' => new Post(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new ValidateListener($provider, $metadata); $listener->onKernelView( new ViewEvent( @@ -72,14 +72,14 @@ public function testCallprovider(): void public function testCallproviderContext(): void { - $operation = new Post(class: 'class'); + $operation = new Post(class: \stdClass::class); $controllerResult = new \stdClass(); $uriVariables = ['id' => 3]; - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class', '_api_uri_variables' => $uriVariables]); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables]); $request->setMethod($operation->getMethod()); $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide') - ->with($operation->withValidate(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => 'class']); + ->with($operation->withValidate(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class]); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $listener = new ValidateListener($provider, $metadata); $listener->onKernelView( @@ -94,14 +94,14 @@ public function testCallproviderContext(): void public function testDeleteNoValidate(): void { - $operation = new Delete(class: 'class'); + $operation = new Delete(class: \stdClass::class); $controllerResult = new \stdClass(); $uriVariables = ['id' => 3]; - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class', '_api_uri_variables' => $uriVariables]); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables]); $request->setMethod($operation->getMethod()); $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide') - ->with($operation->withValidate(false), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => 'class']); + ->with($operation->withValidate(false), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class]); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $listener = new ValidateListener($provider, $metadata); $listener->onKernelView( @@ -116,14 +116,14 @@ public function testDeleteNoValidate(): void public function testDeleteForceValidate(): void { - $operation = new Delete(class: 'class', validate: true); + $operation = new Delete(class: \stdClass::class, validate: true); $controllerResult = new \stdClass(); $uriVariables = ['id' => 3]; - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class', '_api_uri_variables' => $uriVariables]); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables]); $request->setMethod($operation->getMethod()); $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->once())->method('provide') - ->with($operation->withValidate(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => 'class']); + ->with($operation->withValidate(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class]); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $listener = new ValidateListener($provider, $metadata); $listener->onKernelView( @@ -143,7 +143,7 @@ public function testNoCallprovider(...$attributes): void $provider = $this->createMock(ProviderInterface::class); $provider->expects($this->never())->method('provide'); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $metadata->method('create')->willReturn(new ResourceMetadataCollection('class')); + $metadata->method('create')->willReturn(new ResourceMetadataCollection(\stdClass::class)); $request = new Request([], [], $attributes); $listener = new ValidateListener($provider, $metadata); $listener->onKernelView( diff --git a/src/Symfony/Tests/EventListener/WriteListenerTest.php b/src/Symfony/Tests/EventListener/WriteListenerTest.php index 921aa4cb857..9b53bbf4ad4 100644 --- a/src/Symfony/Tests/EventListener/WriteListenerTest.php +++ b/src/Symfony/Tests/EventListener/WriteListenerTest.php @@ -37,13 +37,13 @@ public function testFetchOperation(): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process')->willReturn(new Response()); $metadata = $this->createMock(ResourceMetadataCollectionFactoryInterface::class); - $metadata->expects($this->once())->method('create')->with('class')->willReturn(new ResourceMetadataCollection('class', [ + $metadata->expects($this->once())->method('create')->with(\stdClass::class)->willReturn(new ResourceMetadataCollection(\stdClass::class, [ new ApiResource(operations: [ 'operation' => new Get(), ]), ])); - $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new WriteListener($processor, $metadata); $listener->onKernelView( new ViewEvent( @@ -61,7 +61,7 @@ public function testCallProcessor(): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process')->willReturn(new Response()); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => 'class']); + $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]); $listener = new WriteListener($processor, $metadata); $listener->onKernelView( new ViewEvent( @@ -75,15 +75,15 @@ public function testCallProcessor(): void public function testCallProcessorContext(): void { - $operation = new Get(class: 'class'); + $operation = new Get(class: \stdClass::class); $controllerResult = new \stdClass(); $originalData = new \stdClass(); $uriVariables = ['id' => 3]; $returnValue = new \stdClass(); - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class', '_api_uri_variables' => $uriVariables, 'previous_data' => $originalData]); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables, 'previous_data' => $originalData]); $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->once())->method('process') - ->with($controllerResult, $operation, $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => 'class', 'previous_data' => $originalData])->willReturn($returnValue); + ->with($controllerResult, $operation, $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class, 'previous_data' => $originalData])->willReturn($returnValue); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $listener = new WriteListener($processor, $metadata); $listener->onKernelView( @@ -104,7 +104,7 @@ public function testNoCallProcessor(...$attributes): void $processor = $this->createMock(ProcessorInterface::class); $processor->expects($this->never())->method('process')->willReturn(new Response()); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); - $metadata->method('create')->willReturn(new ResourceMetadataCollection('class')); + $metadata->method('create')->willReturn(new ResourceMetadataCollection(\stdClass::class)); $request = new Request([], [], $attributes); $listener = new WriteListener($processor, $metadata); $listener->onKernelView( @@ -128,13 +128,13 @@ public static function provideNonApiAttributes(): array public function testWriteWithUriVariables(): void { $controllerResult = new \stdClass(); - $operation = new Post(uriVariables: ['id' => new Link(identifiers: ['id'])], class: 'class'); + $operation = new Post(uriVariables: ['id' => new Link(identifiers: ['id'])], class: \stdClass::class); $provider = $this->createMock(ProcessorInterface::class); $provider->expects($this->once())->method('process')->with($controllerResult, $operation->withWrite(true), ['id' => 3]); $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class); $uriVariablesConverter = $this->createMock(UriVariablesConverterInterface::class); - $uriVariablesConverter->expects($this->once())->method('convert')->with(['id' => '3'], 'class')->willReturn(['id' => 3]); - $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => 'class', 'id' => '3']); + $uriVariablesConverter->expects($this->once())->method('convert')->with(['id' => '3'], \stdClass::class)->willReturn(['id' => 3]); + $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, 'id' => '3']); $request->setMethod($operation->getMethod()); $listener = new WriteListener($provider, $metadata, uriVariablesConverter: $uriVariablesConverter); $listener->onKernelView( diff --git a/tests/Symfony/Security/State/AccessCheckerProviderTest.php b/tests/Symfony/Security/State/AccessCheckerProviderTest.php index 7f69eb1d04c..c4545c4a258 100644 --- a/tests/Symfony/Security/State/AccessCheckerProviderTest.php +++ b/tests/Symfony/Security/State/AccessCheckerProviderTest.php @@ -19,6 +19,7 @@ use ApiPlatform\State\ProviderInterface; use ApiPlatform\Symfony\Security\Exception\AccessDeniedException; use ApiPlatform\Symfony\Security\State\AccessCheckerProvider; +use ApiPlatform\Tests\Fixtures\DummyEntity; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -27,11 +28,11 @@ class AccessCheckerProviderTest extends TestCase public function testCheckAccess(): void { $obj = new \stdClass(); - $operation = new Get(class: 'foo', security: 'hi'); + $operation = new Get(class: DummyEntity::class, security: 'hi'); $decorated = $this->createMock(ProviderInterface::class); $decorated->method('provide')->willReturn($obj); $resourceAccessChecker = $this->createMock(ResourceAccessCheckerInterface::class); - $resourceAccessChecker->expects($this->once())->method('isGranted')->with('foo', 'hi', ['object' => $obj, 'previous_object' => null, 'request' => null])->willReturn(true); + $resourceAccessChecker->expects($this->once())->method('isGranted')->with(DummyEntity::class, 'hi', ['object' => $obj, 'previous_object' => null, 'request' => null])->willReturn(true); $accessChecker = new AccessCheckerProvider($decorated, $resourceAccessChecker); $accessChecker->provide($operation, [], []); } @@ -39,11 +40,11 @@ public function testCheckAccess(): void public function testCheckAccessWithEvent(): void { $obj = new \stdClass(); - $operation = new Get(class: 'foo', securityPostDenormalize: 'hi'); + $operation = new Get(class: DummyEntity::class, securityPostDenormalize: 'hi'); $decorated = $this->createMock(ProviderInterface::class); $decorated->method('provide')->willReturn($obj); $resourceAccessChecker = $this->createMock(ResourceAccessCheckerInterface::class); - $resourceAccessChecker->expects($this->once())->method('isGranted')->with('foo', 'hi', ['object' => $obj, 'previous_object' => null, 'request' => null])->willReturn(true); + $resourceAccessChecker->expects($this->once())->method('isGranted')->with(DummyEntity::class, 'hi', ['object' => $obj, 'previous_object' => null, 'request' => null])->willReturn(true); $accessChecker = new AccessCheckerProvider($decorated, $resourceAccessChecker, 'post_denormalize'); $accessChecker->provide($operation, [], []); } @@ -51,11 +52,11 @@ public function testCheckAccessWithEvent(): void public function testCheckAccessWithEventPostValidate(): void { $obj = new \stdClass(); - $operation = new Get(class: 'foo', securityPostValidation: 'hi'); + $operation = new Get(class: DummyEntity::class, securityPostValidation: 'hi'); $decorated = $this->createMock(ProviderInterface::class); $decorated->method('provide')->willReturn($obj); $resourceAccessChecker = $this->createMock(ResourceAccessCheckerInterface::class); - $resourceAccessChecker->expects($this->once())->method('isGranted')->with('foo', 'hi', ['object' => $obj, 'previous_object' => null, 'request' => null])->willReturn(true); + $resourceAccessChecker->expects($this->once())->method('isGranted')->with(DummyEntity::class, 'hi', ['object' => $obj, 'previous_object' => null, 'request' => null])->willReturn(true); $accessChecker = new AccessCheckerProvider($decorated, $resourceAccessChecker, 'post_validate'); $accessChecker->provide($operation, [], []); } @@ -66,11 +67,11 @@ public function testCheckAccessDenied(): void $this->expectExceptionMessage('hello'); $obj = new \stdClass(); - $operation = new Get(class: 'foo', security: 'hi', securityMessage: 'hello'); + $operation = new Get(class: DummyEntity::class, security: 'hi', securityMessage: 'hello'); $decorated = $this->createMock(ProviderInterface::class); $decorated->method('provide')->willReturn($obj); $resourceAccessChecker = $this->createMock(ResourceAccessCheckerInterface::class); - $resourceAccessChecker->expects($this->once())->method('isGranted')->with('foo', 'hi', ['object' => $obj, 'previous_object' => null, 'request' => null])->willReturn(false); + $resourceAccessChecker->expects($this->once())->method('isGranted')->with(DummyEntity::class, 'hi', ['object' => $obj, 'previous_object' => null, 'request' => null])->willReturn(false); $accessChecker = new AccessCheckerProvider($decorated, $resourceAccessChecker); $accessChecker->provide($operation, [], []); } @@ -81,11 +82,11 @@ public function testCheckAccessDeniedWithGraphQl(): void $this->expectExceptionMessage('hello'); $obj = new \stdClass(); - $operation = new Query(class: 'foo', security: 'hi', securityMessage: 'hello'); + $operation = new Query(class: DummyEntity::class, security: 'hi', securityMessage: 'hello'); $decorated = $this->createMock(ProviderInterface::class); $decorated->method('provide')->willReturn($obj); $resourceAccessChecker = $this->createMock(ResourceAccessCheckerInterface::class); - $resourceAccessChecker->expects($this->once())->method('isGranted')->with('foo', 'hi', ['object' => $obj, 'previous_object' => null])->willReturn(false); + $resourceAccessChecker->expects($this->once())->method('isGranted')->with(DummyEntity::class, 'hi', ['object' => $obj, 'previous_object' => null])->willReturn(false); $accessChecker = new AccessCheckerProvider($decorated, $resourceAccessChecker); $accessChecker->provide($operation, [], []); }