snakeCased parameter, and added v2 unit testing behaviors

pull/545/head
n0nag0n 11 months ago
parent d5a5a15607
commit e29f3b5533

@ -27,7 +27,7 @@ use flight\net\Route;
* # Core methods
* @method void start() Starts engine
* @method void stop() Stops framework and outputs current response
* @method void halt(int $code = 200, string $message = '', bool $actually_exit = true) Stops processing and returns a given response.
* @method void halt(int $code = 200, string $message = '', bool $actuallyExit = true) Stops processing and returns a given response.
*
* # Routing
* @method Route route(string $pattern, callable $callback, bool $pass_route = false, string $alias = '')
@ -647,16 +647,16 @@ class Engine
*
* @param int $code HTTP status code
* @param string $message Response message
* @param bool $actually_exit Whether to actually exit the script or just send response
* @param bool $actuallyExit Whether to actually exit the script or just send response
*/
public function _halt(int $code = 200, string $message = '', bool $actually_exit = true): void
public function _halt(int $code = 200, string $message = '', bool $actuallyExit = true): void
{
$this->response()
->clear()
->status($code)
->write($message)
->send();
if ($actually_exit === true) {
if ($actuallyExit === true) {
exit(); // @codeCoverageIgnore
}
}

@ -22,7 +22,7 @@ require_once __DIR__ . '/autoload.php';
* @method static void start() Starts the framework.
* @method static void path(string $path) Adds a path for autoloading classes.
* @method static void stop(?int $code = null) Stops the framework and sends a response.
* @method static void halt(int $code = 200, string $message = '', bool $actually_exit = true)
* @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true)
* Stop the framework with an optional status code and message.
*
* # Routing

@ -242,4 +242,38 @@ class FlightTest extends TestCase
$this->assertEquals('/user/all_users/check_user/check_one/normalpath', $url);
}
public function testHookOutputBuffering() {
Flight::route('/test', function () {
echo 'test';
});
Flight::before('start', function ($output) {
echo 'hooked before start';
});
Flight::request()->url = '/test';
$this->expectOutputString('hooked before starttest');
Flight::start();
$this->assertEquals('test', Flight::response()->getBody());
}
public function testHookOutputBufferingV2OutputBuffering() {
Flight::route('/test', function () {
echo 'test';
});
Flight::before('start', function ($output) {
echo 'hooked before start';
});
Flight::set('flight.v2.output_buffering', true);
Flight::request()->url = '/test';
$this->expectOutputString('hooked before starttest');
ob_start();
Flight::start();
$this->assertEquals('hooked before starttest', Flight::response()->getBody());
}
}

@ -11,6 +11,7 @@ require file_exists(__DIR__ . '/../../vendor/autoload.php') ? __DIR__ . '/../../
Flight::set('flight.content_length', false);
Flight::set('flight.views.path', './');
// This enables the old functionality of Flight output buffering
Flight::set('flight.v2.output_buffering', true);
// Test 1: Root route

Loading…
Cancel
Save