Skip to content

Commit a7e5240

Browse files
authored
test: partial pagination itemcount (#7513)
1 parent 8bdb2bc commit a7e5240

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\Document\Issue7349;
15+
16+
use ApiPlatform\Metadata\ApiResource;
17+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
18+
19+
/**
20+
* Foo7349.
21+
*
22+
* @author Maxime Valin <contact@maximeval.in>
23+
*/
24+
#[ApiResource]
25+
#[ODM\Document]
26+
class Foo7349
27+
{
28+
/**
29+
* @var int id
30+
*/
31+
#[ODM\Id(type: 'int', strategy: 'INCREMENT')]
32+
private int $id;
33+
34+
#[ODM\Field(type: 'string')]
35+
private string $name;
36+
37+
public function getId(): ?int
38+
{
39+
return $this->id;
40+
}
41+
42+
public function getName(): string
43+
{
44+
return $this->name;
45+
}
46+
47+
public function setName(string $name): void
48+
{
49+
$this->name = $name;
50+
}
51+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Functional\Issues;
15+
16+
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
17+
use ApiPlatform\Tests\RecreateSchemaTrait;
18+
use Illuminate\Foundation\Testing\RefreshDatabase;
19+
use Orchestra\Testbench\Concerns\WithWorkbench;
20+
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
21+
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
22+
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
23+
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
24+
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
25+
26+
class Issue7349Test extends ApiTestCase
27+
{
28+
use RecreateSchemaTrait;
29+
use RefreshDatabase;
30+
use WithWorkbench;
31+
32+
/**
33+
* When using partial pagination, totalItems should not be present.
34+
*/
35+
public function testGetPartialNoItemCount(): void
36+
{
37+
if (!$this->isMongoDB()) {
38+
$this->markTestSkipped();
39+
}
40+
41+
$response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3', [
42+
'headers' => [
43+
'Accept' => 'application/ld+json',
44+
],
45+
]);
46+
$this->assertEquals(200, $response->getStatusCode());
47+
$this->assertArrayNotHasKey('hydra:totalItems', $response->toArray());
48+
}
49+
50+
/**
51+
* When not using partial pagination, totalItems should be present.
52+
*
53+
* @throws RedirectionExceptionInterface
54+
* @throws DecodingExceptionInterface
55+
* @throws ClientExceptionInterface
56+
* @throws TransportExceptionInterface
57+
* @throws ServerExceptionInterface
58+
*/
59+
public function testGetItemCount(): void
60+
{
61+
if (!$this->isMongoDB()) {
62+
$this->markTestSkipped();
63+
}
64+
65+
$response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3', [
66+
'headers' => [
67+
'Accept' => 'application/ld+json',
68+
],
69+
]);
70+
$this->assertEquals(200, $response->getStatusCode());
71+
$this->assertArrayHasKey('hydra:totalItems', $response->toArray());
72+
}
73+
}

0 commit comments

Comments
 (0)