|
| 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