-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/rekapager package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Rekapager\Tests\IntegrationTests\ApiPlatform; | ||
|
||
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; | ||
|
||
class ApiTest extends ApiTestCase | ||
{ | ||
public function testApiWithCustomProvider(): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$response = $client->request('GET', '/api/custom/posts'); | ||
$this->assertResponseIsSuccessful(); | ||
$this->assertJsonContains([ | ||
'@context' => '/api/contexts/Post', | ||
'@id' => '/api/custom/posts', | ||
'@type' => 'hydra:Collection', | ||
'hydra:view' => [ | ||
'@id' => '/api/custom/posts', | ||
'@type' => 'hydra:PartialCollectionView', | ||
], | ||
]); | ||
|
||
$nextPage = $response->toArray()['hydra:view']['hydra:next'] ?? null; | ||
self::assertNotNull($nextPage); | ||
|
||
$previousPage = $response->toArray()['hydra:view']['hydra:previous'] ?? null; | ||
self::assertNull($previousPage); | ||
|
||
$firstPage = $response->toArray()['hydra:view']['hydra:first'] ?? null; | ||
self::assertNull($firstPage); | ||
|
||
$lastPage = $response->toArray()['hydra:view']['hydra:last'] ?? null; | ||
self::assertNotNull($lastPage); | ||
|
||
// test next page | ||
|
||
$response = $client->request('GET', $nextPage); | ||
Check failure on line 50 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedArgument
Check failure on line 50 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedArgument
|
||
$this->assertResponseIsSuccessful(); | ||
$this->assertJsonContains([ | ||
'@context' => '/api/contexts/Post', | ||
'@id' => '/api/custom/posts', | ||
'@type' => 'hydra:Collection', | ||
'hydra:view' => [ | ||
'@id' => $nextPage, | ||
'@type' => 'hydra:PartialCollectionView', | ||
], | ||
]); | ||
|
||
$nextPage = $response->toArray()['hydra:view']['hydra:next'] ?? null; | ||
Check failure on line 62 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedAssignment
Check failure on line 62 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedAssignment
|
||
self::assertNotNull($nextPage); | ||
|
||
$previousPage = $response->toArray()['hydra:view']['hydra:previous'] ?? null; | ||
Check failure on line 65 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedAssignment
Check failure on line 65 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedAssignment
|
||
self::assertNotNull($previousPage); | ||
|
||
$firstPage = $response->toArray()['hydra:view']['hydra:first'] ?? null; | ||
Check failure on line 68 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedAssignment
Check failure on line 68 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedAssignment
|
||
self::assertNotNull($firstPage); | ||
|
||
$lastPage = $response->toArray()['hydra:view']['hydra:last'] ?? null; | ||
Check failure on line 71 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedAssignment
Check failure on line 71 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedAssignment
|
||
self::assertNotNull($lastPage); | ||
|
||
// test last page | ||
|
||
$response = $client->request('GET', $lastPage); | ||
Check failure on line 76 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedArgument
Check failure on line 76 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedArgument
|
||
$this->assertResponseIsSuccessful(); | ||
$this->assertJsonContains([ | ||
'@context' => '/api/contexts/Post', | ||
'@id' => '/api/custom/posts', | ||
'@type' => 'hydra:Collection', | ||
'hydra:view' => [ | ||
'@id' => $lastPage, | ||
'@type' => 'hydra:PartialCollectionView', | ||
], | ||
]); | ||
|
||
$nextPage = $response->toArray()['hydra:view']['hydra:next'] ?? null; | ||
Check failure on line 88 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedAssignment
Check failure on line 88 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedAssignment
|
||
self::assertNull($nextPage); | ||
|
||
$previousPage = $response->toArray()['hydra:view']['hydra:previous'] ?? null; | ||
Check failure on line 91 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedAssignment
Check failure on line 91 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedAssignment
|
||
self::assertNotNull($previousPage); | ||
|
||
$firstPage = $response->toArray()['hydra:view']['hydra:first'] ?? null; | ||
Check failure on line 94 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedAssignment
Check failure on line 94 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedAssignment
|
||
self::assertNotNull($firstPage); | ||
|
||
$lastPage = $response->toArray()['hydra:view']['hydra:last'] ?? null; | ||
Check failure on line 97 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.2, ubuntu-latestMixedAssignment
Check failure on line 97 in tests/src/IntegrationTests/ApiPlatform/ApiTest.php GitHub Actions / Symfony 7.*, highest deps, PHP 8.3, ubuntu-latestMixedAssignment
|
||
self::assertNull($lastPage); | ||
} | ||
} |