Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/Fixtures/TestBundle/Document/Issue7349/Foo7349.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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\Document\Issue7349;

use ApiPlatform\Metadata\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* Foo7349.
*
* @author Maxime Valin <contact@maximeval.in>
*/
#[ApiResource]
#[ODM\Document]
class Foo7349
{
/**
* @var int id
*/
#[ODM\Id(type: 'int', strategy: 'INCREMENT')]
private int $id;

#[ODM\Field(type: 'string')]
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;
}
}
73 changes: 73 additions & 0 deletions tests/Functional/Issues/Issue7349Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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\RecreateSchemaTrait;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Orchestra\Testbench\Concerns\WithWorkbench;
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
{
use RecreateSchemaTrait;
use RefreshDatabase;
use WithWorkbench;

/**
* When using partial pagination, totalItems should not be present.
*/
public function testGetPartialNoItemCount(): void
{
if (!$this->isMongoDB()) {
$this->markTestSkipped();
}

$response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3', [
'headers' => [
'Accept' => 'application/ld+json',
],
]);
$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 testGetItemCount(): void
{
if (!$this->isMongoDB()) {
$this->markTestSkipped();
}

$response = self::createClient()->request('GET', '/foo7349s?page=1&itemsPerPage=3', [
'headers' => [
'Accept' => 'application/ld+json',
],
]);
$this->assertEquals(200, $response->getStatusCode());
$this->assertArrayHasKey('hydra:totalItems', $response->toArray());
}
}
Loading