Skip to content

Commit

Permalink
[8.x] Allow a specific seeder to be used in tests (#35864)
Browse files Browse the repository at this point in the history
* Allow a specific seeder to be used in tests

* if $seeder is set within a test use it instead of the default.

* Update RefreshDatabase.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
patrickomeara and taylorotwell authored Jan 13, 2021
1 parent 5c70991 commit 2cd4fd8
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Illuminate/Foundation/Testing/RefreshDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ protected function refreshTestDatabase()
*/
protected function migrateFreshUsing()
{
return [
'--drop-views' => $this->shouldDropViews(),
'--drop-types' => $this->shouldDropTypes(),
'--seed' => $this->shouldSeed(),
];
$seeder = $this->seeder();

return array_merge(
[
'--drop-views' => $this->shouldDropViews(),
'--drop-types' => $this->shouldDropTypes(),
],
$seeder ? ['--seeder' => $seeder] : ['--seed' => $this->shouldSeed()]
);
}

/**
Expand Down Expand Up @@ -157,4 +161,14 @@ protected function shouldSeed()
{
return property_exists($this, 'seed') ? $this->seed : false;
}

/**
* Determine the specific seeder class that should be used when refreshing the database.
*
* @return mixed
*/
protected function seeder()
{
return property_exists($this, 'seeder') ? $this->seeder : false;
}
}

0 comments on commit 2cd4fd8

Please sign in to comment.