diff --git a/app/src/Database/Migrations/V100/PastriesTable.php b/app/src/Database/Migrations/V100/PastriesTable.php index ae8a137..be5b664 100644 --- a/app/src/Database/Migrations/V100/PastriesTable.php +++ b/app/src/Database/Migrations/V100/PastriesTable.php @@ -12,6 +12,7 @@ use Illuminate\Database\Schema\Blueprint; use UserFrosting\Sprinkle\Core\Database\Migration; +use UserFrosting\Sprinkle\Pastries\Database\Seeds\DefaultPastries; class PastriesTable extends Migration { @@ -31,6 +32,10 @@ public function up(): void $table->collation = 'utf8_unicode_ci'; $table->charset = 'utf8'; }); + + // Run Seed for default pastries + $seed = new DefaultPastries(); + $seed->run(); } /** diff --git a/app/src/Database/Migrations/V100/DefaultPastries.php b/app/src/Database/Seeds/DefaultPastries.php similarity index 74% rename from app/src/Database/Migrations/V100/DefaultPastries.php rename to app/src/Database/Seeds/DefaultPastries.php index 988c672..44ecb2f 100644 --- a/app/src/Database/Migrations/V100/DefaultPastries.php +++ b/app/src/Database/Seeds/DefaultPastries.php @@ -1,5 +1,7 @@ pastries() as $pastry) { $pastry = new Pastries($pastry); @@ -33,18 +31,6 @@ public function up(): void } } - /** - * {@inheritdoc} - */ - public function down(): void - { - foreach ($this->pastries() as $pastry) { - /** @var Pastries */ - $pastry = Pastries::where($pastry)->first(); - $pastry->delete(); - } - } - /** * @return string[][] */ diff --git a/app/src/MyApp.php b/app/src/MyApp.php index 52cec52..86b8d95 100644 --- a/app/src/MyApp.php +++ b/app/src/MyApp.php @@ -14,13 +14,14 @@ use UserFrosting\Sprinkle\Admin\Admin; use UserFrosting\Sprinkle\Core\Core; use UserFrosting\Sprinkle\Core\Sprinkle\Recipe\MigrationRecipe; -use UserFrosting\Sprinkle\Pastries\Database\Migrations\V100\DefaultPastries; +use UserFrosting\Sprinkle\Core\Sprinkle\Recipe\SeedRecipe; use UserFrosting\Sprinkle\Pastries\Database\Migrations\V100\PastriesPermissions; use UserFrosting\Sprinkle\Pastries\Database\Migrations\V100\PastriesTable; +use UserFrosting\Sprinkle\Pastries\Database\Seeds\DefaultPastries; use UserFrosting\Sprinkle\SprinkleRecipe; use UserFrosting\Theme\AdminLTE\AdminLTE; -class MyApp implements SprinkleRecipe, MigrationRecipe +class MyApp implements SprinkleRecipe, MigrationRecipe, SeedRecipe { /** * {@inheritdoc} @@ -82,8 +83,19 @@ public function getMigrations(): array { return [ PastriesTable::class, - DefaultPastries::class, PastriesPermissions::class, ]; } + + /** + * {@inheritDoc} + * + * @codeCoverageIgnore + */ + public function getSeeds(): array + { + return [ + DefaultPastries::class, + ]; + } } diff --git a/app/tests/PastriesControllerTest.php b/app/tests/PastriesControllerTest.php index 4a4a65d..4d6ff0a 100644 --- a/app/tests/PastriesControllerTest.php +++ b/app/tests/PastriesControllerTest.php @@ -15,11 +15,10 @@ use UserFrosting\Sprinkle\Account\Database\Models\User; use UserFrosting\Sprinkle\Account\Testing\WithTestUser; use UserFrosting\Sprinkle\Core\Testing\RefreshDatabase; -use UserFrosting\Sprinkle\Pastries\MyApp; -use UserFrosting\Sprinkle\Pastries\Database\Migrations\V100\DefaultPastries; use UserFrosting\Sprinkle\Pastries\Database\Migrations\V100\PastriesPermissions; use UserFrosting\Sprinkle\Pastries\Database\Migrations\V100\PastriesTable; use UserFrosting\Sprinkle\Pastries\Database\Models\Pastries; +use UserFrosting\Sprinkle\Pastries\MyApp; use UserFrosting\Testing\TestCase; /** @@ -60,12 +59,8 @@ public function testMigrations(): void $this->assertNotNull(Permission::where('slug', 'see_pastry_origin')->first()); // Migration down data migration - $this->ci->get(DefaultPastries::class)->down(); $this->ci->get(PastriesPermissions::class)->down(); - // Make sure Pastries were removed - $this->assertSame(0, Pastries::count()); - // Make sure permissions were removed $this->assertNull(Permission::where('slug', 'see_pastries')->first()); $this->assertNull(Permission::where('slug', 'see_pastry_origin')->first()); @@ -76,7 +71,6 @@ public function testMigrations(): void // Run back on, to avoid conflict with further tests $this->ci->get(PastriesTable::class)->up(); - $this->ci->get(DefaultPastries::class)->up(); $this->ci->get(PastriesPermissions::class)->up(); }