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
27 changes: 27 additions & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,33 @@ protected function tearDown(): void
}
}

public function testItDoesNotDisplayGifWhenDebugIsDisabled(): void
{
$client = static::createClient(['environment' => 'dev', 'debug' => false]);

$client->request('GET', '/error-404');
$response = $client->getResponse();

self::assertSame(404, $response->getStatusCode());
self::assertStringNotContainsString('data-gif', (string) $response->getContent());
self::assertFalse(static::getContainer()->has('gif_exception.listener.replace_image'));
}

public function testItFallsBackToOtherGifsForNonHttpExceptions(): void
{
$client = static::createClient(['environment' => 'dev', 'debug' => true]);

$client->request('GET', '/database-error');
$response = $client->getResponse();

self::assertSame(500, $response->getStatusCode());

$image = $this->getImage((string) $response->getContent());

self::assertTrue($image->hasAttribute('data-gif'), 'Image was not replaced.');
self::assertStringMatchesFormat('%s/gifexception/images/other/%s.gif', $image->getAttribute('src'));
}

public function testItDoesNotDisplayGifOnExceptionPageIfTheBundleIsNotEnabled(): void
{
$client = static::createClient(['environment' => 'prod', 'debug' => true]);
Expand Down
3 changes: 3 additions & 0 deletions tests/app/config/routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
->requirements(['status' => '\d+'])
->defaults(['_controller' => 'Joli\GifExceptionBundle\Tests\app\src\TestController::errorAction'])
;
$routes->add('test_routing_database_error', '/database-error')
->defaults(['_controller' => 'Joli\GifExceptionBundle\Tests\app\src\TestController::databaseErrorAction'])
;

try {
$routes->import('@WebProfilerBundle/Resources/config/routing/wdt.xml')
Expand Down
8 changes: 8 additions & 0 deletions tests/app/src/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public function errorAction(Request $request): void

throw new HttpException($statusCode, \sprintf('This is HTTP %s error page!', $statusCode));
}

public function databaseErrorAction(): void
{
// Mimic a PDOException whose code is a SQLSTATE string, not an int
throw new class('Database is on fire!') extends \PDOException {
protected $code = 'HY000';
};
}
}
Loading