Example #1
0
 /**
  * @covers Phossa\Route\Route::getDefault
  */
 public function testGetDefault()
 {
     $this->assertEquals([], $this->object->getDefault());
 }
Example #2
0
 /**
  * @covers Phossa\Route\Dispatcher::addExtension
  */
 public function testAddExtension()
 {
     $this->expectOutputString("BEFORE_MATCH(404) BEFORE_COLL(404) AFTER_COLL(200) AFTER_MATCH(200) BEFORE_DISPATCH(200) BEFORE_ROUTE(200) 200 bingo AFTER_ROUTE(200) AFTER_DISPATCH(200) ");
     $ext = new Extension\SampleExtension();
     $this->col->addExtension($ext);
     $this->object->addExtension($ext);
     $route = new Route('HEAD', '/user[/{name:xd}]', function (ResultInterface $result) {
         echo $result->getStatus() . " bingo ";
         return true;
     });
     $route->addExtension($ext);
     $this->col->addRoute($route);
     $this->object->dispatchUrl('HEAD', '/user/phossa');
 }
Example #3
0
 /**
  * test other filter, filter by server_name, test GCB
  *
  * @covers Phossa\Route\Collector\Collector::match
  */
 public function testMatch51()
 {
     $this->object = new Collector(new ParserGcb(), ['chunk' => 3]);
     unset($_SERVER['SERVER_NAME']);
     $route = new Route('GET,POST', '/user[/{name:c}]');
     $route->addFilter('server.server_name', 'm.phossa.com');
     $this->object->addRoute($route);
     // failed
     $res1 = new Result(new Request('GET', '/user/phossa'));
     if (!$this->invokeMethod('match', [$res1])) {
         $this->assertEquals(Status::PRECONDITION_FAILED, $res1->getStatus());
     } else {
         throw new \Exception('bad');
     }
     // good
     $_SERVER['SERVER_NAME'] = 'm.phossa.com';
     $res2 = new Result(new Request('GET', '/user/phossa'));
     if ($this->invokeMethod('match', [$res2])) {
         $this->assertEquals(Status::OK, $res2->getStatus());
     } else {
         throw new \Exception('bad');
     }
 }