Inheritance: implements Symfony\Component\HttpKernel\HttpKernelInterface, implements Symfony\Component\HttpKernel\TerminableInterface, implements League\Container\ContainerAwareInterface, implements League\Event\ListenerAcceptorInterface, use trait League\Event\EmitterTrait, use trait League\Container\ContainerAwareTrait, use trait Phprest\Service\Hateoas\Getter, use trait Phprest\Service\Hateoas\Util, use trait Phprest\Service\Logger\Getter
Exemple #1
0
 /**
  * @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'));
 }
Exemple #2
0
 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);
 }
Exemple #3
0
 /**
  * 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());
 }
Exemple #4
0
 /**
  * @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);
 }
Exemple #5
0
 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());
 }
Exemple #6
0
 /**
  * Returns the DI container.
  *
  * @return \League\Container\ContainerInterface
  */
 protected function getContainer()
 {
     return $this->app->getConfiguration()->getContainer();
 }