Example #1
0
 /**
  * @dataProvider routeProvider
  * @param        string         $routeDefinition
  * @param        array          $arguments
  * @param        array|null     $params
  */
 public function testMatching($routeDefinition, array $arguments = array(), array $params = null)
 {
     array_unshift($arguments, 'scriptname.php');
     $request = new ConsoleRequest($arguments);
     $route = new Simple($routeDefinition);
     $match = $route->match($request);
     if ($params === null) {
         $this->assertNull($match, "The route must not match");
     } else {
         $this->assertInstanceOf('Zend\\Mvc\\Router\\Console\\RouteMatch', $match, "The route matches");
         foreach ($params as $key => $value) {
             $this->assertEquals($value, $match->getParam($key), $value === null ? "Param {$key} is not present" : "Param {$key} is present and is equal to {$value}");
         }
     }
 }
 public function setUp()
 {
     $this->setApplicationConfig(include __DIR__ . '/../../config/application.config.php');
     parent::setUp();
     // Fake the config and the routing
     $serviceManager = $this->getApplication()->getServiceManager();
     $data = array('name' => 'testArgs', 'options' => array('route' => "testArgs [--singleParam=] [--arrayParam=] ", 'defaults' => array('controller' => 'test', 'action' => 'Args'), 'arrays' => array('arrayParam')));
     $config = $serviceManager->get('config');
     $config['console']['router']['routes'][$data['name']] = $data;
     $serviceManager->setAllowOverride(true);
     $serviceManager->setService('config', $config);
     $serviceManager->setAllowOverride(false);
     $testRoute = SimpleRouter::factory($data['options']);
     $router = $serviceManager->get('router');
     $router->addRoute($data['name'], $testRoute, 99999);
     $eventManager = $this->getApplication()->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'postRoute'), -3);
 }
Example #3
0
 public function testCustomRouteMatcherCanBeInjectedViaConstructor()
 {
     $arguments = array('--foo=bar');
     array_unshift($arguments, 'scriptname.php');
     $request = new ConsoleRequest($arguments);
     $routeMatcher = $this->getMock('Zend\\Console\\RouteMatcher\\RouteMatcherInterface', array('match'));
     $routeMatcher->expects($this->once())->method('match')->with(array('--foo=bar'));
     $route = new Simple($routeMatcher);
     $route->match($request);
 }
Example #4
0
 public function testCanNotMatchingWithEmtpyMandatoryParam()
 {
     $arguments = array('--foo=');
     array_unshift($arguments,'scriptname.php');
     $request = new ConsoleRequest($arguments);
     $route = new Simple('--foo=');
     $match = $route->match($request);
     $this->assertEquals(null, $match);
 }