Skip to content

Commit

Permalink
Merge pull request #1 from gurgentil/hotfix/sqlite-db-reset
Browse files Browse the repository at this point in the history
Reset database after running tests
  • Loading branch information
gurgentil authored May 1, 2020
2 parents 2483f96 + 6b5aa94 commit 41656b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ composer.lock
docs
vendor
coverage
tests/temp
17 changes: 12 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ protected function setUp(): void
$this->setUpDatabase();
}

public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();

static::resetDatabase();
}

protected function getPackageProviders($app)
{
return [
Expand All @@ -27,24 +34,24 @@ protected function getEnvironmentSetUp($app)

$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => $this->getTempDirectory() . '/database.sqlite',
'database' => static::getTempDirectory() . '/database.sqlite',
'prefix' => '',
]);
}

protected function setUpDatabase()
{
$this->resetDatabase();
static::resetDatabase();

$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
}

protected function resetDatabase()
protected static function resetDatabase()
{
file_put_contents($this->getTempDirectory() . '/database.sqlite', null);
file_put_contents(static::getTempDirectory() . '/database.sqlite', null);
}

protected function getTempDirectory(): string
protected static function getTempDirectory(): string
{
return __DIR__ . '/temp';
}
Expand Down
Empty file added tests/temp/database.sqlite
Empty file.

0 comments on commit 41656b2

Please sign in to comment.