From 63c8239194375901afc80cf26295c262fca03640 Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Thu, 30 May 2024 19:31:41 +0200 Subject: [PATCH 1/4] feature/easy-api-platform-refactor-tests --- .phpstorm.meta.php | 6 ++ packages/EasyApiPlatform/composer.json | 1 + .../OperationRequestInitiatorTrait.php | 27 ------ .../Bridge/Symfony/Listeners/ReadListener.php | 3 +- .../Serializers/SerializerContextBuilder.php | 2 +- .../tests/AbstractApiTestCase.php | 36 ++++++++ .../tests/AbstractTestCase.php | 43 +++------- .../Symfony/AbstractSymfonyTestCase.php | 25 ------ .../HttpKernelViewEventListenerTest.php | 83 ------------------ .../Symfony/Listeners/ReadListenerTest.php | 18 ++-- .../tests/Bridge/Symfony/Stubs/KernelStub.php | 46 ---------- .../Stubs/SerializerContextBuilderStub.php | 15 ---- .../tests/Filters/AbstractFilterTestCase.php | 15 +--- .../Filters/AdvancedSearchFilterTest.php | 6 +- .../app/config/packages/api_platform.php | 3 +- .../Fixtures/app/config/packages/doctrine.php | 13 ++- .../ApiResource/Dummy.php | 6 +- .../ApiResource/DummyFriend.php | 2 +- .../ApiResource/EmbeddableDummy.php | 2 +- .../ApiResource/FourthLevel.php | 2 +- .../ApiResource/ParentDummy.php | 2 +- .../ApiResource/RelatedDummy.php | 6 +- .../ApiResource/RelatedOwnedDummy.php | 2 +- .../ApiResource/RelatedOwningDummy.php | 2 +- .../ApiResource/RelatedToDummyFriend.php | 2 +- .../ApiResource/ThirdLevel.php | 2 +- .../NameConverter/CustomConverter.php | 2 +- .../CustomPaginator/ApiResource/Category.php | 45 ++++++++++ .../tests/Paginators/CustomPaginatorTest.php | 85 ++++++------------- .../SerializerContextBuilderTest.php | 72 ---------------- quality/phpstan.neon | 2 +- 31 files changed, 175 insertions(+), 401 deletions(-) delete mode 100644 packages/EasyApiPlatform/src/Bridge/Symfony/Listeners/OperationRequestInitiatorTrait.php create mode 100644 packages/EasyApiPlatform/tests/AbstractApiTestCase.php delete mode 100644 packages/EasyApiPlatform/tests/Bridge/Symfony/AbstractSymfonyTestCase.php delete mode 100644 packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/HttpKernelViewEventListenerTest.php delete mode 100644 packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/KernelStub.php delete mode 100644 packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/SerializerContextBuilderStub.php rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/Dummy.php (96%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/DummyFriend.php (91%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/EmbeddableDummy.php (96%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/FourthLevel.php (92%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/ParentDummy.php (84%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/RelatedDummy.php (93%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/RelatedOwnedDummy.php (93%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/RelatedOwningDummy.php (93%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/RelatedToDummyFriend.php (95%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/ApiResource/ThirdLevel.php (95%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{ => Case/AdvancedSearchFilter}/Serializer/NameConverter/CustomConverter.php (87%) create mode 100644 packages/EasyApiPlatform/tests/Fixtures/app/src/Case/CustomPaginator/ApiResource/Category.php delete mode 100644 packages/EasyApiPlatform/tests/Serializers/SerializerContextBuilderTest.php diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index b2c9c4982..ad362a9a7 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -8,3 +8,9 @@ // $envelope->last(Stamp::class) -> instance of "Stamp" override(\Symfony\Component\Messenger\Envelope::last(0), type(0)); + +// self::getService(Type::class) → instance of "Type" +override( + \EonX\EasyTest\Traits\ContainerServiceTrait::getService(), + type(0), +); diff --git a/packages/EasyApiPlatform/composer.json b/packages/EasyApiPlatform/composer.json index ba4be0415..963fe0c01 100644 --- a/packages/EasyApiPlatform/composer.json +++ b/packages/EasyApiPlatform/composer.json @@ -19,6 +19,7 @@ "doctrine/common": "^3.0", "doctrine/annotations": "^1.14", "doctrine/doctrine-bundle": "^2.8", + "eonx-com/easy-test": "^5.11", "mockery/mockery": "^1.6", "phpspec/prophecy": "^1.0", "phpspec/prophecy-phpunit": "^2.0", diff --git a/packages/EasyApiPlatform/src/Bridge/Symfony/Listeners/OperationRequestInitiatorTrait.php b/packages/EasyApiPlatform/src/Bridge/Symfony/Listeners/OperationRequestInitiatorTrait.php deleted file mode 100644 index 600646109..000000000 --- a/packages/EasyApiPlatform/src/Bridge/Symfony/Listeners/OperationRequestInitiatorTrait.php +++ /dev/null @@ -1,27 +0,0 @@ - ['accept' => ['application/json']], + ] + ); + } + + protected static function createKernel(array $options = []): KernelInterface + { + return new ApplicationKernel('test', false); + } +} diff --git a/packages/EasyApiPlatform/tests/AbstractTestCase.php b/packages/EasyApiPlatform/tests/AbstractTestCase.php index 4147ab3b4..65c27bc3d 100644 --- a/packages/EasyApiPlatform/tests/AbstractTestCase.php +++ b/packages/EasyApiPlatform/tests/AbstractTestCase.php @@ -3,41 +3,24 @@ namespace EonX\EasyApiPlatform\Tests; -use Mockery; -use Mockery\MockInterface; -use PHPUnit\Framework\TestCase; -use Symfony\Component\Filesystem\Filesystem; +use EonX\EasyApiPlatform\Tests\Fixtures\App\Kernel\ApplicationKernel; +use EonX\EasyTest\Traits\ContainerServiceTrait; +use EonX\EasyTest\Traits\PrivatePropertyAccessTrait; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\HttpKernel\KernelInterface; -/** - * This class has for objective to provide common features to all tests without having to update - * the class they all extend. - */ -abstract class AbstractTestCase extends TestCase +abstract class AbstractTestCase extends KernelTestCase { - protected function tearDown(): void - { - $fs = new Filesystem(); - $var = __DIR__ . '/../var'; - - if ($fs->exists($var)) { - $fs->remove($var); - } + use ContainerServiceTrait; + use PrivatePropertyAccessTrait; - parent::tearDown(); + protected function setUp(): void + { + self::bootKernel(); } - /** - * @param class-string|object $target - */ - protected static function mock(string|object $target, ?callable $expectations = null): MockInterface + protected static function createKernel(array $options = []): KernelInterface { - /** @var \Mockery\MockInterface $mock */ - $mock = Mockery::mock($target); - - if ($expectations !== null) { - $expectations($mock); - } - - return $mock; + return new ApplicationKernel('test', false); } } diff --git a/packages/EasyApiPlatform/tests/Bridge/Symfony/AbstractSymfonyTestCase.php b/packages/EasyApiPlatform/tests/Bridge/Symfony/AbstractSymfonyTestCase.php deleted file mode 100644 index 5868eb0ef..000000000 --- a/packages/EasyApiPlatform/tests/Bridge/Symfony/AbstractSymfonyTestCase.php +++ /dev/null @@ -1,25 +0,0 @@ -kernel !== null) { - return $this->kernel; - } - - $this->kernel = new KernelStub(); - $this->kernel->boot(); - - return $this->kernel; - } -} diff --git a/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/HttpKernelViewEventListenerTest.php b/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/HttpKernelViewEventListenerTest.php deleted file mode 100644 index 9692d012d..000000000 --- a/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/HttpKernelViewEventListenerTest.php +++ /dev/null @@ -1,83 +0,0 @@ - [ - 'controllerResult' => new stdClass(), - 'isCustomPaginator' => false, - ]; - - yield 'The controller result is Paginator' => [ - 'controllerResult' => self::getApiPlatformPaginator(), - 'isCustomPaginator' => true, - ]; - } - - #[DataProvider('providerTestListener')] - public function testListener(object $controllerResult, bool $isCustomPaginator): void - { - $event = new ViewEvent( - $this->getKernel(), - new Request(), - HttpKernelInterface::MAIN_REQUEST, - $controllerResult - ); - $listener = new HttpKernelViewEventListener(); - - $listener($event); - - self::assertSame($isCustomPaginator, $event->getControllerResult() instanceof CustomPaginatorInterface); - } - - private static function getApiPlatformPaginator(): Paginator - { - /** @var \Doctrine\ORM\EntityManagerInterface $manager */ - $manager = self::mock(EntityManagerInterface::class, static function (MockInterface $mock): void { - $mock->shouldReceive('getConfiguration') - ->atLeast() - ->once() - ->withNoArgs() - ->andReturn(new Configuration()); - }); - - $query = new Query($manager); - $query->setFirstResult(1) - ->setMaxResults(15); - - /** @var \Doctrine\ORM\Tools\Pagination\Paginator $doctrinePaginator */ - $doctrinePaginator = self::mock( - DoctrinePaginator::class, - static function (MockInterface $mock) use ($query): void { - $mock->shouldReceive('getQuery') - ->once() - ->withNoArgs() - ->andReturn($query); - } - ); - - return new Paginator($doctrinePaginator); - } -} diff --git a/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/ReadListenerTest.php b/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/ReadListenerTest.php index 636721db6..40ef9e3d8 100644 --- a/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/ReadListenerTest.php +++ b/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/ReadListenerTest.php @@ -7,15 +7,15 @@ use ApiPlatform\Metadata\NotExposed; use ApiPlatform\Metadata\Post; use EonX\EasyApiPlatform\Bridge\Symfony\Listeners\ReadListener; -use EonX\EasyApiPlatform\Tests\Bridge\Symfony\AbstractSymfonyTestCase; -use EonX\EasyApiPlatform\Tests\Fixtures\App\ApiResource\Dummy; +use EonX\EasyApiPlatform\Tests\AbstractTestCase; +use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource\Dummy; use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; -final class ReadListenerTest extends AbstractSymfonyTestCase +final class ReadListenerTest extends AbstractTestCase { /** * @see testItThrowsException @@ -137,7 +137,11 @@ public static function provideRequestsForSuccessfulCases(): iterable #[DataProvider('provideRequestsForSuccessfulCases')] public function testItSucceeds(Request $request): void { - $event = new RequestEvent($this->getKernel(), $request, HttpKernelInterface::MAIN_REQUEST); + $event = new RequestEvent( + self::getService(HttpKernelInterface::class), + $request, + HttpKernelInterface::MAIN_REQUEST + ); $sut = new ReadListener(); $sut($event); @@ -148,7 +152,11 @@ public function testItSucceeds(Request $request): void #[DataProvider('provideRequestsForCasesWithThrownException')] public function testItThrowsException(Request $request): void { - $event = new RequestEvent($this->getKernel(), $request, HttpKernelInterface::MAIN_REQUEST); + $event = new RequestEvent( + self::getService(HttpKernelInterface::class), + $request, + HttpKernelInterface::MAIN_REQUEST + ); $sut = new ReadListener(); $this->expectException(NotFoundHttpException::class); diff --git a/packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/KernelStub.php b/packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/KernelStub.php deleted file mode 100644 index 409e86f93..000000000 --- a/packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/KernelStub.php +++ /dev/null @@ -1,46 +0,0 @@ -configs = $configs ?? []; - - parent::__construct('test', true); - } - - public function process(ContainerBuilder $container): void - { - $container->setDefinition( - 'api_platform.serializer.context_builder', - new Definition(SerializerContextBuilderStub::class) - ); - } - - /** - * @return iterable<\Symfony\Component\HttpKernel\Bundle\BundleInterface> - */ - public function registerBundles(): iterable - { - yield new EasyApiPlatformSymfonyBundle(); - } - - public function registerContainerConfiguration(LoaderInterface $loader): void - { - foreach ($this->configs as $config) { - $loader->load($config); - } - } -} diff --git a/packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/SerializerContextBuilderStub.php b/packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/SerializerContextBuilderStub.php deleted file mode 100644 index 5e72173b2..000000000 --- a/packages/EasyApiPlatform/tests/Bridge/Symfony/Stubs/SerializerContextBuilderStub.php +++ /dev/null @@ -1,15 +0,0 @@ -getContainer()->get('doctrine'); @@ -113,9 +111,4 @@ public function testApply( ); } } - - protected static function createKernel(array $options = []): KernelInterface - { - return new ApplicationKernel('test', false); - } } diff --git a/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php b/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php index 1c5296933..01d4d1455 100644 --- a/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php +++ b/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php @@ -9,9 +9,9 @@ use ApiPlatform\Metadata\Get; use Doctrine\Persistence\ManagerRegistry; use EonX\EasyApiPlatform\Filters\AdvancedSearchFilter; -use EonX\EasyApiPlatform\Tests\Fixtures\App\ApiResource\Dummy; -use EonX\EasyApiPlatform\Tests\Fixtures\App\ApiResource\RelatedDummy; -use EonX\EasyApiPlatform\Tests\Fixtures\App\Serializer\NameConverter\CustomConverter; +use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource\Dummy; +use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource\RelatedDummy; +use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\Serializer\NameConverter\CustomConverter; use Prophecy\Argument; use Prophecy\Prophet; diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php index 4d76fbf55..1737cafc0 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php @@ -42,7 +42,8 @@ $apiPlatformConfig->mapping() ->paths([ - param('kernel.project_dir') . '/src/ApiResource/', + param('kernel.project_dir') . '/src/Case/AdvancedSearchFilter/ApiResource/', + param('kernel.project_dir') . '/src/Case/CustomPaginator/ApiResource/', ]); $apiPlatformConfig->swagger() diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php index 00adbe8c8..cf105d597 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php @@ -19,10 +19,15 @@ $entityManager = $doctrineConfig->orm() ->entityManager('default'); - $entityManager->mapping('AppApiResource') - ->alias('AppApiResource') - ->dir(param('kernel.project_dir') . '/src/ApiResource') + $entityManager->mapping('AppCaseAdvancedSearchFilterApiResource') + ->dir(param('kernel.project_dir') . '/src/Case/AdvancedSearchFilter/ApiResource') ->isBundle(false) - ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\ApiResource') + ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource') + ->type('attribute'); + + $entityManager->mapping('AppCaseCustomPaginatorApiResource') + ->dir(param('kernel.project_dir') . '/src/Case/CustomPaginator/ApiResource') + ->isBundle(false) + ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\CustomPaginator\ApiResource') ->type('attribute'); }; diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/Dummy.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/Dummy.php similarity index 96% rename from packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/Dummy.php rename to packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/Dummy.php index 6e286856d..55d8afc4a 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/Dummy.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/Dummy.php @@ -1,7 +1,7 @@ Several dummies + * @var \Doctrine\Common\Collections\Collection Several dummies */ #[ORM\ManyToMany(targetEntity: RelatedDummy::class)] private Collection $relatedDummies; @@ -169,7 +169,7 @@ public function getNameConverted(): ?string } /** - * @return \Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\Collection */ public function getRelatedDummies(): Collection { diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/DummyFriend.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/DummyFriend.php similarity index 91% rename from packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/DummyFriend.php rename to packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/DummyFriend.php index 28bbd237b..541b920c8 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/DummyFriend.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/DummyFriend.php @@ -1,7 +1,7 @@ + * @var \Doctrine\Common\Collections\Collection */ #[Groups(['fakemanytomany', 'friends'])] #[ORM\OneToMany(mappedBy: 'relatedDummy', targetEntity: RelatedToDummyFriend::class, cascade: ['persist'])] @@ -95,7 +95,7 @@ public function getName(): ?string } /** - * @return \Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\Collection */ public function getRelatedToDummyFriend(): Collection { diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/RelatedOwnedDummy.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php similarity index 93% rename from packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/RelatedOwnedDummy.php rename to packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php index cedbe34e1..0ed40fd82 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/src/ApiResource/RelatedOwnedDummy.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php @@ -1,7 +1,7 @@ id; + } + + public function getTitle(): string + { + return $this->title; + } + + public function setId(int $id): self + { + $this->id = $id; + + return $this; + } + + public function setTitle(string $title): self + { + $this->title = $title; + + return $this; + } +} diff --git a/packages/EasyApiPlatform/tests/Paginators/CustomPaginatorTest.php b/packages/EasyApiPlatform/tests/Paginators/CustomPaginatorTest.php index 9a59e7897..cd49f3773 100644 --- a/packages/EasyApiPlatform/tests/Paginators/CustomPaginatorTest.php +++ b/packages/EasyApiPlatform/tests/Paginators/CustomPaginatorTest.php @@ -3,72 +3,35 @@ namespace EonX\EasyApiPlatform\Tests\Paginators; -use ApiPlatform\Doctrine\Orm\Paginator; -use ArrayIterator; -use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Query; -use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator; -use EonX\EasyApiPlatform\Paginators\CustomPaginator; -use EonX\EasyApiPlatform\Tests\AbstractTestCase; -use Mockery\MockInterface; +use Doctrine\ORM\Tools\SchemaTool; +use EonX\EasyApiPlatform\Tests\AbstractApiTestCase; +use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\CustomPaginator\ApiResource\Category; -final class CustomPaginatorTest extends AbstractTestCase +final class CustomPaginatorTest extends AbstractApiTestCase { public function testCustomPaginator(): void { - $paginator = new CustomPaginator($this->getApiPlatformPaginator()); - - $expectedPagination = [ - 'currentPage' => 1, - 'hasNextPage' => false, - 'hasPreviousPage' => false, - 'itemsPerPage' => 15, - 'totalItems' => 0, - 'totalPages' => 1, - ]; - - self::assertEmpty($paginator->getItems()); - self::assertEquals($expectedPagination, $paginator->getPagination()); - } - - /** - * @return \ApiPlatform\Doctrine\Orm\Paginator - */ - private function getApiPlatformPaginator(): Paginator - { - /** @var \Doctrine\ORM\EntityManagerInterface $manager */ - $manager = self::mock(EntityManagerInterface::class, static function (MockInterface $mock): void { - $mock->shouldReceive('getConfiguration') - ->atLeast() - ->once() - ->withNoArgs() - ->andReturn(new Configuration()); - }); - - $query = new Query($manager); - $query->setFirstResult(1) - ->setMaxResults(15); - - /** @var \Doctrine\ORM\Tools\Pagination\Paginator $doctrinePaginator */ - $doctrinePaginator = self::mock( - DoctrinePaginator::class, - static function (MockInterface $mock) use ($query): void { - $mock->shouldReceive('getQuery') - ->once() - ->withNoArgs() - ->andReturn($query); - $mock->shouldReceive('getIterator') - ->once() - ->withNoArgs() - ->andReturn(new ArrayIterator()); - $mock->shouldReceive('count') - ->once() - ->withNoArgs() - ->andReturn(0); - } + $entityManager = self::getService(EntityManagerInterface::class); + $metaData = $entityManager->getMetadataFactory()->getAllMetadata(); + $schemaTool = new SchemaTool($entityManager); + $schemaTool->updateSchema($metaData); + $entityManager->persist((new Category())->setTitle('Some category')); + $entityManager->flush(); + + $response = self::$client->request('GET', '/categories'); + + $responseData = $response->toArray(false); + self::assertSame( + [ + 'currentPage' => 1, + 'hasNextPage' => false, + 'hasPreviousPage' => false, + 'itemsPerPage' => 25, + 'totalItems' => 1, + 'totalPages' => 1, + ], + $responseData['pagination'] ); - - return new Paginator($doctrinePaginator); } } diff --git a/packages/EasyApiPlatform/tests/Serializers/SerializerContextBuilderTest.php b/packages/EasyApiPlatform/tests/Serializers/SerializerContextBuilderTest.php deleted file mode 100644 index 94425449a..000000000 --- a/packages/EasyApiPlatform/tests/Serializers/SerializerContextBuilderTest.php +++ /dev/null @@ -1,72 +0,0 @@ - [ - 'contextFromDecorated' => [ - 'operation' => new Get(), - ], - 'isGroupAdded' => false, - ]; - - yield 'Group is added' => [ - 'contextFromDecorated' => [ - 'operation' => new GetCollection(), - ], - 'isGroupAdded' => true, - ]; - } - - #[DataProvider('providerTestCreateFromRequest')] - public function testCreateFromRequest(array $contextFromDecorated, bool $isGroupAdded): void - { - $request = new Request(); - $contextBuilder = new SerializerContextBuilder( - $this->mockDecoratedSerializerContextBuilder($contextFromDecorated) - ); - - $context = $contextBuilder->createFromRequest($request, true); - - /** @var string[] $groups */ - $groups = $context['groups'] ?? []; - self::assertSame( - $isGroupAdded, - \in_array(CustomPaginatorInterface::SERIALIZER_GROUP, $groups, true) - ); - } - - private function mockDecoratedSerializerContextBuilder( - array $contextFromDecorated, - ): SerializerContextBuilderInterface { - /** @var \ApiPlatform\Serializer\SerializerContextBuilderInterface $decorated */ - $decorated = self::mock( - SerializerContextBuilderInterface::class, - static function (MockInterface $mock) use ($contextFromDecorated): void { - $mock - ->shouldReceive('createFromRequest') - ->once() - ->andReturn($contextFromDecorated); - } - ); - - return $decorated; - } -} diff --git a/quality/phpstan.neon b/quality/phpstan.neon index 36d2ea872..4f5cdba28 100644 --- a/quality/phpstan.neon +++ b/quality/phpstan.neon @@ -48,7 +48,7 @@ parameters: - message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy\:\:getResourceFromIri\(\)#' path: %currentWorkingDirectory%/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php - - message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy\:\:getId\(\)#' + - message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy\:\:getId\(\)#' path: %currentWorkingDirectory%/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php - message: '#Access to an undefined property EonX\\EasyApiPlatform\\Bridge\\Symfony\\Listeners\\ReadListener\:\:\$resourceMetadataCollectionFactory#' From 2871482e9f901ef225aadffecffcc3e586362490 Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Fri, 31 May 2024 11:05:29 +0200 Subject: [PATCH 2/4] feature/easy-api-platform-refactor-tests --- .../tests/AbstractApiTestCase.php | 11 ++ .../Symfony/Listeners/ReadListenerTest.php | 176 +++--------------- .../app/config/packages/api_platform.php | 1 + .../Fixtures/app/config/packages/doctrine.php | 12 +- .../ReadListener/ApiResource/Question.php | 54 ++++++ .../tests/Paginators/CustomPaginatorTest.php | 5 +- 6 files changed, 105 insertions(+), 154 deletions(-) create mode 100644 packages/EasyApiPlatform/tests/Fixtures/app/src/Case/ReadListener/ApiResource/Question.php diff --git a/packages/EasyApiPlatform/tests/AbstractApiTestCase.php b/packages/EasyApiPlatform/tests/AbstractApiTestCase.php index b53f8253d..3cc992c4b 100644 --- a/packages/EasyApiPlatform/tests/AbstractApiTestCase.php +++ b/packages/EasyApiPlatform/tests/AbstractApiTestCase.php @@ -5,6 +5,8 @@ use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use ApiPlatform\Symfony\Bundle\Test\Client; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Tools\SchemaTool; use EonX\EasyApiPlatform\Tests\Fixtures\App\Kernel\ApplicationKernel; use EonX\EasyTest\Traits\ArrayAssertionTrait; use EonX\EasyTest\Traits\ContainerServiceTrait; @@ -33,4 +35,13 @@ protected static function createKernel(array $options = []): KernelInterface { return new ApplicationKernel('test', false); } + + protected function initDatabase(): void + { + $entityManager = self::getService(EntityManagerInterface::class); + $metaData = $entityManager->getMetadataFactory()->getAllMetadata(); + $schemaTool = new SchemaTool($entityManager); + $schemaTool->dropSchema($metaData); + $schemaTool->updateSchema($metaData); + } } diff --git a/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/ReadListenerTest.php b/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/ReadListenerTest.php index 40ef9e3d8..5b804eb81 100644 --- a/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/ReadListenerTest.php +++ b/packages/EasyApiPlatform/tests/Bridge/Symfony/Listeners/ReadListenerTest.php @@ -3,165 +3,47 @@ namespace EonX\EasyApiPlatform\Tests\Bridge\Symfony\Listeners; -use ApiPlatform\Metadata\Link; -use ApiPlatform\Metadata\NotExposed; -use ApiPlatform\Metadata\Post; use EonX\EasyApiPlatform\Bridge\Symfony\Listeners\ReadListener; -use EonX\EasyApiPlatform\Tests\AbstractTestCase; -use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource\Dummy; -use PHPUnit\Framework\Attributes\DataProvider; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\RequestEvent; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\HttpKernel\HttpKernelInterface; +use EonX\EasyApiPlatform\Tests\AbstractApiTestCase; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; -final class ReadListenerTest extends AbstractTestCase +final class ReadListenerTest extends AbstractApiTestCase { - /** - * @see testItThrowsException - */ - public static function provideRequestsForCasesWithThrownException(): iterable + public function testItSucceeds(): void { - yield 'a request with operation with URI variables' => [ - 'request' => new Request( - attributes: [ - '_api_operation' => new Post(uriVariables: ['id' => new Link()]), - '_api_operation_name' => 'post_dummy', - '_api_resource_class' => Dummy::class, - 'receive' => true, + $this->initDatabase(); + + $response = self::$client->request( + 'POST', + '/questions/1/mark-as-answered', + [ + 'headers' => [ + 'content-type' => 'application/json', ], - server: [ - 'REQUEST_METHOD' => 'POST', - ] - ), - ]; - - yield 'a request with method safe equals to true' => [ - 'request' => new Request( - attributes: [ - '_api_operation' => new Post(uriVariables: []), - '_api_operation_name' => 'post_dummy', - '_api_resource_class' => Dummy::class, - 'receive' => true, - ], - server: [ - 'REQUEST_METHOD' => 'GET', - ] - ), - ]; - } - - /** - * @see testItSucceeds - */ - public static function provideRequestsForSuccessfulCases(): iterable - { - yield 'a request without attributes' => [ - 'request' => new Request( - server: [ - 'REQUEST_METHOD' => 'POST', - ] - ), - ]; - - yield 'a request without "receive" attribute' => [ - 'request' => new Request( - attributes: [ - '_api_operation' => new Post(uriVariables: []), - '_api_operation_name' => 'post_dummy', - '_api_resource_class' => Dummy::class, - ], - server: [ - 'REQUEST_METHOD' => 'POST', - ] - ), - ]; - - yield 'a request with "receive" attribute equals to "false"' => [ - 'request' => new Request( - attributes: [ - '_api_operation' => new Post(uriVariables: []), - '_api_operation_name' => 'post_dummy', - '_api_resource_class' => Dummy::class, - 'receive' => false, - ], - server: [ - 'REQUEST_METHOD' => 'POST', - ] - ), - ]; - - yield 'a request without operation' => [ - 'request' => new Request( - attributes: [ - '_api_operation' => null, - '_api_operation_name' => 'post_dummy', - '_api_resource_class' => Dummy::class, - 'receive' => true, - ], - server: [ - 'REQUEST_METHOD' => 'POST', - ] - ), - ]; - - yield 'a request with operation that cannot read' => [ - 'request' => new Request( - attributes: [ - '_api_operation' => new NotExposed(uriVariables: []), - '_api_operation_name' => 'post_dummy', - '_api_resource_class' => Dummy::class, - 'receive' => true, - ], - server: [ - 'REQUEST_METHOD' => 'POST', - ] - ), - ]; - - yield 'a request with method safe equals to false and with operation without URI variables' => [ - 'request' => new Request( - attributes: [ - '_api_operation' => new Post(uriVariables: []), - '_api_operation_name' => 'post_dummy', - '_api_resource_class' => Dummy::class, - 'receive' => true, - ], - server: [ - 'REQUEST_METHOD' => 'POST', - ] - ), - ]; - } - - #[DataProvider('provideRequestsForSuccessfulCases')] - public function testItSucceeds(Request $request): void - { - $event = new RequestEvent( - self::getService(HttpKernelInterface::class), - $request, - HttpKernelInterface::MAIN_REQUEST + ] ); - $sut = new ReadListener(); - - $sut($event); - self::assertTrue(true); + self::assertSame(404, $response->getStatusCode()); } - #[DataProvider('provideRequestsForCasesWithThrownException')] - public function testItThrowsException(Request $request): void + public function testItSucceedsWithoutReadListener(): void { - $event = new RequestEvent( - self::getService(HttpKernelInterface::class), - $request, - HttpKernelInterface::MAIN_REQUEST + $this->initDatabase(); + self::getService(EventDispatcherInterface::class)->removeListener( + 'kernel.request', + [self::getService(ReadListener::class), '__invoke'] ); - $sut = new ReadListener(); - $this->expectException(NotFoundHttpException::class); - $this->expectExceptionMessage('Not Found'); + $response = self::$client->request( + 'POST', + '/questions/1/mark-as-answered', + [ + 'headers' => [ + 'content-type' => 'application/json', + ], + ] + ); - $sut($event); + self::assertSame(200, $response->getStatusCode()); } } diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php index 1737cafc0..2a360a57a 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php @@ -44,6 +44,7 @@ ->paths([ param('kernel.project_dir') . '/src/Case/AdvancedSearchFilter/ApiResource/', param('kernel.project_dir') . '/src/Case/CustomPaginator/ApiResource/', + param('kernel.project_dir') . '/src/Case/ReadListener/ApiResource/', ]); $apiPlatformConfig->swagger() diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php index cf105d597..d9f6f4260 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php @@ -25,9 +25,15 @@ ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource') ->type('attribute'); - $entityManager->mapping('AppCaseCustomPaginatorApiResource') - ->dir(param('kernel.project_dir') . '/src/Case/CustomPaginator/ApiResource') + $entityManager->mapping('AppCaseAdvancedSearchFilterApiResource') + ->dir(param('kernel.project_dir') . '/src/Case/AdvancedSearchFilter/ApiResource') + ->isBundle(false) + ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource') + ->type('attribute'); + + $entityManager->mapping('AppCaseReadListenerApiResource') + ->dir(param('kernel.project_dir') . '/src/Case/ReadListener/ApiResource') ->isBundle(false) - ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\CustomPaginator\ApiResource') + ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\ReadListener\ApiResource') ->type('attribute'); }; diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/ReadListener/ApiResource/Question.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/ReadListener/ApiResource/Question.php new file mode 100644 index 000000000..35f02802f --- /dev/null +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/ReadListener/ApiResource/Question.php @@ -0,0 +1,54 @@ +id; + } + + public function getQuestion(): string + { + return $this->question; + } + + public function setId(int $id): self + { + $this->id = $id; + + return $this; + } + + public function setQuestion(string $question): self + { + $this->question = $question; + + return $this; + } +} diff --git a/packages/EasyApiPlatform/tests/Paginators/CustomPaginatorTest.php b/packages/EasyApiPlatform/tests/Paginators/CustomPaginatorTest.php index cd49f3773..fecdfd0d6 100644 --- a/packages/EasyApiPlatform/tests/Paginators/CustomPaginatorTest.php +++ b/packages/EasyApiPlatform/tests/Paginators/CustomPaginatorTest.php @@ -4,7 +4,6 @@ namespace EonX\EasyApiPlatform\Tests\Paginators; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Tools\SchemaTool; use EonX\EasyApiPlatform\Tests\AbstractApiTestCase; use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\CustomPaginator\ApiResource\Category; @@ -12,10 +11,8 @@ final class CustomPaginatorTest extends AbstractApiTestCase { public function testCustomPaginator(): void { + $this->initDatabase(); $entityManager = self::getService(EntityManagerInterface::class); - $metaData = $entityManager->getMetadataFactory()->getAllMetadata(); - $schemaTool = new SchemaTool($entityManager); - $schemaTool->updateSchema($metaData); $entityManager->persist((new Category())->setTitle('Some category')); $entityManager->flush(); From 420c62d116adafb08efad748d7476dbbe0d0866b Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Fri, 31 May 2024 11:18:08 +0200 Subject: [PATCH 3/4] -fix CI --- packages/EasyApiPlatform/composer.json | 4 +++- packages/EasyApiPlatform/tests/AbstractApiTestCase.php | 3 ++- .../tests/Fixtures/app/config/packages/doctrine.php | 6 +++--- .../app/src/Case/CustomPaginator/ApiResource/Category.php | 4 ++-- .../app/src/Case/ReadListener/ApiResource/Question.php | 4 ++-- quality/phpstan.neon | 6 ------ 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/EasyApiPlatform/composer.json b/packages/EasyApiPlatform/composer.json index 963fe0c01..7dc528fe1 100644 --- a/packages/EasyApiPlatform/composer.json +++ b/packages/EasyApiPlatform/composer.json @@ -24,7 +24,9 @@ "phpspec/prophecy": "^1.0", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^10.2", - "symfony/symfony": "^6.4" + "symfony/browser-kit": "^6.4", + "symfony/framework-bundle": "^6.4", + "symfony/routing": "^6.4" }, "autoload": { "psr-4": { diff --git a/packages/EasyApiPlatform/tests/AbstractApiTestCase.php b/packages/EasyApiPlatform/tests/AbstractApiTestCase.php index 3cc992c4b..650307774 100644 --- a/packages/EasyApiPlatform/tests/AbstractApiTestCase.php +++ b/packages/EasyApiPlatform/tests/AbstractApiTestCase.php @@ -39,7 +39,8 @@ protected static function createKernel(array $options = []): KernelInterface protected function initDatabase(): void { $entityManager = self::getService(EntityManagerInterface::class); - $metaData = $entityManager->getMetadataFactory()->getAllMetadata(); + $metaData = $entityManager->getMetadataFactory() +->getAllMetadata(); $schemaTool = new SchemaTool($entityManager); $schemaTool->dropSchema($metaData); $schemaTool->updateSchema($metaData); diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php index d9f6f4260..6c04098fa 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php @@ -25,10 +25,10 @@ ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource') ->type('attribute'); - $entityManager->mapping('AppCaseAdvancedSearchFilterApiResource') - ->dir(param('kernel.project_dir') . '/src/Case/AdvancedSearchFilter/ApiResource') + $entityManager->mapping('AppCaseCustomPaginatorApiResource') + ->dir(param('kernel.project_dir') . '/src/Case/CustomPaginator/ApiResource') ->isBundle(false) - ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource') + ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\CustomPaginator\ApiResource') ->type('attribute'); $entityManager->mapping('AppCaseReadListenerApiResource') diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/CustomPaginator/ApiResource/Category.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/CustomPaginator/ApiResource/Category.php index 0be7202ab..136d07673 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/CustomPaginator/ApiResource/Category.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/CustomPaginator/ApiResource/Category.php @@ -11,9 +11,9 @@ #[ORM\Entity] class Category { - #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'AUTO')] #[ORM\Column(type: Types::INTEGER)] + #[ORM\GeneratedValue(strategy: 'AUTO')] + #[ORM\Id] private int $id; #[Orm\Column(type: Types::STRING, nullable: true)] diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/ReadListener/ApiResource/Question.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/ReadListener/ApiResource/Question.php index 35f02802f..6e47a4cc3 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/ReadListener/ApiResource/Question.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/ReadListener/ApiResource/Question.php @@ -20,9 +20,9 @@ #[ORM\Entity] class Question { - #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'AUTO')] #[ORM\Column(type: Types::INTEGER)] + #[ORM\GeneratedValue(strategy: 'AUTO')] + #[ORM\Id] private int $id; #[Orm\Column(type: Types::STRING, nullable: true)] diff --git a/quality/phpstan.neon b/quality/phpstan.neon index 4f5cdba28..39a850087 100644 --- a/quality/phpstan.neon +++ b/quality/phpstan.neon @@ -51,12 +51,6 @@ parameters: - message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy\:\:getId\(\)#' path: %currentWorkingDirectory%/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php - - message: '#Access to an undefined property EonX\\EasyApiPlatform\\Bridge\\Symfony\\Listeners\\ReadListener\:\:\$resourceMetadataCollectionFactory#' - path: %currentWorkingDirectory%/packages/EasyApiPlatform/src/Bridge/Symfony/Listeners/ReadListener.php - - - message: '#Call to an undefined method EonX\\EasyApiPlatform\\Bridge\\Symfony\\Listeners\\ReadListener\:\:initializeOperation\(\)#' - path: %currentWorkingDirectory%/packages/EasyApiPlatform/src/Bridge/Symfony/Listeners/ReadListener.php - # ---- EasyApiToken ---- - message: '#Parameter \#1 \$payload of static method Firebase\\JWT\\JWT\:\:encode\(\) expects array, array\|object given#' path: %currentWorkingDirectory%/packages/EasyApiToken/src/External/FirebaseJwtDriver.php From b92e0db4393d7c6894825291da7a824c1c61e56a Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Thu, 13 Jun 2024 13:39:36 +0200 Subject: [PATCH 4/4] -refactoring --- .../tests/Filters/AbstractFilterTestCase.php | 2 +- .../tests/Filters/AdvancedSearchFilterTest.php | 6 +++--- .../Fixtures/app/config/packages/api_platform.php | 6 +++--- .../tests/Fixtures/app/config/packages/doctrine.php | 12 ++++++------ .../AdvancedSearchFilter/ApiResource/Dummy.php | 6 +++--- .../AdvancedSearchFilter/ApiResource/DummyFriend.php | 2 +- .../ApiResource/EmbeddableDummy.php | 2 +- .../AdvancedSearchFilter/ApiResource/FourthLevel.php | 2 +- .../AdvancedSearchFilter/ApiResource/ParentDummy.php | 2 +- .../ApiResource/RelatedDummy.php | 6 +++--- .../ApiResource/RelatedOwnedDummy.php | 2 +- .../ApiResource/RelatedOwningDummy.php | 2 +- .../ApiResource/RelatedToDummyFriend.php | 2 +- .../AdvancedSearchFilter/ApiResource/ThirdLevel.php | 2 +- .../Serializer/NameConverter/CustomConverter.php | 2 +- .../CustomPaginator/ApiResource/Category.php | 2 +- .../{Case => }/ReadListener/ApiResource/Question.php | 2 +- .../tests/Paginators/CustomPaginatorTest.php | 2 +- quality/phpstan.neon | 2 +- 19 files changed, 32 insertions(+), 32 deletions(-) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/Dummy.php (96%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/DummyFriend.php (91%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/EmbeddableDummy.php (96%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/FourthLevel.php (92%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/ParentDummy.php (84%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/RelatedDummy.php (93%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php (93%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/RelatedOwningDummy.php (93%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/RelatedToDummyFriend.php (95%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/ApiResource/ThirdLevel.php (95%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/AdvancedSearchFilter/Serializer/NameConverter/CustomConverter.php (87%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/CustomPaginator/ApiResource/Category.php (90%) rename packages/EasyApiPlatform/tests/Fixtures/app/src/{Case => }/ReadListener/ApiResource/Question.php (92%) diff --git a/packages/EasyApiPlatform/tests/Filters/AbstractFilterTestCase.php b/packages/EasyApiPlatform/tests/Filters/AbstractFilterTestCase.php index 280c7fc4f..6f7141a54 100644 --- a/packages/EasyApiPlatform/tests/Filters/AbstractFilterTestCase.php +++ b/packages/EasyApiPlatform/tests/Filters/AbstractFilterTestCase.php @@ -9,7 +9,7 @@ use Doctrine\ORM\EntityRepository; use Doctrine\Persistence\ManagerRegistry; use EonX\EasyApiPlatform\Tests\AbstractTestCase; -use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource\Dummy; +use EonX\EasyApiPlatform\Tests\Fixtures\App\AdvancedSearchFilter\ApiResource\Dummy; use PHPUnit\Framework\Attributes\DataProvider; abstract class AbstractFilterTestCase extends AbstractTestCase diff --git a/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php b/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php index 01d4d1455..911881f8c 100644 --- a/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php +++ b/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php @@ -9,9 +9,9 @@ use ApiPlatform\Metadata\Get; use Doctrine\Persistence\ManagerRegistry; use EonX\EasyApiPlatform\Filters\AdvancedSearchFilter; -use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource\Dummy; -use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource\RelatedDummy; -use EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\Serializer\NameConverter\CustomConverter; +use EonX\EasyApiPlatform\Tests\Fixtures\App\AdvancedSearchFilter\ApiResource\Dummy; +use EonX\EasyApiPlatform\Tests\Fixtures\App\AdvancedSearchFilter\ApiResource\RelatedDummy; +use EonX\EasyApiPlatform\Tests\Fixtures\App\AdvancedSearchFilter\Serializer\NameConverter\CustomConverter; use Prophecy\Argument; use Prophecy\Prophet; diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php index 2a360a57a..d5d4870df 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/api_platform.php @@ -42,9 +42,9 @@ $apiPlatformConfig->mapping() ->paths([ - param('kernel.project_dir') . '/src/Case/AdvancedSearchFilter/ApiResource/', - param('kernel.project_dir') . '/src/Case/CustomPaginator/ApiResource/', - param('kernel.project_dir') . '/src/Case/ReadListener/ApiResource/', + param('kernel.project_dir') . '/src/AdvancedSearchFilter/ApiResource/', + param('kernel.project_dir') . '/src/CustomPaginator/ApiResource/', + param('kernel.project_dir') . '/src/ReadListener/ApiResource/', ]); $apiPlatformConfig->swagger() diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php index 6c04098fa..133753add 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/config/packages/doctrine.php @@ -20,20 +20,20 @@ ->entityManager('default'); $entityManager->mapping('AppCaseAdvancedSearchFilterApiResource') - ->dir(param('kernel.project_dir') . '/src/Case/AdvancedSearchFilter/ApiResource') + ->dir(param('kernel.project_dir') . '/src/AdvancedSearchFilter/ApiResource') ->isBundle(false) - ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\AdvancedSearchFilter\ApiResource') + ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\AdvancedSearchFilter\ApiResource') ->type('attribute'); $entityManager->mapping('AppCaseCustomPaginatorApiResource') - ->dir(param('kernel.project_dir') . '/src/Case/CustomPaginator/ApiResource') + ->dir(param('kernel.project_dir') . '/src/CustomPaginator/ApiResource') ->isBundle(false) - ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\CustomPaginator\ApiResource') + ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\CustomPaginator\ApiResource') ->type('attribute'); $entityManager->mapping('AppCaseReadListenerApiResource') - ->dir(param('kernel.project_dir') . '/src/Case/ReadListener/ApiResource') + ->dir(param('kernel.project_dir') . '/src/ReadListener/ApiResource') ->isBundle(false) - ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\Case\ReadListener\ApiResource') + ->prefix('EonX\EasyApiPlatform\Tests\Fixtures\App\ReadListener\ApiResource') ->type('attribute'); }; diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/Dummy.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/Dummy.php similarity index 96% rename from packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/Dummy.php rename to packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/Dummy.php index 55d8afc4a..c060b5ad4 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/Dummy.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/Dummy.php @@ -1,7 +1,7 @@ Several dummies + * @var \Doctrine\Common\Collections\Collection Several dummies */ #[ORM\ManyToMany(targetEntity: RelatedDummy::class)] private Collection $relatedDummies; @@ -169,7 +169,7 @@ public function getNameConverted(): ?string } /** - * @return \Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\Collection */ public function getRelatedDummies(): Collection { diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/DummyFriend.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/DummyFriend.php similarity index 91% rename from packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/DummyFriend.php rename to packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/DummyFriend.php index 541b920c8..104306c14 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/DummyFriend.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/DummyFriend.php @@ -1,7 +1,7 @@ + * @var \Doctrine\Common\Collections\Collection */ #[Groups(['fakemanytomany', 'friends'])] #[ORM\OneToMany(mappedBy: 'relatedDummy', targetEntity: RelatedToDummyFriend::class, cascade: ['persist'])] @@ -95,7 +95,7 @@ public function getName(): ?string } /** - * @return \Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\Collection */ public function getRelatedToDummyFriend(): Collection { diff --git a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php b/packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php similarity index 93% rename from packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php rename to packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php index 0ed40fd82..d576f0449 100644 --- a/packages/EasyApiPlatform/tests/Fixtures/app/src/Case/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php +++ b/packages/EasyApiPlatform/tests/Fixtures/app/src/AdvancedSearchFilter/ApiResource/RelatedOwnedDummy.php @@ -1,7 +1,7 @@ \:\:getResourceFromIri\(\)#' path: %currentWorkingDirectory%/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php - - message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy\:\:getId\(\)#' + - message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy\:\:getId\(\)#' path: %currentWorkingDirectory%/packages/EasyApiPlatform/tests/Filters/AdvancedSearchFilterTest.php # ---- EasyApiToken ----