generated from spiral-packages/package-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from spiral-packages/hotfix/seed-specific-seeder
Fixes problem with seeding seeder by given class name
- Loading branch information
Showing
6 changed files
with
111 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\DatabaseSeeder\Seeder; | ||
|
||
interface LocatorInterface | ||
{ | ||
/** | ||
* @template T of SeederInterface | ||
* @return array<class-string<T>, T> | ||
*/ | ||
public function find(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Unit\Seeder; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Spiral\DatabaseSeeder\Seeder\Locator; | ||
use Spiral\DatabaseSeeder\Seeder\LocatorInterface; | ||
use Tests\Database\Seeder\CommentSeeder; | ||
use Tests\Database\Seeder\PostSeeder; | ||
use Tests\Database\Seeder\UserSeeder; | ||
|
||
final class LocatorTest extends TestCase | ||
{ | ||
public function testFindSeederByName(): void | ||
{ | ||
$locator = new Locator( | ||
$seedersLocator = \Mockery::mock(LocatorInterface::class), | ||
); | ||
|
||
$seedersLocator->shouldReceive('find')->once()->andReturn([ | ||
$seeder = new CommentSeeder(), | ||
new PostSeeder(), | ||
new UserSeeder(), | ||
]); | ||
|
||
$seeders = $locator->findSeeders('CommentSeeder'); | ||
|
||
$this->assertEquals([$seeder], $seeders); | ||
} | ||
|
||
|
||
public function testFindAllSeeders(): void | ||
{ | ||
$locator = new Locator( | ||
$seedersLocator = \Mockery::mock(LocatorInterface::class), | ||
$directoriesSeedersLocator = \Mockery::mock(LocatorInterface::class), | ||
); | ||
|
||
$seedersLocator->shouldReceive('find') | ||
->once() | ||
->andReturn([ | ||
PostSeeder::class => new PostSeeder(), | ||
UserSeeder::class => $userSeeder = new UserSeeder(), | ||
]); | ||
|
||
$directoriesSeedersLocator->shouldReceive('find') | ||
->once() | ||
->andReturn([ | ||
PostSeeder::class => $postSeeder = new PostSeeder(), | ||
CommentSeeder::class => $commentSeeder = new CommentSeeder() | ||
]); | ||
|
||
$seeders = $locator->findSeeders(); | ||
|
||
$this->assertEquals([ | ||
$postSeeder, | ||
$commentSeeder, | ||
$userSeeder, | ||
], $seeders); | ||
} | ||
} |