title: How to bootstrap a Zend Framework 2 application for testing with Behat
body: <p>I'm using ZF <code>2.5.0</code> on a legacy application that we are going to write tests for.</p>
  
  <p>I used <a href="https://stackoverflow.com/questions/5667444/zend-framework-integration-with-behat-bdd">this question</a> as a reference, but mainly changed many things regarding autoloading.</p>
  
  <p>I'm basically manually instantiating a subclass of <code>AbstractControllerTestCase</code> inside my <code>FeatureContext</code>. I'm specifically trying to get a <code>ServiceLocator</code> instance, so I can load my dependencies (for instance: <code>$locator-&gt;get('Doctrine\ORM\EntityManager');</code>).</p>
  
  <p>In order to understand how to bootstrap it, I read the <a href="https://framework.zend.com/manual/2.4/en/tutorials/unittesting.html#bootstrapping-your-tests" rel="nofollow noreferrer">tutorial for <code>PHPUnit</code></a>. While reading this tutorial, I noticed the <code>Boostrap</code> class creates an instance of a <code>ServiceManager</code> on it's <code>init()</code> class method, but I fail to see how this instance is injected into the application instance that is created by <code>AbstractControllerTestCase</code>. </p>
  
  <p>Any explanation or clarification on this would be appreciated. Or in general about how do I bootstrap an application to work with Behat.</p>