|
|
|
@ -13,15 +13,14 @@ use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
class RouteCommandTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected static $in = __DIR__ . '/input.test';
|
|
|
|
|
protected static $in = __DIR__ . '/input.test';
|
|
|
|
|
protected static $ou = __DIR__ . '/output.test';
|
|
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
file_put_contents(static::$in, '', LOCK_EX);
|
|
|
|
|
file_put_contents(static::$ou, '', LOCK_EX);
|
|
|
|
|
$_SERVER = [];
|
|
|
|
|
$_SERVER = [];
|
|
|
|
|
$_REQUEST = [];
|
|
|
|
|
Flight::init();
|
|
|
|
|
Flight::setEngine(new Engine());
|
|
|
|
@ -37,25 +36,25 @@ class RouteCommandTest extends TestCase
|
|
|
|
|
unlink(static::$ou);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file_exists(__DIR__.'/index.php')) {
|
|
|
|
|
unlink(__DIR__.'/index.php');
|
|
|
|
|
}
|
|
|
|
|
if (file_exists(__DIR__ . '/index.php')) {
|
|
|
|
|
unlink(__DIR__ . '/index.php');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($_REQUEST);
|
|
|
|
|
unset($_REQUEST);
|
|
|
|
|
unset($_SERVER);
|
|
|
|
|
Flight::clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function newApp(string $name, string $version = '')
|
|
|
|
|
protected function newApp(string $name, string $version = '')
|
|
|
|
|
{
|
|
|
|
|
$app = new Application($name, $version ?: '0.0.1', fn () => false);
|
|
|
|
|
|
|
|
|
|
return $app->io(new Interactor(static::$in, static::$ou));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function createIndexFile()
|
|
|
|
|
{
|
|
|
|
|
$index = <<<PHP
|
|
|
|
|
protected function createIndexFile()
|
|
|
|
|
{
|
|
|
|
|
$index = <<<PHP
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
@ -70,32 +69,32 @@ Flight::router()->case_sensitive = true;
|
|
|
|
|
Flight::start();
|
|
|
|
|
PHP;
|
|
|
|
|
|
|
|
|
|
file_put_contents(__DIR__.'/index.php', $index);
|
|
|
|
|
}
|
|
|
|
|
file_put_contents(__DIR__ . '/index.php', $index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function removeColors(string $str): string
|
|
|
|
|
{
|
|
|
|
|
return preg_replace('/\e\[[\d;]*m/', '', $str);
|
|
|
|
|
}
|
|
|
|
|
protected function removeColors(string $str): string
|
|
|
|
|
{
|
|
|
|
|
return preg_replace('/\e\[[\d;]*m/', '', $str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testConfigIndexRootNotSet()
|
|
|
|
|
{
|
|
|
|
|
$app = $this->newApp('test', '0.0.1');
|
|
|
|
|
$app->add(new RouteCommand([]));
|
|
|
|
|
$app->handle(['runway', 'routes']);
|
|
|
|
|
public function testConfigIndexRootNotSet()
|
|
|
|
|
{
|
|
|
|
|
$app = $this->newApp('test', '0.0.1');
|
|
|
|
|
$app->add(new RouteCommand([]));
|
|
|
|
|
$app->handle(['runway', 'routes']);
|
|
|
|
|
|
|
|
|
|
$this->assertStringContainsString('index_root not set in .runway-config.json', file_get_contents(static::$ou));
|
|
|
|
|
}
|
|
|
|
|
$this->assertStringContainsString('index_root not set in .runway-config.json', file_get_contents(static::$ou));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetRoutes()
|
|
|
|
|
{
|
|
|
|
|
$app = $this->newApp('test', '0.0.1');
|
|
|
|
|
$this->createIndexFile();
|
|
|
|
|
$app->add(new RouteCommand(['index_root' => 'tests/commands/index.php']));
|
|
|
|
|
$app->handle(['runway', 'routes']);
|
|
|
|
|
public function testGetRoutes()
|
|
|
|
|
{
|
|
|
|
|
$app = $this->newApp('test', '0.0.1');
|
|
|
|
|
$this->createIndexFile();
|
|
|
|
|
$app->add(new RouteCommand(['index_root' => 'tests/commands/index.php']));
|
|
|
|
|
$app->handle(['runway', 'routes']);
|
|
|
|
|
|
|
|
|
|
$this->assertStringContainsString('Routes', file_get_contents(static::$ou));
|
|
|
|
|
$this->assertStringContainsString('+---------+-----------+-------+----------+----------------+
|
|
|
|
|
$this->assertStringContainsString('Routes', file_get_contents(static::$ou));
|
|
|
|
|
$this->assertStringContainsString('+---------+-----------+-------+----------+----------------+
|
|
|
|
|
| Pattern | Methods | Alias | Streamed | Middleware |
|
|
|
|
|
+---------+-----------+-------+----------+----------------+
|
|
|
|
|
| / | GET, HEAD | | No | - |
|
|
|
|
@ -104,20 +103,20 @@ PHP;
|
|
|
|
|
| /put | PUT | | No | - |
|
|
|
|
|
| /patch | PATCH | | No | Bad Middleware |
|
|
|
|
|
+---------+-----------+-------+----------+----------------+', $this->removeColors(file_get_contents(static::$ou)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetPostRoute() {
|
|
|
|
|
$app = $this->newApp('test', '0.0.1');
|
|
|
|
|
$this->createIndexFile();
|
|
|
|
|
$app->add(new RouteCommand(['index_root' => 'tests/commands/index.php']));
|
|
|
|
|
$app->handle(['runway', 'routes', '--post']);
|
|
|
|
|
public function testGetPostRoute()
|
|
|
|
|
{
|
|
|
|
|
$app = $this->newApp('test', '0.0.1');
|
|
|
|
|
$this->createIndexFile();
|
|
|
|
|
$app->add(new RouteCommand(['index_root' => 'tests/commands/index.php']));
|
|
|
|
|
$app->handle(['runway', 'routes', '--post']);
|
|
|
|
|
|
|
|
|
|
$this->assertStringContainsString('Routes', file_get_contents(static::$ou));
|
|
|
|
|
$this->assertStringContainsString('+---------+---------+-------+----------+------------+
|
|
|
|
|
$this->assertStringContainsString('Routes', file_get_contents(static::$ou));
|
|
|
|
|
$this->assertStringContainsString('+---------+---------+-------+----------+------------+
|
|
|
|
|
| Pattern | Methods | Alias | Streamed | Middleware |
|
|
|
|
|
+---------+---------+-------+----------+------------+
|
|
|
|
|
| /post | POST | | No | Closure |
|
|
|
|
|
+---------+---------+-------+----------+------------+', $this->removeColors(file_get_contents(static::$ou)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|