Beispiel #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();
 }
Beispiel #2
0
 public function testCreateFail()
 {
     $config = array();
     $container = new Container();
     $factory = $container->instantiate('Packfire\\Router\\RouteFactory');
     $obj = $factory->create('test', $config);
     $this->assertNull($obj);
 }
Beispiel #3
0
 public function testInverseOfControl()
 {
     $container = new Container();
     $container['Samsui\\DefinitionInterface'] = $container->instance('Samsui\\MockDefinition');
     $factory = new Factory();
     $factory($container);
     $definition = $factory->define('test');
     $this->assertInstanceOf('Samsui\\MockDefinition', $definition);
 }
Beispiel #4
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);
 }
Beispiel #5
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);
 }
Beispiel #6
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);
 }
Beispiel #7
0
 /**
  * Create an instance of a class
  * @param string $className The class name to create
  * @param array $params (optional) An array of arguments to be passed to the constructor.
  * @return object Returns the instance of the class created.
  * @since 1.2.0
  */
 public function instantiate($className, $params = array())
 {
     $class = new \ReflectionClass($className);
     $constructor = $class->getConstructor();
     $result = null;
     if ($constructor) {
         $arguments = Container::buildDependencies($this, $constructor, $params);
         $result = $class->newInstanceArgs($arguments);
     } else {
         $result = $class->newInstance();
     }
     if ($result instanceof ConsumerInterface) {
         $result($this);
     }
     return $result;
 }