Tests / PHP 8.4 (push) Failing after 1m26s
Drop support for PHP 8.3 and lower. The package now declares >=8.4, and CI runs only on 8.4. - composer.json: require php >=8.4. - mago.toml: php-version = "8.4", matching the minimum supported version. - phpstan.neon: phpVersion 80400. - Upgrade phpstan/phpstan to ^2.3: 1.x cannot parse `new Foo()->bar()`, which the 8.4 formatter now emits. - Narrow ArrayGateway::count() to int, matching what the fixture actually returns. - CI: single PHP 8.4 job using the php:8.4-cli container instead of setup-php, which failed with a TLS handshake timeout on the runner. BREAKING CHANGE: PHP 8.4 is now required.
63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Camelia\Controllers\Tests\Unit;
|
|
|
|
use Camelia\Controllers\JsonRequest;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class JsonRequestTest extends TestCase
|
|
{
|
|
public function testReadsInjectedArraysOnly(): void
|
|
{
|
|
$request = new JsonRequest(
|
|
method: 'post',
|
|
path: '/articulos',
|
|
query: ['page' => '2'],
|
|
body: ['nombre' => 'Taladro'],
|
|
);
|
|
|
|
self::assertSame('POST', $request->method());
|
|
self::assertSame('/articulos', $request->path());
|
|
self::assertSame('2', $request->query('page'));
|
|
self::assertSame(['nombre' => 'Taladro'], $request->body());
|
|
}
|
|
|
|
public function testQueryFallsBackToDefault(): void
|
|
{
|
|
$request = new JsonRequest();
|
|
|
|
self::assertNull($request->query('missing'));
|
|
self::assertSame('x', $request->query('missing', 'x'));
|
|
}
|
|
|
|
public function testHeaderLookupIsCaseInsensitive(): void
|
|
{
|
|
$request = new JsonRequest(headers: ['accept' => 'application/json']);
|
|
|
|
self::assertSame('application/json', $request->header('Accept'));
|
|
self::assertSame('application/json', $request->header('ACCEPT'));
|
|
self::assertNull($request->header('X-Missing'));
|
|
}
|
|
|
|
public function testWithAttributeIsImmutable(): void
|
|
{
|
|
$original = new JsonRequest(path: '/articulos');
|
|
$withId = $original->withAttribute('id', '7');
|
|
|
|
self::assertNull($original->attribute('id'));
|
|
self::assertSame('7', $withId->attribute('id'));
|
|
}
|
|
|
|
public function testWithAttributeKeepsPreviousAttributes(): void
|
|
{
|
|
$request = new JsonRequest()
|
|
->withAttribute('a', '1')
|
|
->withAttribute('b', '2');
|
|
|
|
self::assertSame('1', $request->attribute('a'));
|
|
self::assertSame('2', $request->attribute('b'));
|
|
}
|
|
}
|