Select Git revision
ApiTest.php
ApiTest.php 1.94 KiB
<?php
declare(strict_types=1);
namespace Dbp\Relay\ExampleBundle\Tests;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
use Symfony\Component\HttpFoundation\Response;
class ApiTest extends ApiTestCase
{
/**
* You can test some basic api functionality here.
*
* @return void
*
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
*/
public function testBasics()
{
$client = self::createClient();
$response = $client->request('GET', '/example/places');
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
$response = $client->request('GET', '/example/places/graz');
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
$response = $client->request('DELETE', '/example/places/graz');
$this->assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode());
$response = $client->request('PUT', '/example/places/graz', [
'headers' => [
'Content-Type' => 'application/json',
],
'body' => json_encode(['name' => 'foo']),
]);
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
$this->assertSame('foo', json_decode($response->getContent(), true)['name']);
}
/**
* Test if you can access the api without a user.
*
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
*/
public function testNoAuth()
{
$client = self::createClient();
$response = $client->request('GET', '/example/places/graz/loggedin-only');
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
}
}