Describe entities as API Platform resources

This commit is contained in:
2024-06-05 17:37:53 +02:00
parent 48bc5fd8c3
commit 22be991b8c
16 changed files with 621 additions and 1 deletions

31
tests/Api/UserApiTest.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
namespace App\Tests\Api;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
class UserApiTest extends ApiTestCase
{
public function testInsertUser(): void
{
$response = static::createClient()->request('POST', '/api/users', [
'json' => [
'email' => 'test@test.com',
'plainPassword' => 'password',
]
]);
$this->assertResponseStatusCodeSame(201);
$this->assertResponseHasHeader('Content-Location');
$location = $response->getHeaders()['content-location'][0];
static::createClient()->request('GET', $location);
$this->assertResponseIsSuccessful();
$this->assertJsonEquals([
'@context' => '/api/contexts/User',
'@id' => $location,
'@type' => 'User',
'email' => 'test@test.com',
]);
}
}