Phred/tests/Feature/CompressionMiddlewareTest.php
Funky Waddle 54303282d7
Some checks failed
CI / PHP ${{ matrix.php }} (8.1) (push) Has been cancelled
CI / PHP ${{ matrix.php }} (8.2) (push) Has been cancelled
CI / PHP ${{ matrix.php }} (8.3) (push) Has been cancelled
Too many things
2026-01-06 11:02:05 -06:00

49 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Phred\Tests\Feature;
use PHPUnit\Framework\TestCase;
use Phred\Http\Kernel;
use Nyholm\Psr7\ServerRequest;
class CompressionMiddlewareTest extends TestCase
{
protected function tearDown(): void
{
putenv('COMPRESSION_ENABLED');
\Phred\Support\Config::clear();
}
public function test_compression_is_applied_when_enabled(): void
{
if (!function_exists('gzencode')) {
$this->markTestSkipped('gzencode not available');
}
putenv('COMPRESSION_ENABLED=true');
$kernel = new Kernel();
$request = (new ServerRequest('GET', '/_phred/health'))
->withHeader('Accept-Encoding', 'gzip');
$response = $kernel->handle($request);
$this->assertEquals('gzip', $response->getHeaderLine('Content-Encoding'));
$this->assertNotEmpty($response->getBody()->getContents());
}
public function test_compression_is_not_applied_when_disabled(): void
{
putenv('COMPRESSION_ENABLED=false');
$kernel = new Kernel();
$request = (new ServerRequest('GET', '/_phred/health'))
->withHeader('Accept-Encoding', 'gzip');
$response = $kernel->handle($request);
$this->assertFalse($response->hasHeader('Content-Encoding'));
}
}