From 43bae7751c1244549bf6b4869223147ab09f2e10 Mon Sep 17 00:00:00 2001 From: Maxime Date: Fri, 7 Nov 2025 08:36:58 +0100 Subject: [PATCH 1/3] test: partial pagination itemcount --- .../TestBundle/Entity/Issue7349/Foo7349.php | 48 ++++++++++++ tests/Functional/Issues/Issue7349Test.php | 74 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/Fixtures/TestBundle/Entity/Issue7349/Foo7349.php create mode 100644 tests/Functional/Issues/Issue7349Test.php diff --git a/tests/Fixtures/TestBundle/Entity/Issue7349/Foo7349.php b/tests/Fixtures/TestBundle/Entity/Issue7349/Foo7349.php new file mode 100644 index 00000000000..614fa6fd8a0 --- /dev/null +++ b/tests/Fixtures/TestBundle/Entity/Issue7349/Foo7349.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7349; + +use ApiPlatform\Metadata\ApiResource; +use Doctrine\ORM\Mapping as ORM; + +#[ORM\Entity] +#[ApiResource] +class Foo7349 +{ + /** + * @var ?int id + */ + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'AUTO')] + #[ORM\Column(type: 'integer')] + private ?int $id = null; + + #[ORM\Column(type: 'string', length: 255)] + private string $name; + + public function getId(): ?int + { + return $this->id; + } + + public function getName(): string + { + return $this->name; + } + + public function setName(string $name): void + { + $this->name = $name; + } +} diff --git a/tests/Functional/Issues/Issue7349Test.php b/tests/Functional/Issues/Issue7349Test.php new file mode 100644 index 00000000000..5d92418bc33 --- /dev/null +++ b/tests/Functional/Issues/Issue7349Test.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Functional\Issues; + +use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; +use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7349\Foo7349; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; + +class Issue7349Test extends ApiTestCase +{ + protected static ?bool $alwaysBootKernel = false; + + public static function getResources(): array + { + return [Foo7349::class]; + } + + /** + * When using partial pagination, totalItems should not be present. + * + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testGetPartialNoItemCount(): void + { + $response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3&partial=true', [ + 'headers' => [ + 'Accept' => 'application/ld+json', + ], + ]); + var_dump($response->toArray()); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertArrayNotHasKey('hydra:totalItems', $response->toArray()); + } + + /** + * When not using partial pagination, totalItems should be present. + * + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testGetNoItemCount(): void + { + $response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3', [ + 'headers' => [ + 'Accept' => 'application/ld+json', + ], + ]); + var_dump($response->toArray()); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertArrayHasKey('hydra:totalItems', $response->toArray()); + } +} From 8c9316aa86558a3fb5c38077d8d95874fe920075 Mon Sep 17 00:00:00 2001 From: Maxime Date: Fri, 7 Nov 2025 12:08:05 +0100 Subject: [PATCH 2/3] test: skip when not mongodb --- .../Issue7349/Foo7349.php | 22 +++++++----- tests/Functional/Issues/Issue7349Test.php | 34 +++++++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) rename tests/Fixtures/TestBundle/{Entity => Document}/Issue7349/Foo7349.php (65%) diff --git a/tests/Fixtures/TestBundle/Entity/Issue7349/Foo7349.php b/tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php similarity index 65% rename from tests/Fixtures/TestBundle/Entity/Issue7349/Foo7349.php rename to tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php index 614fa6fd8a0..461307b2a94 100644 --- a/tests/Fixtures/TestBundle/Entity/Issue7349/Foo7349.php +++ b/tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php @@ -11,24 +11,28 @@ declare(strict_types=1); -namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7349; +namespace ApiPlatform\Tests\Fixtures\TestBundle\Document\Issue7349; use ApiPlatform\Metadata\ApiResource; -use Doctrine\ORM\Mapping as ORM; +use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; + +/** + * Foo7349. + * + * @author Maxime Valin + */ -#[ORM\Entity] #[ApiResource] +#[ODM\Document] class Foo7349 { /** - * @var ?int id + * @var int id */ - #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'AUTO')] - #[ORM\Column(type: 'integer')] - private ?int $id = null; + #[ODM\Id(type: 'int', strategy: 'INCREMENT')] + private int $id; - #[ORM\Column(type: 'string', length: 255)] + #[ODM\Field(type: 'string')] private string $name; public function getId(): ?int diff --git a/tests/Functional/Issues/Issue7349Test.php b/tests/Functional/Issues/Issue7349Test.php index 5d92418bc33..312e78ba8c5 100644 --- a/tests/Functional/Issues/Issue7349Test.php +++ b/tests/Functional/Issues/Issue7349Test.php @@ -14,7 +14,10 @@ namespace ApiPlatform\Tests\Functional\Issues; use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; -use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7349\Foo7349; +use ApiPlatform\Tests\RecreateSchemaTrait; +use Illuminate\Foundation\Testing\RefreshDatabase; +use Orchestra\Testbench\Concerns\WithWorkbench; +use Orchestra\Testbench\TestCase; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; @@ -23,30 +26,24 @@ class Issue7349Test extends ApiTestCase { - protected static ?bool $alwaysBootKernel = false; - - public static function getResources(): array - { - return [Foo7349::class]; - } + use RecreateSchemaTrait; + use WithWorkbench; + use RefreshDatabase; /** * When using partial pagination, totalItems should not be present. - * - * @throws RedirectionExceptionInterface - * @throws DecodingExceptionInterface - * @throws ClientExceptionInterface - * @throws TransportExceptionInterface - * @throws ServerExceptionInterface */ public function testGetPartialNoItemCount(): void { - $response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3&partial=true', [ + if (!$this->isMongoDB()) { + $this->markTestSkipped(); + } + + $response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3', [ 'headers' => [ 'Accept' => 'application/ld+json', ], ]); - var_dump($response->toArray()); $this->assertEquals(200, $response->getStatusCode()); $this->assertArrayNotHasKey('hydra:totalItems', $response->toArray()); } @@ -60,14 +57,17 @@ public function testGetPartialNoItemCount(): void * @throws TransportExceptionInterface * @throws ServerExceptionInterface */ - public function testGetNoItemCount(): void + public function testGetItemCount(): void { + if (!$this->isMongoDB()) { + $this->markTestSkipped(); + } + $response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3', [ 'headers' => [ 'Accept' => 'application/ld+json', ], ]); - var_dump($response->toArray()); $this->assertEquals(200, $response->getStatusCode()); $this->assertArrayHasKey('hydra:totalItems', $response->toArray()); } From b05b425234fc5770ac83ef1096820e2e8bbb19ba Mon Sep 17 00:00:00 2001 From: Maxime Date: Fri, 7 Nov 2025 13:47:28 +0100 Subject: [PATCH 3/3] fix: cs fixer --- tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php | 1 - tests/Functional/Issues/Issue7349Test.php | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php b/tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php index 461307b2a94..bed74e5eecf 100644 --- a/tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php +++ b/tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php @@ -21,7 +21,6 @@ * * @author Maxime Valin */ - #[ApiResource] #[ODM\Document] class Foo7349 diff --git a/tests/Functional/Issues/Issue7349Test.php b/tests/Functional/Issues/Issue7349Test.php index 312e78ba8c5..d81fd82c4f2 100644 --- a/tests/Functional/Issues/Issue7349Test.php +++ b/tests/Functional/Issues/Issue7349Test.php @@ -17,7 +17,6 @@ use ApiPlatform\Tests\RecreateSchemaTrait; use Illuminate\Foundation\Testing\RefreshDatabase; use Orchestra\Testbench\Concerns\WithWorkbench; -use Orchestra\Testbench\TestCase; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; @@ -27,8 +26,8 @@ class Issue7349Test extends ApiTestCase { use RecreateSchemaTrait; - use WithWorkbench; use RefreshDatabase; + use WithWorkbench; /** * When using partial pagination, totalItems should not be present.