jetzt auch mit einheitstests
This commit is contained in:
parent
d68e7f45b3
commit
e883913d3a
10 changed files with 3952 additions and 16 deletions
57
tests/Unit/PlaintextResponseTest.php
Normal file
57
tests/Unit/PlaintextResponseTest.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\PlaintextResponse;
|
||||
|
||||
covers(PlaintextResponse::class);
|
||||
test('it sets content-type to text/plain by default', function (): void {
|
||||
$response = new PlaintextResponse('Hello, World!');
|
||||
|
||||
expect($response->headers->get('Content-Type'))->toBe('text/plain');
|
||||
});
|
||||
|
||||
test('it allows custom content-type to be set', function (): void {
|
||||
$response = new PlaintextResponse('Hello, World!', 200, [
|
||||
'Content-Type' => 'application/json',
|
||||
]);
|
||||
|
||||
expect($response->headers->get('Content-Type'))->toBe('application/json');
|
||||
});
|
||||
|
||||
test('it sets content correctly', function (): void {
|
||||
$content = 'Hello, World!';
|
||||
$response = new PlaintextResponse($content);
|
||||
|
||||
expect($response->getContent())->toBe($content);
|
||||
});
|
||||
|
||||
test('it sets status code correctly', function (): void {
|
||||
$status = 201;
|
||||
$response = new PlaintextResponse('Hello, World!', $status);
|
||||
|
||||
expect($response->getStatusCode())->toBe($status);
|
||||
});
|
||||
|
||||
test('it sets headers correctly', function (): void {
|
||||
$headers = [
|
||||
'X-Custom-Header' => 'Custom Value',
|
||||
'X-Another-Header' => 'Another Value',
|
||||
];
|
||||
$response = new PlaintextResponse('Hello, World!', 200, $headers);
|
||||
|
||||
foreach ($headers as $key => $value) {
|
||||
expect($response->headers->get($key))->toBe($value);
|
||||
}
|
||||
});
|
||||
|
||||
test('it handles null content', function (): void {
|
||||
$response = new PlaintextResponse(null);
|
||||
|
||||
expect($response->getContent())->toBe('');
|
||||
});
|
||||
|
||||
test('it has correct defaultstatuscode', function (): void {
|
||||
$response = new PlaintextResponse('Hello, World!');
|
||||
expect($response->getStatusCode())->toBe(200);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue