예제 #1
0
 public function testExecute2()
 {
     $container = new Container();
     $config = array('path' => '/blog-:id', 'params' => array('id' => 'i'), 'defaults' => array('id' => 1), 'action' => array($this, 'controllerAction'));
     $route = $container->instantiate('Packfire\\Router\\Routes\\BaseRoute', array('name' => 'test', 'config' => $config));
     $route->execute();
 }
예제 #2
0
 public function testCreateFail()
 {
     $config = array();
     $container = new Container();
     $factory = $container->instantiate('Packfire\\Router\\RouteFactory');
     $obj = $factory->create('test', $config);
     $this->assertNull($obj);
 }
예제 #3
0
 public function testLoad2()
 {
     $router = $this->getMock('Packfire\\Router\\RouterInterface');
     $router->expects($this->exactly(2))->method('add');
     $container = new Container();
     $container['Packfire\\Router\\RouterInterface'] = $router;
     $loader = $container->instantiate('Packfire\\Router\\FileLoader', array('file' => __DIR__ . '/sampleRoutes.yml'));
     $resultRouter = $loader->load();
     $this->assertInstanceOf('Packfire\\Router\\RouterInterface', $resultRouter);
 }
예제 #4
0
 public function testExecute()
 {
     $container = new Container();
     $container['PHPUnit_Framework_TestCase'] = $this;
     $config = array('path' => '/blog', 'target' => 'http://blog.example.com');
     $route = $container->instantiate('Packfire\\Router\\Routes\\RedirectRoute', array('name' => 'test', 'config' => $config));
     ob_start();
     $route->execute();
     $content = ob_get_contents();
     ob_end_clean();
     $var = json_decode($content, true);
     $this->assertEquals(array('Location: http://blog.example.com', true, 302), $var);
 }
예제 #5
0
 public function testGenerateCustomGenerator()
 {
     $generator = $this->getMock('Packfire\\Router\\GeneratorInterface');
     $generator->expects($this->once())->method('generate')->will($this->returnValue('/blog/5'));
     $container = new Container();
     $container['Packfire\\Router\\GeneratorInterface'] = $generator;
     $router = $container->instantiate('Packfire\\Router\\Router');
     $config = array('path' => '/blog/:id', 'target' => 'http://heartcode.sg/');
     $router->add('test', $config);
     $uri = $router->generate('test', array('id' => 5));
     $this->assertEquals('/blog/5', $uri);
 }