title: How can I pass extra parameters to the routeMatch object?
body: <p>I'm trying to unit test a controller, but can't figure out how to pass some extra parameters to the routeMatch object.</p>
  
  <p>I followed the posts from tomoram at <a href="http://devblog.x2k.co.uk/unit-testing-a-zend-framework-2-controller/" rel="nofollow">http://devblog.x2k.co.uk/unit-testing-a-zend-framework-2-controller/</a> and <a href="http://devblog.x2k.co.uk/getting-the-servicemanager-into-the-test-environment-and-dependency-injection/" rel="nofollow">http://devblog.x2k.co.uk/getting-the-servicemanager-into-the-test-environment-and-dependency-injection/</a>, but when I try to dispatch a request to /album/edit/1, for instance, it throws the following exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>Zend\Mvc\Exception\DomainException: Url plugin requires that controller event compose a router; none found
  </code></pre>
  
  <p>Here is my PHPUnit Bootstrap:</p>
  
  <pre class="lang-php prettyprint-override"><code>class Bootstrap
  {
      static $serviceManager;
      static $di;
  
      static public function go()
      {
          include 'init_autoloader.php';
  
          $config = include 'config/application.config.php';
          // append some testing configuration
          $config['module_listener_options']['config_static_paths'] = array(getcwd() . '/config/test.config.php');
  
          // append some module-specific testing configuration
          if (file_exists(__DIR__ . '/config/test.config.php')) {
              $moduleConfig = include __DIR__ . '/config/test.config.php';
              array_unshift($config['module_listener_options']['config_static_paths'], $moduleConfig);
          }
  
          $serviceManager = Application::init($config)-&gt;getServiceManager();
  
          self::$serviceManager = $serviceManager;
  
          // Setup Di
          $di = new Di();
  
          $di-&gt;instanceManager()-&gt;addTypePreference('Zend\ServiceManager\ServiceLocatorInterface', 'Zend\ServiceManager\ServiceManager');
          $di-&gt;instanceManager()-&gt;addTypePreference('Zend\EventManager\EventManagerInterface', 'Zend\EventManager\EventManager');
          $di-&gt;instanceManager()-&gt;addTypePreference('Zend\EventManager\SharedEventManagerInterface', 'Zend\EventManager\SharedEventManager');
  
          self::$di = $di;
      }
  
      static public function getServiceManager()
      {
          return self::$serviceManager;
      }
  
      static public function getDi()
      {
          return self::$di;
      }
  
  }
  
  Bootstrap::go();
  </code></pre>
  
  <p>Basically, we are creating a <code>Zend\Mvc\Application</code> environment.</p>
  
  <p>My <code>PHPUnit_Framework_TestCase</code> is enclosed in a custom class, which goes like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>abstract class ControllerTestCase extends TestCase
  {
      /**
       * The ActionController we are testing
       *
       * @var Zend\Mvc\Controller\AbstractActionController
       */
      protected $controller;
  
      /**
       * A request object
       *
       * @var Zend\Http\Request
       */
      protected $request;
  
      /**
       * A response object
       *
       * @var Zend\Http\Response
       */
      protected $response;
  
      /**
       * The matched route for the controller
       *
       * @var Zend\Mvc\Router\RouteMatch
       */
      protected $routeMatch;
  
      /**
       * An MVC event to be assigned to the controller
       *
       * @var Zend\Mvc\MvcEvent
       */
      protected $event;
  
      /**
       * The Controller fully qualified domain name, so each ControllerTestCase can create an instance
       * of the tested controller
       *
       * @var string
       */
      protected $controllerFQDN;
  
      /**
       * The route to the controller, as defined in the configuration files
       *
       * @var string
       */
      protected $controllerRoute;
  
      public function setup()
      {
          parent::setup();
  
          $di = \Bootstrap::getDi();
  
          // Create a Controller and set some properties
          $this-&gt;controller = $di-&gt;newInstance($this-&gt;controllerFQDN);
  
          $this-&gt;request    = new Request();
          $this-&gt;routeMatch = new RouteMatch(array('controller' =&gt; $this-&gt;controllerRoute));
          $this-&gt;event      = new MvcEvent();
  
          $this-&gt;event-&gt;setRouteMatch($this-&gt;routeMatch);
  
          $this-&gt;controller-&gt;setEvent($this-&gt;event);
          $this-&gt;controller-&gt;setServiceLocator(\Bootstrap::getServiceManager());
      }
  
      public function tearDown()
      {
          parent::tearDown();
          unset($this-&gt;controller);
          unset($this-&gt;request);
          unset($this-&gt;routeMatch);
          unset($this-&gt;event);
      }
  }
  </code></pre>
  
  <p>And we create a Controller instance and a Request with a RouteMatch.</p>
  
  <p>The code for the test:</p>
  
  <pre class="lang-php prettyprint-override"><code>public function testEditActionWithGetRequest()
  {
      // Dispatch the edit action
      $this-&gt;routeMatch-&gt;setParam('action', 'edit');
      $this-&gt;routeMatch-&gt;setParam('id', $album-&gt;id);
      $result = $this-&gt;controller-&gt;dispatch($this-&gt;request, $this-&gt;response);
  
      // rest of the code isn't executed
  }
  </code></pre>
  
  <p>I'm not sure what I'm missing here. Can it be any configuration for the testing bootstrap? Or should I pass the parameters in some other way? Or am I forgetting to instantiate something?</p>