Writing firsts tests for Flight class with named arguments

php8-named-arguments-support
fadrian06 1 year ago
parent aba66dab3e
commit 407e4ce5ac

@ -20,7 +20,6 @@ require_once __DIR__ . '/autoload.php';
*
* # Core methods
* @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 $actuallyExit = true)
* Stop the framework with an optional status code and message.
@ -129,6 +128,12 @@ class Flight
static::__callStatic('unregister', [$methodName]);
}
/** Adds a path for autoloading classes. */
public static function path(string $path): void
{
static::__callStatic('path', [$path]);
}
/**
* Handles calls to static methods.
*

@ -19,6 +19,7 @@
<testsuites>
<testsuite name="default">
<directory>tests/</directory>
<exclude>tests/named-arguments/</exclude>
</testsuite>
</testsuites>
<logging />

@ -0,0 +1,5 @@
<?php
class ExampleClass
{
}

@ -0,0 +1,75 @@
<?php
namespace Tests\PHP8;
use ExampleClass;
use Flight;
use flight\Engine;
use flight\net\Route;
use PHPUnit\Framework\TestCase;
class FlightTest extends TestCase
{
protected function setUp(): void
{
$_SERVER = [];
$_REQUEST = [];
Flight::init();
Flight::setEngine(new Engine());
}
protected function tearDown(): void
{
unset($_REQUEST);
unset($_SERVER);
Flight::clear();
}
//////////////////
// CORE METHODS //
//////////////////
public function test_path(): void
{
Flight::path(path: __DIR__);
$exampleObject = new ExampleClass();
self::assertInstanceOf(ExampleClass::class, $exampleObject);
}
public function test_stop_with_code(): void
{
Flight::stop(code: 500);
self::expectOutputString('');
self::assertSame(500, Flight::response()->status());
}
public function test_halt(): void
{
Flight::halt(500, actuallyExit: false, message: 'Test');
self::expectOutputString('Test');
self::assertSame(500, Flight::response()->status());
}
/////////////////////
// ROUTING METHODS //
/////////////////////
public function test_static_route(): void
{
Flight::request()->url = '/test';
$route = Flight::route(
pass_route: true,
alias: 'testRoute',
callback: function () {
echo 'test';
},
pattern: '/test'
);
self::assertInstanceOf(Route::class, $route);
self::expectOutputString('test');
Flight::start();
}
}
Loading…
Cancel
Save