get() public method

Add a GET route.
public get ( string $route, mixed $action ) : void
$route string
$action mixed
return void
Example #1
0
 public function testRun()
 {
     $request = Request::create('/welcome');
     $request->headers->set('Accept', '*/*');
     $this->app->get('/1.0/welcome', function (Request $request) {
         return new Response('Hello Phprest World', 200);
     });
     ob_start();
     $this->app->run($request);
     $this->assertEquals('Hello Phprest World', ob_get_clean());
 }
Example #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);
 }