Skip to content

Commit

Permalink
Merge pull request #280 from Magnesium38/handle-parens
Browse files Browse the repository at this point in the history
Handle Parentheses On Anonymous Settings Migrations
  • Loading branch information
rubenvanassche authored Aug 13, 2024
2 parents e96ad62 + 0916596 commit 9c6e6c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/LaravelSettingsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ private function removeMigrationsWhenSchemaLoaded(SchemaLoaded $event)
if (
str_contains($contents, 'return new class extends '.SettingsMigration::class)
|| str_contains($contents, 'return new class extends SettingsMigration')
|| str_contains($contents, 'return new class() extends '.SettingsMigration::class)
|| str_contains($contents, 'return new class() extends SettingsMigration')
) {
return $file->getBasename('.php');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Spatie\LaravelSettings\Migrations\SettingsBlueprint;
use Spatie\LaravelSettings\Migrations\SettingsMigration;

return new class() extends SettingsMigration {
public function up(): void
{
$this->migrator->inGroup('anonymous-class-with-parentheses-general', function (SettingsBlueprint $migrator) {
$migrator->add('name', 'laravel-settings');
$migrator->add('organization', 'spatie');
});
}
};
2 changes: 2 additions & 0 deletions tests/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@
assertDatabaseHas('migrations', ['migration' => '2018_11_21_091111_create_fake_anonymous_class_settings']);
assertDatabaseHas('migrations', ['migration' => '2018_11_21_091111_create_fake_table']);
assertDatabaseHas('migrations', ['migration' => '2018_11_21_091111_create_fake_anonymous_class_table']);
assertDatabaseHas('migrations', ['migration' => '2018_11_21_091111_create_fake_anonymous_class_with_parentheses_settings']);

event(new SchemaLoaded(
DB::connection(),
Expand All @@ -461,6 +462,7 @@

assertDatabaseMissing('migrations', ['migration' => '2018_11_21_091111_create_fake_settings']);
assertDatabaseMissing('migrations', ['migration' => '2018_11_21_091111_create_fake_anonymous_class_settings']);
assertDatabaseMissing('migrations', ['migration' => '2018_11_21_091111_create_fake_anonymous_class_with_parentheses_settings']);
assertDatabaseHas('migrations', ['migration' => '2018_11_21_091111_create_fake_table']);
assertDatabaseHas('migrations', ['migration' => '2018_11_21_091111_create_fake_anonymous_class_table']);
})->skip(fn () => Str::startsWith(app()->version(), '7'), 'No support for dumping migrations in Laravel 7');
Expand Down

0 comments on commit 9c6e6c0

Please sign in to comment.