Files
simple-php-router/tests/TestRouter.php
Simon Sessingø 5cd6cab801 Development
- Fixed issue causing default-namespace to add duplicate namespace when using type-hints (issue: #561).
- Fixed phpstan issues.
- Tests: Fixed TestRouter not resetting namespace upon reset.
- Tests: Added NSController (namespace controller) class.
- Tests: added test for class hint + default namespace case.
- Composer: added phpstan support + configuration.
- Composer: updated phpunit version.
2021-06-09 08:54:24 +02:00

51 lines
1.2 KiB
PHP

<?php
class TestRouter extends \Pecee\SimpleRouter\SimpleRouter
{
public function __construct()
{
static::request()->setHost('testhost.com');
}
public static function debugNoReset($testUrl, $testMethod = 'get')
{
$request = static::request();
$request->setUrl((new \Pecee\Http\Url($testUrl))->setHost('local.unitTest'));
$request->setMethod($testMethod);
static::start();
}
public static function debug($testUrl, $testMethod = 'get', bool $reset = true)
{
try {
static::debugNoReset($testUrl, $testMethod);
} catch (\Exception $e) {
static::$defaultNamespace = null;
static::router()->reset();
throw $e;
}
if ($reset === true) {
static::$defaultNamespace = null;
static::router()->reset();
}
}
public static function debugOutput($testUrl, $testMethod = 'get', bool $reset = true)
{
$response = null;
// Route request
ob_start();
static::debug($testUrl, $testMethod, $reset);
$response = ob_get_clean();
// Return response
return $response;
}
}