Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel5 module fixes #3954

Merged
merged 2 commits into from
Jan 25, 2017
Merged
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
24 changes: 19 additions & 5 deletions src/Codeception/Module/Laravel5.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ public function _before(\Codeception\TestInterface $test)
{
$this->client = new LaravelConnector($this);

// Database migrations and seeder should run before database cleanup transaction starts
// Database migrations should run before database cleanup transaction starts
if ($this->config['run_database_migrations']) {
$this->callArtisan('migrate', ['--path' => $this->config['database_migrations_path']]);
}

if ($this->config['run_database_seeder']) {
$this->callArtisan('db:seed', ['--class' => $this->config['database_seeder_class']]);
if ($this->applicationUsesDatabase() && $this->config['cleanup']) {
$this->app['db']->beginTransaction();
}

if (isset($this->app['db']) && $this->config['cleanup']) {
$this->app['db']->beginTransaction();
if ($this->config['run_database_seeder']) {
$this->callArtisan('db:seed', ['--class' => $this->config['database_seeder_class']]);
}
}

Expand All @@ -187,6 +187,10 @@ public function _before(\Codeception\TestInterface $test)
*/
public function _after(\Codeception\TestInterface $test)
{
if (! $this->applicationUsesDatabase()) {
return;
}

if (isset($this->app['db']) && $this->config['cleanup']) {
$this->app['db']->rollback();
}
Expand All @@ -197,6 +201,16 @@ public function _after(\Codeception\TestInterface $test)
}
}

/**
* Does the application use the database?
*
* @return bool
*/
private function applicationUsesDatabase()
{
return ! empty($this->app['config']['database.default']);
}

/**
* Make sure the Laravel bootstrap file exists.
*
Expand Down