Skip to content

Commit

Permalink
Merge 13b786f into 1dedd25
Browse files Browse the repository at this point in the history
  • Loading branch information
Starli0n committed Sep 12, 2016
2 parents 1dedd25 + 13b786f commit 3980065
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Slim/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Slim;

use Exception;
use Throwable;
use InvalidArgumentException;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -324,6 +325,11 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
ob_start();
$newResponse = $handler($this->callable, $request, $response, $this->arguments);
$output = ob_get_clean();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
ob_end_clean();
throw $e;
// @codeCoverageIgnoreEnd
} catch (Exception $e) {
ob_end_clean();
throw $e;
Expand Down
43 changes: 41 additions & 2 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1589,15 +1589,15 @@ public function testRespondIndeterminateLength()
$app->respond($response);
$this->expectOutputString("Hello");
}

public function testResponseWithStreamReadYieldingLessBytesThanAsked()
{
$app = new App([
'settings' => ['responseChunkSize' => Mocks\SmallChunksStream::CHUNK_SIZE * 2]
]);
$app->get('/foo', function ($req, $res) {
$res->write('Hello');

return $res;
});

Expand Down Expand Up @@ -1660,6 +1660,45 @@ public function testExceptionErrorHandlerDoesNotDisplayErrorDetails()
$this->assertNotRegExp('/.*middleware exception.*/', (string)$resOut);
}

/**
* @requires PHP 7.0
*/
public function testExceptionPhpErrorHandlerDoesNotDisplayErrorDetails()
{
$app = new App();

// Prepare request and response objects
$env = Environment::mock([
'SCRIPT_NAME' => '/index.php',
'REQUEST_URI' => '/foo',
'REQUEST_METHOD' => 'GET',
]);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new Body(fopen('php://temp', 'r+'));
$req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$res = new Response();
$app->getContainer()['request'] = $req;
$app->getContainer()['response'] = $res;

$mw = function ($req, $res, $next) {
dumpFonction();
};

$app->add($mw);

$app->get('/foo', function ($req, $res) {
return $res;
});

$resOut = $app->run(true);

$this->assertEquals(500, $resOut->getStatusCode());
$this->assertNotRegExp('/.*middleware exception.*/', (string)$resOut);
}

public function appFactory()
{
$app = new App();
Expand Down

0 comments on commit 3980065

Please sign in to comment.