false); return $app->io(new Interactor(static::$in, static::$ou)); } protected function createIndexFile() { $index = <<<'PHP' addMiddleware(function() {}); Flight::delete('/delete', function () {}); Flight::put('/put', function () {}); Flight::patch('/patch', function () {})->addMiddleware('SomeMiddleware'); Flight::router()->caseSensitive = true; Flight::start(); PHP; file_put_contents(__DIR__ . '/index.php', $index); } 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']); $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']); $this->assertStringContainsString('Routes', file_get_contents(static::$ou)); $this->assertStringContainsString('+---------+-----------+-------+----------+----------------+ | Pattern | Methods | Alias | Streamed | Middleware | +---------+-----------+-------+----------+----------------+ | / | GET, HEAD | | No | - | | /post | POST | | No | Closure | | /delete | DELETE | | No | - | | /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']); $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))); } }