diff --git a/readme.md b/readme.md index 1ec6af2..cecac3d 100644 --- a/readme.md +++ b/readme.md @@ -27,6 +27,7 @@ default: extensions: Laracasts\Behat: # env_path: .env.behat + # bootstrap_path: bootstrap/app.php Behat\MinkExtension: default_session: laravel laravel: ~ @@ -37,6 +38,8 @@ Here, is where we reference the Laravel extension, and tell Behat to use it as o This file should, like the standard `.env` file in your project root, contain any special environment variables for your tests (such as a special acceptance test-specific database). +You may also specify a custom path to Laravel's `bootstrap_path` if it's not in the default location. + # 3. Write Some Features ![example](https://dl.dropboxusercontent.com/u/774859/Work/BehatLaravelExtension/example.png) @@ -135,4 +138,4 @@ $lastEmail = $this->fetchInbox()[0]; If working along, you can dump that variable to see all of the various fields that you may write assertions against. In the example above, we're ensuring that the subject was set correctly, and the body of the email matches a stub that we've created. -Even better, after each scenario completes, we'll go ahead and empty out your MailTrap inbox for convenience. \ No newline at end of file +Even better, after each scenario completes, we'll go ahead and empty out your MailTrap inbox for convenience. diff --git a/spec/Context/KernelAwareInitializerSpec.php b/spec/Context/KernelAwareInitializerSpec.php index 6f72f2b..348d0f9 100644 --- a/spec/Context/KernelAwareInitializerSpec.php +++ b/spec/Context/KernelAwareInitializerSpec.php @@ -13,7 +13,8 @@ class KernelAwareInitializerSpec extends ObjectBehavior function let(HttpKernelInterface $kernel) { - $this->beConstructedWith($kernel); + $config = []; + $this->beConstructedWith($kernel, $config); } function it_is_an_event_subscriber() diff --git a/spec/ServiceContainer/LaravelBooterSpec.php b/spec/ServiceContainer/LaravelBooterSpec.php index b3fdd50..e27851f 100644 --- a/spec/ServiceContainer/LaravelBooterSpec.php +++ b/spec/ServiceContainer/LaravelBooterSpec.php @@ -9,7 +9,7 @@ class LaravelBooterSpec extends ObjectBehavior { function let() { - $this->beConstructedWith(__DIR__, '.env.foo'); + $this->beConstructedWith(__DIR__, '.env.foo', '/bootstrap/app.php'); } function it_is_initializable() @@ -27,6 +27,11 @@ function it_knows_the_environment_file() $this->environmentFile()->shouldBe('.env.foo'); } + function it_knows_the_bootstrap_file() + { + $this->bootstrapFile()->shouldBe('bootstrap/app.php'); + } + function it_takes_exception_with_a_missing_bootstrap_file() { $this->shouldThrow('RuntimeException')->duringBoot(); diff --git a/src/Context/KernelAwareInitializer.php b/src/Context/KernelAwareInitializer.php index e842c44..c1ef551 100644 --- a/src/Context/KernelAwareInitializer.php +++ b/src/Context/KernelAwareInitializer.php @@ -26,14 +26,23 @@ class KernelAwareInitializer implements EventSubscriberInterface, ContextInitial */ private $context; + /** + * Behat config. + * + * @var array + */ + private $config; + /** * Construct the initializer. * * @param HttpKernelInterface $kernel + * @param array $config */ - public function __construct(HttpKernelInterface $kernel) + public function __construct(HttpKernelInterface $kernel, array $config) { $this->kernel = $kernel; + $this->config = $config; } /** @@ -73,11 +82,11 @@ public function rebootKernel() { $this->kernel->flush(); - $laravel = new LaravelBooter($this->kernel->basePath(), $this->kernel->environmentFile()); + $laravel = new LaravelBooter($this->kernel->basePath(), $this->kernel->environmentFile(), $this->config['bootstrap_path']); $this->context->getSession('laravel')->getDriver()->reboot($this->kernel = $laravel->boot()); $this->setAppOnContext(); } -} \ No newline at end of file +} diff --git a/src/ServiceContainer/BehatExtension.php b/src/ServiceContainer/BehatExtension.php index ab9501b..56638ff 100644 --- a/src/ServiceContainer/BehatExtension.php +++ b/src/ServiceContainer/BehatExtension.php @@ -60,7 +60,7 @@ public function load(ContainerBuilder $container, array $config) { $app = $this->loadLaravel($container, $config); - $this->loadInitializer($container, $app); + $this->loadInitializer($container, $app, $config); } /** @@ -72,7 +72,7 @@ public function load(ContainerBuilder $container, array $config) */ private function loadLaravel(ContainerBuilder $container, array $config) { - $laravel = new LaravelBooter($container->getParameter('paths.base'), $config['env_path']); + $laravel = new LaravelBooter($container->getParameter('paths.base'), $config['env_path'], $config['bootstrap_path']); $container->set('laravel.app', $app = $laravel->boot()); @@ -84,10 +84,11 @@ private function loadLaravel(ContainerBuilder $container, array $config) * * @param ContainerBuilder $container * @param HttpKernelInterface $app + * @param array $config */ - private function loadInitializer(ContainerBuilder $container, $app) + private function loadInitializer(ContainerBuilder $container, $app, array $config) { - $definition = new Definition('Laracasts\Behat\Context\KernelAwareInitializer', [$app]); + $definition = new Definition('Laracasts\Behat\Context\KernelAwareInitializer', [$app, $config]); $definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]); $definition->addTag(ContextExtension::INITIALIZER_TAG, ['priority' => 0]); @@ -95,4 +96,4 @@ private function loadInitializer(ContainerBuilder $container, $app) $container->setDefinition('laravel.initializer', $definition); } -} \ No newline at end of file +} diff --git a/src/ServiceContainer/LaravelBooter.php b/src/ServiceContainer/LaravelBooter.php index 8c4266b..dff43ec 100644 --- a/src/ServiceContainer/LaravelBooter.php +++ b/src/ServiceContainer/LaravelBooter.php @@ -21,16 +21,25 @@ class LaravelBooter */ private $environmentFile; + /** + * The application's bootstrap file. + * + * @var string + */ + private $bootstrapFile; + /** * Create a new Laravel booter instance. * * @param $basePath * @param string $environmentFile + * @param string $bootstrapFile */ - public function __construct($basePath, $environmentFile = '.env.behat') + public function __construct($basePath, $environmentFile = '.env.behat', $bootstrapFile = 'bootstrap/app.php') { $this->basePath = $basePath; $this->environmentFile = $environmentFile; + $this->bootstrapFile = $bootstrapFile; } /** @@ -53,6 +62,15 @@ public function environmentFile() return $this->environmentFile; } + /** + * Get the applications bootstrap file. + * + * @return string + */ + public function bootstrapFile() + { + return ltrim($this->bootstrapFile, '/'); + } /** * Boot the app. @@ -61,7 +79,8 @@ public function environmentFile() */ public function boot() { - $bootstrapPath = $this->basePath() . '/bootstrap/app.php'; + $bootstrapFile = $this->bootstrapFile(); + $bootstrapPath = $this->basePath() . "/$bootstrapFile"; $this->assertBootstrapFileExists($bootstrapPath); @@ -87,4 +106,4 @@ private function assertBootstrapFileExists($bootstrapPath) } } -} \ No newline at end of file +}