Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/http/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testHandleExceptionWithGenericException(): void
);
}

#[TestWith(['apache'])]
#[TestWith(['apache2handler'])]
#[TestWith(['cli'])]
public function testHandleExceptionWithHttpException(string $sapi): void
{
Expand Down
54 changes: 54 additions & 0 deletions tests/http/StatelessApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use yii2\extensions\psrbridge\http\{ErrorHandler, Request, Response};
use yii2\extensions\psrbridge\tests\provider\StatelessApplicationProvider;
use yii2\extensions\psrbridge\tests\support\FactoryHelper;
use yii2\extensions\psrbridge\tests\support\stub\HTTPFunctions;
use yii2\extensions\psrbridge\tests\TestCase;

use function array_fill;
Expand Down Expand Up @@ -50,6 +51,8 @@ protected function tearDown(): void
{
$this->closeApplication();

HTTPFunctions::reset();

parent::tearDown();
}

Expand Down Expand Up @@ -724,6 +727,57 @@ public function testRecalculateMemoryLimitAfterResetAndIniChange(): void
ini_set('memory_limit', $originalLimit);
}

public function testRenderExceptionWithRawFormat(): void
{
HTTPFunctions::set_sapi('apache2handler');

$_SERVER = [
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => 'site/trigger-exception',
];

$request = FactoryHelper::createServerRequestCreator()->createFromGlobals();

$app = $this->statelessApplication(
[
'components' => [
'response' => [
'format' => Response::FORMAT_RAW,
],
'errorHandler' => [
'errorAction' => null,
],
],
],
);

$response = $app->handle($request);

self::assertSame(
500,
$response->getStatusCode(),
"Response 'status code' should be '500' for exception with RAW format.",
);

$body = $response->getBody()->getContents();

self::assertStringContainsString(
'yii\base\Exception',
$body,
'RAW format response should contain exception class name.',
);
self::assertStringContainsString(
'Exception error message.',
$body,
'RAW format response should contain exception message.',
);
self::assertStringNotContainsString(
'<pre>',
$body,
'RAW format response should not contain HTML tags.',
);
}

/**
* @throws InvalidConfigException if the configuration is invalid or incomplete.
*/
Expand Down
Loading