Added test for weird edge case (which isn't triggering awesome).

This commit is contained in:
flash 2025-03-21 00:04:27 +00:00
parent 7521d0ee82
commit 1ee6dc8115
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
2 changed files with 19 additions and 2 deletions

View file

@ -1 +1 @@
0.2503.202342
0.2503.210003

View file

@ -1,7 +1,7 @@
<?php
// RouterTest.php
// Created: 2022-01-20
// Updated: 2025-03-19
// Updated: 2025-03-21
declare(strict_types=1);
@ -254,6 +254,19 @@ final class RouterTest extends TestCase {
public function testOutputBencode(): array {
return ['benben' => 12345];
}
#[After('output:bencode')]
#[ExactRoute('GET', '/output/bencode/object')]
public function testOutputBencodeObject(): object {
return new class implements \Index\Bencode\BencodeSerializable {
use \Index\Bencode\BencodeSerializableCommon;
public function __construct(
#[\Index\Bencode\BencodeProperty('failure reason')]
public private(set) string $reason = 'Invalid info hash.'
) {}
};
}
});
$response = $router->handle(HttpRequest::createRequestWithoutBody('GET', '/output/stream'));
@ -288,6 +301,10 @@ final class RouterTest extends TestCase {
$this->assertSame('application/x-bittorrent', $response->getHeaderLine('Content-Type'));
$this->assertSame('d6:benbeni12345ee', (string)$response->getBody());
$response = $router->handle(HttpRequest::createRequestWithoutBody('GET', '/output/bencode/object'));
$this->assertSame('application/x-bittorrent', $response->getHeaderLine('Content-Type'));
$this->assertSame('d14:failure reason18:Invalid info hash.e', (string)$response->getBody());
$response = $router->handle(HttpRequest::createRequestWithoutBody('POST', '/optional-form'));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('none', (string)$response->getBody());