Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ default:
extensions:
Laracasts\Behat:
# env_path: .env.behat
# bootstrap_path: bootstrap/app.php
Behat\MinkExtension:
default_session: laravel
laravel: ~
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Even better, after each scenario completes, we'll go ahead and empty out your MailTrap inbox for convenience.
3 changes: 2 additions & 1 deletion spec/Context/KernelAwareInitializerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion spec/ServiceContainer/LaravelBooterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
Expand Down
15 changes: 12 additions & 3 deletions src/Context/KernelAwareInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();
}

}
}
11 changes: 6 additions & 5 deletions src/ServiceContainer/BehatExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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());

Expand All @@ -84,15 +84,16 @@ 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]);

$container->setDefinition('laravel.initializer', $definition);
}

}
}
25 changes: 22 additions & 3 deletions src/ServiceContainer/LaravelBooter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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.
Expand All @@ -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);

Expand All @@ -87,4 +106,4 @@ private function assertBootstrapFileExists($bootstrapPath)
}
}

}
}