title: Setting up package migrations with Behat 3 and Laravel
body: <p>I'm working on including Behat 3 in a new Laravel based API, and I'm using the lucadegasperi/oauth2-server-laravel package to handle authentication.</p>
  
  <p>Been having a time getting the Behat setup working (it is now). I don't get why, but seems like I need to migrate the packages both in the beforeSuite and beforeFeature hooks. Seems silly as I should only have to migrate once before all the features run..?</p>
  
  <p>I would like to only migrate once before the suite loads, otherwise the running time is likely to get long as the number of tests grow.  </p>
  
  <p>I've been hacking an example for Behat 2.* to work in version 3. </p>
  
  <p>My FeatureContext class currently looks like this: </p>
  
  <pre><code>use Behat\Behat\Context\SnippetAcceptingContext;
  use Behat\Gherkin\Node\PyStringNode;
  use Behat\Gherkin\Node\TableNode;
  
  /**
   * Behat context class.
   */
  class FeatureContext implements SnippetAcceptingContext
  {
  
      private $_restObject        = null;
      private $_restObjectType    = null;
      private $_restObjectMethod  = 'get';
      private $_client            = null;
      private $_response          = null;
      private $_requestUrl        = null;
  
      private $_baseUrl           = null;
  
      /**
       * Initializes context.
       *
       * Every scenario gets its own context object.
       * You can also pass arbitrary arguments to the context constructor through behat.yml.
       */
      public function __construct($baseUrl)
      {
          $this-&gt;_restObject  = new stdClass();
          $this-&gt;_client      = new GuzzleHttp\Client();
          $this-&gt;_baseUrl = $baseUrl;
      }
  
      /**
      * @static
      * @beforeSuite
      */
      public static function bootstrapLaravel()
      {
          $unitTesting = true;
          $testEnvironment = 'testing';
          // This assumes the FeatureContext.php class is within app/tests/features/bootstrap
          $app = require_once __DIR__.'/../../../../bootstrap/start.php';
  
          $app-&gt;boot();
  
          Mail::pretend(true);
      }
  
      /**
      * @static
      * @beforeSuite
      */
      public static function setUpDb()
      {
          Artisan::call('migrate');
  
          self::migratePackages();
  
          /* do seeding */
          $seeders = array(
              "OAuthTestSeeder",
              "RolesPermissionsSeeder"
          );
  
          foreach ($seeders as $seedClass)
          {
              Artisan::call("db:seed", array("--class" =&gt; $seedClass));
          }        
      }
      /**
      * @static
      * @beforeFeature
      */
      public static function prepDb()
      {
          Artisan::call('migrate:refresh');
          self::migratePackages();
  
          Artisan::call('db:seed');
  
  
      }
  
      public static function migratePackages() 
      {
          $packages = array(
              "lucadegasperi/oauth2-server-laravel",
          );        
  
          foreach ($packages as $packageName)
          {
              Artisan::call("migrate",
                  array("--package" =&gt; $packageName, "--env" =&gt; "testing"));
              echo 'migrating package: '.$packageName;
          }   
  
      }
  /* feature specs here... 
  */ 
  }
  </code></pre>