-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathVersionControllerTest.php
67 lines (56 loc) · 1.96 KB
/
VersionControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace App\Tests\Application\Tool\Transport\Controller\Api;
use App\General\Domain\Utils\JSON;
use App\Log\Application\Resource\LogRequestResource;
use App\Tests\TestCase\WebTestCase;
use PHPUnit\Framework\Attributes\TestDox;
use Symfony\Component\HttpFoundation\Response;
use Throwable;
use function file_get_contents;
/**
* @package App\Tests
*/
class VersionControllerTest extends WebTestCase
{
private string $baseUrl = self::API_URL_PREFIX . '/version';
/**
* @throws Throwable
*/
#[TestDox('Test that version route returns success response.')]
public function testThatVersionRouteReturns200(): void
{
$client = $this->getTestClient();
$client->request('GET', $this->baseUrl);
$response = $client->getResponse();
static::assertSame(Response::HTTP_OK, $response->getStatusCode(), "Response:\n" . $response);
}
/**
* @throws Throwable
*/
#[TestDox('Test that version route does not make request log.')]
public function testThatVersionRouteDoesNotMakeRequestLog(): void
{
$resource = static::getContainer()->get(LogRequestResource::class);
$expectedLogCount = $resource->count();
$client = $this->getTestClient();
$client->request('GET', $this->baseUrl);
static::assertSame($expectedLogCount, $resource->count());
}
/**
* @throws Throwable
*/
#[TestDox('Test that `X-API-VERSION` is added to response headers.')]
public function testThatApiVersionIsAddedToResponseHeaders(): void
{
$client = $this->getTestClient();
$client->request('GET', $this->baseUrl);
$response = $client->getResponse();
$version = $response->headers->get('X-API-VERSION');
static::assertNotNull($version);
static::assertSame(
JSON::decode((string)file_get_contents(__DIR__ . '/../../../../../../composer.json'))->version,
$version,
);
}
}