From 981b9ae6294e70804540deb78b5730651b57adc3 Mon Sep 17 00:00:00 2001 From: Ivan Babenko Date: Mon, 20 May 2024 17:02:25 +0200 Subject: [PATCH 1/4] Add Laravel 11 support --- .github/workflows/code-style.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- .github/workflows/test.yml | 16 ++--- .php-cs-fixer.dist.php | 4 +- README.md | 6 +- composer.json | 14 ++-- phpstan.neon.dist | 4 +- phpunit.xml.dist | 30 ++++---- .../Adapters/IndexManagerAdapterTest.php | 68 ++++++------------- .../Integration/Console/FreshCommandTest.php | 5 +- tests/Integration/Console/MakeCommandTest.php | 5 +- .../Console/MigrateCommandTest.php | 5 +- .../Console/RefreshCommandTest.php | 5 +- .../Integration/Console/ResetCommandTest.php | 5 +- .../Console/RollbackCommandTest.php | 5 +- .../Integration/Console/StatusCommandTest.php | 5 +- tests/Integration/Facades/IndexTest.php | 5 +- .../Factories/MigrationFactoryTest.php | 19 ++---- .../Filesystem/MigrationStorageTest.php | 51 ++++---------- tests/Integration/MigratorTest.php | 56 ++++++++------- .../Repositories/MigrationRepositoryTest.php | 5 +- tests/Unit/Filesystem/MigrationFileTest.php | 5 +- 22 files changed, 124 insertions(+), 198 deletions(-) diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index abdae6b..fa2b0ce 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -12,7 +12,7 @@ jobs: - name: Install php and composer uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 coverage: none tools: composer:v2 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 55c8392..0e07f9d 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -12,7 +12,7 @@ jobs: - name: Install php and composer uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 coverage: none tools: composer:v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9d88d8d..4e541e4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,19 +7,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [7.4, 8.0, 8.1] + php: [8.2] include: - - php: 7.4 - testbench: 6.0 - phpunit: 9.5 - - - php: 8.0 - testbench: 7.0 - phpunit: 9.5 - - - php: 8.1 - testbench: 8.0 - phpunit: 9.5 + - php: 8.2 + testbench: 9.0 + phpunit: 11.0 steps: - name: Checkout code uses: actions/checkout@v2 diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f94df3a..5456d67 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -13,14 +13,14 @@ ->setRules([ '@PSR2' => true, 'array_syntax' => ['syntax' => 'short'], - 'compact_nullable_typehint' => true, + 'compact_nullable_type_declaration' => true, 'concat_space' => ['spacing' => 'one'], 'declare_strict_types' => true, 'dir_constant' => true, 'self_static_accessor' => false, 'fully_qualified_strict_types' => true, 'function_to_constant' => true, - 'function_typehint_space' => true, + 'type_declaration_spaces' => true, 'header_comment' => false, 'list_syntax' => ['syntax' => 'short'], 'lowercase_cast' => true, diff --git a/README.md b/README.md index 84f70a3..846dcf8 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,11 @@ Elastic Migrations for Laravel allow you to easily modify and share indices sche The current version of Elastic Migrations has been tested with the following configuration: -* PHP 7.4-8.x +* PHP 8.2 * Elasticsearch 8.x -* Laravel 6.x-10.x +* Laravel 11.x + +If your project uses older Laravel (or PHP) version check [the previous major version](https://github.com/babenkoivan/elastic-migrations/tree/v3.4.1#compatibility) of the package. ## Installation diff --git a/composer.json b/composer.json index 17883ed..eccda7f 100644 --- a/composer.json +++ b/composer.json @@ -40,15 +40,15 @@ } }, "require": { - "php": "^7.4 || ^8.0", - "babenkoivan/elastic-adapter": "^3.2" + "php": "^8.2", + "babenkoivan/elastic-adapter": "v4.x-dev" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "orchestra/testbench": "^8.0", + "phpunit/phpunit": "^11.0", + "orchestra/testbench": "^9.0", "friendsofphp/php-cs-fixer": "^3.14", "phpstan/phpstan": "^1.10", - "dg/bypass-finals": "^1.3" + "dg/bypass-finals": "^1.7" }, "config": { "bin-dir": "bin", @@ -62,5 +62,7 @@ "Elastic\\Migrations\\ServiceProvider" ] } - } + }, + "minimum-stability": "dev", + "prefer-stable" : true } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 8aac751..dc78996 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,9 +3,9 @@ includes: parameters: level: max - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false paths: - src ignoreErrors: + - identifier: missingType.iterableValue + - identifier: missingType.generics - '#Parameter .+? of method Illuminate\\Support\\Collection<.+?>::.+?\(\) expects .+? given#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1703511..1fd9827 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,12 @@ - - - src - - - src/ServiceProvider.php - - + colors="true" + cacheDirectory=".phpunit.cache" + requireCoverageMetadata="true" + beStrictAboutCoverageMetadata="false"> tests/Unit @@ -29,4 +19,12 @@ + + + src + + + src/ServiceProvider.php + + diff --git a/tests/Integration/Adapters/IndexManagerAdapterTest.php b/tests/Integration/Adapters/IndexManagerAdapterTest.php index e23980e..f4bb2f4 100644 --- a/tests/Integration/Adapters/IndexManagerAdapterTest.php +++ b/tests/Integration/Adapters/IndexManagerAdapterTest.php @@ -8,11 +8,11 @@ use Elastic\Adapter\Indices\Settings; use Elastic\Migrations\Adapters\IndexManagerAdapter; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; -/** - * @covers \Elastic\Migrations\Adapters\IndexManagerAdapter - */ +#[CoversClass(IndexManagerAdapter::class)] final class IndexManagerAdapterTest extends TestCase { private MockObject $indexManagerMock; @@ -26,9 +26,7 @@ protected function setUp(): void $this->indexManagerAdapter = new IndexManagerAdapter($this->indexManagerMock); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_index_can_be_created_without_modifier(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -43,9 +41,7 @@ public function test_index_can_be_created_without_modifier(string $indexNamePref $this->indexManagerAdapter->create($indexName); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_index_can_be_created_with_modifier(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -69,9 +65,7 @@ public function test_index_can_be_created_with_modifier(string $indexNamePrefix) $this->indexManagerAdapter->create($indexName, $modifier); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_index_can_be_created_with_raw_mapping(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -94,9 +88,7 @@ public function test_index_can_be_created_with_raw_mapping(string $indexNamePref $this->indexManagerAdapter->createRaw($indexName, $mapping); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_index_with_modifier_can_be_created_only_if_it_does_not_exist(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -117,9 +109,7 @@ public function test_index_with_modifier_can_be_created_only_if_it_does_not_exis $this->indexManagerAdapter->createIfNotExists($indexName); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_index_with_raw_mapping_can_be_created_only_if_it_does_not_exist(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -148,9 +138,7 @@ public function test_index_with_raw_mapping_can_be_created_only_if_it_does_not_e $this->indexManagerAdapter->createIfNotExistsRaw($indexName, $mapping); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_mapping_can_be_updated_using_modifier(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -172,9 +160,7 @@ public function test_mapping_can_be_updated_using_modifier(string $indexNamePref $this->indexManagerAdapter->putMapping($indexName, $modifier); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_mapping_can_be_updated_using_raw_input(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -195,9 +181,7 @@ public function test_mapping_can_be_updated_using_raw_input(string $indexNamePre $this->indexManagerAdapter->putMappingRaw($indexName, $mapping); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_settings_can_be_updated_using_modifier(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -219,9 +203,7 @@ public function test_settings_can_be_updated_using_modifier(string $indexNamePre $this->indexManagerAdapter->putSettings($indexName, $modifier); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_settings_can_be_updated_using_raw_input(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -237,9 +219,7 @@ public function test_settings_can_be_updated_using_raw_input(string $indexNamePr $this->indexManagerAdapter->putSettingsRaw($indexName, $settings); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_settings_can_be_pushed_using_modifier(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -271,9 +251,7 @@ public function test_settings_can_be_pushed_using_modifier(string $indexNamePref $this->indexManagerAdapter->pushSettings($indexName, $modifier); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_settings_can_be_pushed_using_raw_input(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -299,9 +277,7 @@ public function test_settings_can_be_pushed_using_raw_input(string $indexNamePre $this->indexManagerAdapter->pushSettingsRaw($indexName, $settings); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_index_can_be_dropped(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -316,9 +292,7 @@ public function test_index_can_be_dropped(string $indexNamePrefix): void $this->indexManagerAdapter->drop($indexName); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_index_can_be_dropped_only_if_exists(string $indexNamePrefix): void { $this->config->set('elastic.migrations.prefixes.index', $indexNamePrefix); @@ -339,9 +313,7 @@ public function test_index_can_be_dropped_only_if_exists(string $indexNamePrefix $this->indexManagerAdapter->dropIfExists($indexName); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_alias_can_be_created(string $aliasNamePrefix): void { $this->config->set('elastic.migrations.prefixes.alias', $aliasNamePrefix); @@ -357,9 +329,7 @@ public function test_alias_can_be_created(string $aliasNamePrefix): void $this->indexManagerAdapter->putAlias($indexName, $aliasName); } - /** - * @dataProvider prefixProvider - */ + #[DataProvider('prefixProvider')] public function test_alias_can_be_deleted(string $aliasNamePrefix): void { $this->config->set('elastic.migrations.prefixes.alias', $aliasNamePrefix); @@ -387,7 +357,7 @@ public function test_connection_can_be_changed(): void $this->indexManagerAdapter->connection($connection); } - public function prefixProvider(): array + public static function prefixProvider(): array { return [ 'no prefix' => [''], diff --git a/tests/Integration/Console/FreshCommandTest.php b/tests/Integration/Console/FreshCommandTest.php index 788c1b0..40dc1ca 100644 --- a/tests/Integration/Console/FreshCommandTest.php +++ b/tests/Integration/Console/FreshCommandTest.php @@ -7,13 +7,12 @@ use Elastic\Migrations\Migrator; use Elastic\Migrations\Repositories\MigrationRepository; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -/** - * @covers \Elastic\Migrations\Console\FreshCommand - */ +#[CoversClass(FreshCommand::class)] final class FreshCommandTest extends TestCase { private MockObject $migrator; diff --git a/tests/Integration/Console/MakeCommandTest.php b/tests/Integration/Console/MakeCommandTest.php index 7da56e1..9a64752 100644 --- a/tests/Integration/Console/MakeCommandTest.php +++ b/tests/Integration/Console/MakeCommandTest.php @@ -5,12 +5,11 @@ use Elastic\Migrations\Console\MakeCommand; use Elastic\Migrations\Filesystem\MigrationStorage; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; -/** - * @covers \Elastic\Migrations\Console\MakeCommand - */ +#[CoversClass(MakeCommand::class)] final class MakeCommandTest extends TestCase { public function test_migration_file_can_be_created(): void diff --git a/tests/Integration/Console/MigrateCommandTest.php b/tests/Integration/Console/MigrateCommandTest.php index f7d606a..b2ef1fc 100644 --- a/tests/Integration/Console/MigrateCommandTest.php +++ b/tests/Integration/Console/MigrateCommandTest.php @@ -5,13 +5,12 @@ use Elastic\Migrations\Console\MigrateCommand; use Elastic\Migrations\Migrator; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -/** - * @covers \Elastic\Migrations\Console\MigrateCommand - */ +#[CoversClass(MigrateCommand::class)] final class MigrateCommandTest extends TestCase { private MockObject $migrator; diff --git a/tests/Integration/Console/RefreshCommandTest.php b/tests/Integration/Console/RefreshCommandTest.php index 9268759..4b0bdf9 100644 --- a/tests/Integration/Console/RefreshCommandTest.php +++ b/tests/Integration/Console/RefreshCommandTest.php @@ -5,13 +5,12 @@ use Elastic\Migrations\Console\RefreshCommand; use Elastic\Migrations\Migrator; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -/** - * @covers \Elastic\Migrations\Console\RefreshCommand - */ +#[CoversClass(RefreshCommand::class)] final class RefreshCommandTest extends TestCase { private MockObject $migrator; diff --git a/tests/Integration/Console/ResetCommandTest.php b/tests/Integration/Console/ResetCommandTest.php index 682407e..a745892 100644 --- a/tests/Integration/Console/ResetCommandTest.php +++ b/tests/Integration/Console/ResetCommandTest.php @@ -5,13 +5,12 @@ use Elastic\Migrations\Console\ResetCommand; use Elastic\Migrations\Migrator; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -/** - * @covers \Elastic\Migrations\Console\ResetCommand - */ +#[CoversClass(ResetCommand::class)] final class ResetCommandTest extends TestCase { private MockObject $migrator; diff --git a/tests/Integration/Console/RollbackCommandTest.php b/tests/Integration/Console/RollbackCommandTest.php index 9a2ec9a..62fdb27 100644 --- a/tests/Integration/Console/RollbackCommandTest.php +++ b/tests/Integration/Console/RollbackCommandTest.php @@ -5,13 +5,12 @@ use Elastic\Migrations\Console\RollbackCommand; use Elastic\Migrations\Migrator; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -/** - * @covers \Elastic\Migrations\Console\RollbackCommand - */ +#[CoversClass(RollbackCommand::class)] final class RollbackCommandTest extends TestCase { private MockObject $migrator; diff --git a/tests/Integration/Console/StatusCommandTest.php b/tests/Integration/Console/StatusCommandTest.php index 3462ed0..fda7691 100644 --- a/tests/Integration/Console/StatusCommandTest.php +++ b/tests/Integration/Console/StatusCommandTest.php @@ -5,13 +5,12 @@ use Elastic\Migrations\Console\StatusCommand; use Elastic\Migrations\Migrator; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -/** - * @covers \Elastic\Migrations\Console\StatusCommand - */ +#[CoversClass(StatusCommand::class)] final class StatusCommandTest extends TestCase { private MockObject $migrator; diff --git a/tests/Integration/Facades/IndexTest.php b/tests/Integration/Facades/IndexTest.php index f6d23ac..babc84c 100644 --- a/tests/Integration/Facades/IndexTest.php +++ b/tests/Integration/Facades/IndexTest.php @@ -5,10 +5,9 @@ use Elastic\Migrations\Facades\Index; use Elastic\Migrations\IndexManagerInterface; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @covers \Elastic\Migrations\Facades\Index - */ +#[CoversClass(Index::class)] final class IndexTest extends TestCase { public function test_facade_instantiates_instance_of_correct_type(): void diff --git a/tests/Integration/Factories/MigrationFactoryTest.php b/tests/Integration/Factories/MigrationFactoryTest.php index feb8880..331d318 100644 --- a/tests/Integration/Factories/MigrationFactoryTest.php +++ b/tests/Integration/Factories/MigrationFactoryTest.php @@ -7,10 +7,10 @@ use Elastic\Migrations\Filesystem\MigrationStorage; use Elastic\Migrations\MigrationInterface; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestWith; -/** - * @covers \Elastic\Migrations\Factories\MigrationFactory - */ +#[CoversClass(MigrationFactory::class)] final class MigrationFactoryTest extends TestCase { private MigrationFactory $migrationFactory; @@ -24,17 +24,8 @@ protected function setUp(): void $this->migrationStorage = resolve(MigrationStorage::class); } - public function fileNameProvider(): array - { - return [ - ['2018_12_01_081000_create_test_index'], - ['2019_08_10_142230_update_test_index_mapping'], - ]; - } - - /** - * @dataProvider fileNameProvider - */ + #[TestWith(['2018_12_01_081000_create_test_index'])] + #[TestWith(['2019_08_10_142230_update_test_index_mapping'])] public function test_migration_can_be_created_from_file(string $fileName): void { /** @var MigrationFile $file */ diff --git a/tests/Integration/Filesystem/MigrationStorageTest.php b/tests/Integration/Filesystem/MigrationStorageTest.php index 14aa288..a7ee6a8 100644 --- a/tests/Integration/Filesystem/MigrationStorageTest.php +++ b/tests/Integration/Filesystem/MigrationStorageTest.php @@ -5,10 +5,10 @@ use Elastic\Migrations\Filesystem\MigrationFile; use Elastic\Migrations\Filesystem\MigrationStorage; use Elastic\Migrations\Tests\Integration\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestWith; -/** - * @covers \Elastic\Migrations\Filesystem\MigrationStorage - */ +#[CoversClass(MigrationStorage::class)] final class MigrationStorageTest extends TestCase { private MigrationStorage $migrationStorage; @@ -21,36 +21,8 @@ protected function setUp(): void $this->migrationStorage->registerPaths([__DIR__ . '/../../migrations/archive']); } - public function newFileNameProvider(): array - { - return [ - ['2022_06_01_223400_create_new_index'], - [__DIR__ . '/../../migrations/archive/2022_06_01_223400_create_new_index.php'], - ]; - } - - public function existingFileNameProvider(): array - { - return [ - ['2018_12_01_081000_create_test_index'], - ['2019_08_10_142230_update_test_index_mapping'], - [__DIR__ . '/../../migrations/archive/2017_11_11_100000_create_test_alias.php'], - ]; - } - - public function nonExistingFileNameProvider(): array - { - return [ - ['3030_01_01_000000_non_existing_file'], - ['test'], - [''], - [__DIR__ . '/../../migrations/archive/3030_01_01_000000_non_existing_file.php'], - ]; - } - - /** - * @dataProvider newFileNameProvider - */ + #[TestWith(['2022_06_01_223400_create_new_index'])] + #[TestWith([__DIR__ . '/../../migrations/archive/2022_06_01_223400_create_new_index.php'])] public function test_file_can_be_created(string $fileName): void { $file = $this->migrationStorage->create($fileName, 'content'); @@ -78,9 +50,9 @@ public function test_directory_is_created_along_with_file(): void @rmdir($defaultPath); } - /** - * @dataProvider existingFileNameProvider - */ + #[TestWith(['2018_12_01_081000_create_test_index'])] + #[TestWith(['2019_08_10_142230_update_test_index_mapping'])] + #[TestWith([__DIR__ . '/../../migrations/archive/2017_11_11_100000_create_test_alias.php'])] public function test_file_can_be_retrieved_if_exists(string $fileName): void { /** @var MigrationFile $file */ @@ -89,9 +61,10 @@ public function test_file_can_be_retrieved_if_exists(string $fileName): void $this->assertSame(basename($fileName, MigrationFile::FILE_EXTENSION), $file->name()); } - /** - * @dataProvider nonExistingFileNameProvider - */ + #[TestWith(['3030_01_01_000000_non_existing_file'])] + #[TestWith(['test'])] + #[TestWith([''])] + #[TestWith([__DIR__ . '/../../migrations/archive/3030_01_01_000000_non_existing_file.php'])] public function test_file_can_not_be_retrieved_if_it_does_not_exist(string $fileName): void { $file = $this->migrationStorage->whereName($fileName); diff --git a/tests/Integration/MigratorTest.php b/tests/Integration/MigratorTest.php index 0a9ea85..c243b0a 100644 --- a/tests/Integration/MigratorTest.php +++ b/tests/Integration/MigratorTest.php @@ -9,11 +9,11 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; -/** - * @covers \Elastic\Migrations\Migrator - */ +#[CoversClass(Migrator::class)] final class MigratorTest extends TestCase { use RefreshDatabase; @@ -56,9 +56,11 @@ public function test_single_migration_can_be_executed_if_file_exists(): void $this->output ->expects($this->exactly(2)) ->method('writeln') - ->withConsecutive( - ['Migrating: 2019_08_10_142230_update_test_index_mapping'], - ['Migrated: 2019_08_10_142230_update_test_index_mapping'] + ->with( + $this->callback(static fn (string $message) => in_array($message, [ + 'Migrating: 2019_08_10_142230_update_test_index_mapping', + 'Migrated: 2019_08_10_142230_update_test_index_mapping', + ])) ); $this->assertSame( @@ -102,9 +104,11 @@ public function test_all_migrations_can_be_executed_if_directory_is_not_empty(): $this->output ->expects($this->exactly(2)) ->method('writeln') - ->withConsecutive( - ['Migrating: 2019_08_10_142230_update_test_index_mapping'], - ['Migrated: 2019_08_10_142230_update_test_index_mapping'] + ->with( + $this->callback(static fn (string $message) => in_array($message, [ + 'Migrating: 2019_08_10_142230_update_test_index_mapping', + 'Migrated: 2019_08_10_142230_update_test_index_mapping', + ])) ); $this->assertSame( @@ -151,9 +155,11 @@ public function test_single_migration_can_be_rolled_back_if_file_exists_and_is_m $this->output ->expects($this->exactly(2)) ->method('writeln') - ->withConsecutive( - ['Rolling back: 2018_12_01_081000_create_test_index'], - ['Rolled back: 2018_12_01_081000_create_test_index'] + ->with( + $this->callback(static fn (string $message) => in_array($message, [ + 'Rolling back: 2018_12_01_081000_create_test_index', + 'Rolled back: 2018_12_01_081000_create_test_index', + ])) ); $this->assertSame( @@ -197,9 +203,11 @@ public function test_last_batch_can_be_rolled_back_if_all_files_are_present(): v $this->output ->expects($this->exactly(2)) ->method('writeln') - ->withConsecutive( - ['Rolling back: 2019_08_10_142230_update_test_index_mapping'], - ['Rolled back: 2019_08_10_142230_update_test_index_mapping'] + ->with( + $this->callback(static fn (string $message) => in_array($message, [ + 'Rolling back: 2019_08_10_142230_update_test_index_mapping', + 'Rolled back: 2019_08_10_142230_update_test_index_mapping', + ])) ); $this->assertSame( @@ -247,11 +255,13 @@ public function test_all_migrations_can_be_rolled_back_if_all_files_are_present( $this->output ->expects($this->exactly(4)) ->method('writeln') - ->withConsecutive( - ['Rolling back: 2019_08_10_142230_update_test_index_mapping'], - ['Rolled back: 2019_08_10_142230_update_test_index_mapping'], - ['Rolling back: 2018_12_01_081000_create_test_index'], - ['Rolled back: 2018_12_01_081000_create_test_index'] + ->with( + $this->callback(static fn (string $message) => in_array($message, [ + 'Rolling back: 2019_08_10_142230_update_test_index_mapping', + 'Rolled back: 2019_08_10_142230_update_test_index_mapping', + 'Rolling back: 2018_12_01_081000_create_test_index', + 'Rolled back: 2018_12_01_081000_create_test_index', + ])) ); $this->assertSame( @@ -270,7 +280,7 @@ public function test_all_migrations_can_be_rolled_back_if_all_files_are_present( ]); } - public function statusDataProvider(): array + public static function statusDataProvider(): array { return [ 'all migrations' => [ @@ -289,9 +299,7 @@ public function statusDataProvider(): array ]; } - /** - * @dataProvider statusDataProvider - */ + #[DataProvider('statusDataProvider')] public function test_status_is_displayed_correctly(bool $onlyPending, array $expectedOutput): void { $this->output diff --git a/tests/Integration/Repositories/MigrationRepositoryTest.php b/tests/Integration/Repositories/MigrationRepositoryTest.php index a20d88b..56c072b 100644 --- a/tests/Integration/Repositories/MigrationRepositoryTest.php +++ b/tests/Integration/Repositories/MigrationRepositoryTest.php @@ -7,10 +7,9 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @covers \Elastic\Migrations\Repositories\MigrationRepository - */ +#[CoversClass(MigrationRepository::class)] final class MigrationRepositoryTest extends TestCase { use RefreshDatabase; diff --git a/tests/Unit/Filesystem/MigrationFileTest.php b/tests/Unit/Filesystem/MigrationFileTest.php index 739d4cb..37fee4b 100644 --- a/tests/Unit/Filesystem/MigrationFileTest.php +++ b/tests/Unit/Filesystem/MigrationFileTest.php @@ -3,11 +3,10 @@ namespace Elastic\Migrations\Tests\Unit\Filesystem; use Elastic\Migrations\Filesystem\MigrationFile; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \Elastic\Migrations\Filesystem\MigrationFile - */ +#[CoversClass(MigrationFile::class)] final class MigrationFileTest extends TestCase { private const FULL_PATH = '/tmp/test.php'; From fbc997db5c2dbd932cc8b29d3706eda84792eca8 Mon Sep 17 00:00:00 2001 From: Ivan Babenko Date: Mon, 27 May 2024 19:04:06 +0200 Subject: [PATCH 2/4] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6f53677..709af77 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /vendor /composer.lock /phpunit.xml -/.phpunit.result.cache +/.phpunit.cache /.php_cs /.php_cs.cache /.php-cs-fixer.cache From 4556f8ea9a127fedfa69c68ee5398cd2d3d0e636 Mon Sep 17 00:00:00 2001 From: Ivan Babenko Date: Tue, 4 Jun 2024 09:12:08 +0200 Subject: [PATCH 3/4] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 709af77..6f53677 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /vendor /composer.lock /phpunit.xml -/.phpunit.cache +/.phpunit.result.cache /.php_cs /.php_cs.cache /.php-cs-fixer.cache From a046c8b1489359797c49f2235fdbd58dad5cf54c Mon Sep 17 00:00:00 2001 From: Ivan Babenko Date: Tue, 18 Jun 2024 09:01:48 +0200 Subject: [PATCH 4/4] Update .gitignore and composer dependencies --- .gitignore | 1 + composer.json | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6f53677..4758b36 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /vendor /composer.lock /phpunit.xml +/.phpunit.cache /.phpunit.result.cache /.php_cs /.php_cs.cache diff --git a/composer.json b/composer.json index eccda7f..cf9ca8a 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ }, "require": { "php": "^8.2", - "babenkoivan/elastic-adapter": "v4.x-dev" + "babenkoivan/elastic-adapter": "^4.0" }, "require-dev": { "phpunit/phpunit": "^11.0", @@ -62,7 +62,5 @@ "Elastic\\Migrations\\ServiceProvider" ] } - }, - "minimum-stability": "dev", - "prefer-stable" : true + } }