Skip to content

Commit

Permalink
Merge pull request #3954 from janhenkgerritsen/2.2
Browse files Browse the repository at this point in the history
Laravel5 module fixes
  • Loading branch information
janhenkgerritsen committed Jan 25, 2017
2 parents a50025e + 5976db3 commit 4a04cd1
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Codeception/Module/Laravel5.php
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

0 comments on commit 4a04cd1

Please sign in to comment.