Skip to content

Commit 950c441

Browse files
author
Ryan
committed
Revert PR #31 - Output buffering in error handlers
As of Slim 3.9 the output buffering was moved from the error handler (as an argument) and into the main Slim app. **IMPORTANT NOTE**: Slim-Bridge `composer.json` indicated a dependency on Slim ^3.4.0 ==> This PR changes the dependency to ^3.9.0 The PR #31 added the output buffering argument in slim-bridge. This PR reverts PR #31 and modifies the unit tests to validate the change to error handling. Closes #33
1 parent 2f7dc12 commit 950c441

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"php": "~5.5|~7.0",
1818
"php-di/php-di": "^5.2.0",
1919
"php-di/invoker": "^1.2.0",
20-
"slim/slim": "^3.4.0"
20+
"slim/slim": "^3.9.0"
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "~4.8.36"

src/config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
->method('setCacheFile', DI\get('settings.routerCacheFile')),
4040
Slim\Router::class => DI\get('router'),
4141
'errorHandler' => DI\object(Slim\Handlers\Error::class)
42-
->constructor(DI\get('settings.displayErrorDetails'), DI\get('settings.outputBuffering')),
42+
->constructor(DI\get('settings.displayErrorDetails')),
4343
'phpErrorHandler' => DI\object(Slim\Handlers\PhpError::class)
44-
->constructor(DI\get('settings.displayErrorDetails'), DI\get('settings.outputBuffering')),
44+
->constructor(DI\get('settings.displayErrorDetails')),
4545
'notFoundHandler' => DI\object(Slim\Handlers\NotFound::class),
4646
'notAllowedHandler' => DI\object(Slim\Handlers\NotAllowed::class),
4747
'environment' => function () {

tests/ErrorTest.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPUnit\Framework\TestCase;
99
use DI\Bridge\Slim\Test\Mock\RequestFactory;
1010
use Slim\Http\Response;
11-
use Throwable;
1211

1312
class ErrorTest extends TestCase
1413
{
@@ -32,7 +31,7 @@ public function default_exception_handling()
3231

3332
/** @var Error $error */
3433
$error = $c->get('errorHandler');
35-
$response = $error(RequestFactory::create('/'), new Response(), new TestException());
34+
$response = $error(RequestFactory::create('/'), new Response(), new \Exception());
3635
$reasonPhrase = $response->getReasonPhrase();
3736
$this->assertEquals('Internal Server Error', $reasonPhrase);
3837

@@ -52,10 +51,10 @@ public function custom_exception_handling()
5251
ini_set('error_log', $logFile);
5352

5453
$app = new BridgeApp(
55-
[
56-
'settings.displayErrorDetails' => true,
57-
'settings.outputBuffering' => 'append'
58-
]);
54+
[
55+
'settings.displayErrorDetails' => true,
56+
'settings.outputBuffering' => 'append'
57+
]);
5958
$c = $app->getContainer();
6059

6160
// Sanity checks
@@ -67,7 +66,7 @@ public function custom_exception_handling()
6766
/** @var Error $error */
6867
$error = $c->get('errorHandler');
6968

70-
$response = $error(RequestFactory::create('/'), new Response(), new TestException());
69+
$response = $error(RequestFactory::create('/'), new Response(), new \Exception());
7170
$reasonPhrase = $response->getReasonPhrase();
7271
$this->assertEquals('Internal Server Error', $reasonPhrase);
7372

@@ -76,27 +75,6 @@ public function custom_exception_handling()
7675
}
7776
}
7877

79-
/**
80-
* Class TestException
81-
*
82-
* Test Exception that starts its own output buffer
83-
*/
84-
class TestException extends \Exception
85-
{
86-
public function __construct($message = "", $code = 0, Throwable $previous = null)
87-
{
88-
parent::__construct($message, $code, $previous);
89-
90-
// the Slim Error handler calls `ob_get_clean()` regardless of any outputBuffering setting:
91-
// 'preappend' => $body->write(ob_get_clean() . $output);
92-
// 'append' => $body->write($output . ob_get_clean());
93-
// false || anything else => ob_get_clean(); $body->write($output);
94-
//
95-
// We start our own OB for testing to keep the OB stack clean
96-
ob_start();
97-
}
98-
}
99-
10078
/**
10179
* Class BridgeApp
10280
*

0 commit comments

Comments
 (0)