/** * @dataProvider appProvider * * @param Application $app */ public function testHandle(Application $app) { $middleware = new ApiVersion($app); /** @var \Mockery\MockInterface $app */ $app->shouldReceive('handle')->andReturnUsing(function ($request) { $this->assertInstanceOf('Phprest\\HttpFoundation\\Request', $request); /** @var \Phprest\HttpFoundation\Request $request */ $this->assertEquals('/2.6/temperatures', $request->getPathInfo()); }); $middleware->handle(Request::create('/temperatures')); }
public function testDisplayedData() { $phprestApp = new PhprestApp(new Config('phprest-test', '2.3', true)); $phprestApp->get('/2.3/get-the-answer-of-everything', 'Phprest\\Stub\\Controller::getTheAnswerOfEverything'); $phprestApp->get('/2.3/get-welcome-message', function () { return new Response('Welcome!'); }); $cliApp = new ConsoleApp(); $cliApp->add(new Get($phprestApp)); $command = $cliApp->find('routes:get'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName())); $displayedData = $commandTester->getDisplay(); $this->assertContains('| GET | /2.3/get-the-answer-of-everything | Phprest\\Stub\\Controller::getTheAnswerOfEverything |', $displayedData); $this->assertContains('| GET | /2.3/get-welcome-message | Closure |', $displayedData); }
/** * Create a new Streamlines application instance. * * @param \Phprest\Config $phprestConfig * @param string|null $basePath */ public function __construct(PhprestConfig $phprestConfig, $basePath = null) { parent::__construct($phprestConfig); if ($basePath !== null) { $this->setBasePath($basePath); } $this->config = new Config($this->configPath()); }
/** * @param InputInterface $input * @param OutputInterface $output * * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $routes = []; $routingTable = $this->app->getRouter()->getRoutingTable(); usort($routingTable, function ($a, $b) { return $a['route'] < $b['route'] ? -1 : 1; }); foreach ($routingTable as $routingTableRecord) { if ($routingTableRecord['handler'] instanceof \Closure) { $routes[] = [$routingTableRecord['method'], $routingTableRecord['route'], 'Closure']; } else { $routes[] = [$routingTableRecord['method'], $routingTableRecord['route'], $routingTableRecord['handler']]; } } $table = $this->getHelper('table'); $table->setHeaders(['Method', 'Route', 'Handler'])->setRows($routes); $table->render($output); }
public function testGetters() { $this->assertInstanceOf('\\Phprest\\Config', $this->app->getConfiguration()); $this->assertInstanceOf('\\League\\Container\\ContainerInterface', $this->app->getContainer()); $this->assertInstanceOf('\\Phprest\\Router\\RouteCollection', $this->app->getRouter()); }
/** * Returns the DI container. * * @return \League\Container\ContainerInterface */ protected function getContainer() { return $this->app->getConfiguration()->getContainer(); }