diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
index 63cdde1..ec9d02c 100644
--- a/.github/workflows/run-tests.yml
+++ b/.github/workflows/run-tests.yml
@@ -50,9 +50,8 @@ jobs:
- name: Install dependencies
run: |
- ruby -rjson -e 'composer = JSON.parse(File.read("composer.json")); composer["repositories"] = [{"type" => "vcs", "url" => "https://github.com/DirectoryTree/OpenSearchAdapter"}, {"type" => "vcs", "url" => "https://github.com/DirectoryTree/OpenSearchClient"}]; File.write("composer.json", JSON.pretty_generate(composer))'
- composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --no-blocking
- composer update --prefer-dist --no-interaction --no-blocking
+ composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
+ composer update --prefer-dist --no-interaction
- name: Wait for OpenSearch
run: |
diff --git a/composer.json b/composer.json
index f63f74a..9cfe680 100644
--- a/composer.json
+++ b/composer.json
@@ -27,7 +27,7 @@
},
"require": {
"php": "^8.2",
- "directorytree/opensearch-adapter": "^1.0",
+ "directorytree/opensearch-adapter": "^1.2.1",
"directorytree/opensearch-client": "^1.0",
"illuminate/console": "^11.0|^12.0|^13.0",
"illuminate/database": "^11.0|^12.0|^13.0",
@@ -41,26 +41,6 @@
"orchestra/testbench": "^9.0|^10.0|^11.0",
"pestphp/pest": "^3.0"
},
- "repositories": [
- {
- "type": "path",
- "url": "../OpenSearchAdapter",
- "options": {
- "versions": {
- "directorytree/opensearch-adapter": "1.0.1"
- }
- }
- },
- {
- "type": "path",
- "url": "../OpenSearchClient",
- "options": {
- "versions": {
- "directorytree/opensearch-client": "1.0.0"
- }
- }
- }
- ],
"config": {
"allow-plugins": {
"php-http/discovery": true,
@@ -73,5 +53,7 @@
"DirectoryTree\\OpenSearchMigrations\\OpenSearchMigrationsServiceProvider"
]
}
- }
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true
}
diff --git a/src/Testing/Fakes/FakeIndexManager.php b/src/Testing/Fakes/FakeIndexManager.php
index 11e48b9..8e67777 100644
--- a/src/Testing/Fakes/FakeIndexManager.php
+++ b/src/Testing/Fakes/FakeIndexManager.php
@@ -144,10 +144,18 @@ public function assertChecked(string $index): static
/**
* Assert that the given index was created.
+ *
+ * @param (callable(?Mapping, ?Settings): bool)|null $callback
*/
- public function assertCreated(string $index, ?callable $modifier = null): static
+ public function assertCreated(string $index, ?callable $callback = null): static
{
- $this->manager->assertCreated($this->blueprint($index, $modifier));
+ $this->manager->assertCreated(
+ MigrationPrefix::index($index),
+ $callback ? fn (IndexBlueprint $index): bool => $callback(
+ $index->mapping(),
+ $index->settings(),
+ ) : null,
+ );
return $this;
}
@@ -164,24 +172,30 @@ public function assertNotCreated(string $index): static
/**
* Assert that the given index mapping was updated.
+ *
+ * @param (callable(Mapping): bool)|null $callback
*/
- public function assertMappingPut(string $index, callable $modifier): static
+ public function assertMappingPut(string $index, ?callable $callback = null): static
{
- $modifier($mapping = new Mapping);
-
- $this->manager->assertMappingPut(MigrationPrefix::index($index), $mapping);
+ $this->manager->assertMappingPut(
+ MigrationPrefix::index($index),
+ $callback,
+ );
return $this;
}
/**
* Assert that the given index settings were updated.
+ *
+ * @param (callable(Settings): bool)|null $callback
*/
- public function assertSettingsPut(string $index, callable $modifier): static
+ public function assertSettingsPut(string $index, ?callable $callback = null): static
{
- $modifier($settings = new Settings);
-
- $this->manager->assertSettingsPut(MigrationPrefix::index($index), $settings);
+ $this->manager->assertSettingsPut(
+ MigrationPrefix::index($index),
+ $callback,
+ );
return $this;
}
@@ -243,21 +257,4 @@ public function assertAliasDeleted(string $index, string $alias): static
return $this;
}
-
- /**
- * Create an index blueprint for an assertion.
- */
- protected function blueprint(string $index, ?callable $modifier = null): IndexBlueprint
- {
- if (isset($modifier)) {
- $modifier(
- $mapping = new Mapping,
- $settings = new Settings,
- );
-
- return new IndexBlueprint(MigrationPrefix::index($index), $mapping, $settings);
- }
-
- return new IndexBlueprint(MigrationPrefix::index($index));
- }
}
diff --git a/tests/Integration/Console/FreshCommandTest.php b/tests/Integration/Console/FreshCommandTest.php
index 3befac8..276c89d 100644
--- a/tests/Integration/Console/FreshCommandTest.php
+++ b/tests/Integration/Console/FreshCommandTest.php
@@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
-it('drops indices and migrations', function (): void {
+it('drops indices and migrations', function () {
$migrator = Mockery::mock(Migrator::class);
$repository = Mockery::mock(MigrationRepository::class);
$index = Mockery::mock(IndexManagerInterface::class);
diff --git a/tests/Integration/Console/MakeCommandTest.php b/tests/Integration/Console/MakeCommandTest.php
index 49eec9b..cc7826b 100644
--- a/tests/Integration/Console/MakeCommandTest.php
+++ b/tests/Integration/Console/MakeCommandTest.php
@@ -5,7 +5,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
-it('creates migration files', function (): void {
+it('creates migration files', function () {
$migrations = Mockery::mock(MigrationStorage::class);
app()->instance(MigrationStorage::class, $migrations);
diff --git a/tests/Integration/Console/MigrateCommandTest.php b/tests/Integration/Console/MigrateCommandTest.php
index bf80468..ca7f8de 100644
--- a/tests/Integration/Console/MigrateCommandTest.php
+++ b/tests/Integration/Console/MigrateCommandTest.php
@@ -5,7 +5,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
-it('runs one migration when a file name is provided', function (): void {
+it('runs one migration when a file name is provided', function () {
$migrator = Mockery::mock(Migrator::class);
app()->instance(Migrator::class, $migrator);
@@ -20,7 +20,7 @@
expect($command->run(new ArrayInput(['--force' => true, 'fileName' => 'test_file_name']), new NullOutput))->toBe(0);
});
-it('runs all migrations when a file name is not provided', function (): void {
+it('runs all migrations when a file name is not provided', function () {
$migrator = Mockery::mock(Migrator::class);
app()->instance(Migrator::class, $migrator);
diff --git a/tests/Integration/Console/RefreshCommandTest.php b/tests/Integration/Console/RefreshCommandTest.php
index 79b25c6..8133c64 100644
--- a/tests/Integration/Console/RefreshCommandTest.php
+++ b/tests/Integration/Console/RefreshCommandTest.php
@@ -5,7 +5,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
-it('resets and reruns all migrations', function (): void {
+it('resets and reruns all migrations', function () {
$migrator = Mockery::mock(Migrator::class);
app()->instance(Migrator::class, $migrator);
diff --git a/tests/Integration/Console/ResetCommandTest.php b/tests/Integration/Console/ResetCommandTest.php
index c7d607d..82f848e 100644
--- a/tests/Integration/Console/ResetCommandTest.php
+++ b/tests/Integration/Console/ResetCommandTest.php
@@ -5,7 +5,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
-it('rolls back all migrations', function (): void {
+it('rolls back all migrations', function () {
$migrator = Mockery::mock(Migrator::class);
app()->instance(Migrator::class, $migrator);
diff --git a/tests/Integration/Console/RollbackCommandTest.php b/tests/Integration/Console/RollbackCommandTest.php
index b0786f0..269ff70 100644
--- a/tests/Integration/Console/RollbackCommandTest.php
+++ b/tests/Integration/Console/RollbackCommandTest.php
@@ -5,7 +5,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
-it('rolls back one migration when a file name is provided', function (): void {
+it('rolls back one migration when a file name is provided', function () {
$migrator = Mockery::mock(Migrator::class);
app()->instance(Migrator::class, $migrator);
@@ -20,7 +20,7 @@
expect($command->run(new ArrayInput(['--force' => true, 'fileName' => 'test_file_name']), new NullOutput))->toBe(0);
});
-it('rolls back the last batch when a file name is not provided', function (): void {
+it('rolls back the last batch when a file name is not provided', function () {
$migrator = Mockery::mock(Migrator::class);
app()->instance(Migrator::class, $migrator);
diff --git a/tests/Integration/Console/StatusCommandTest.php b/tests/Integration/Console/StatusCommandTest.php
index 39b703b..7ff9360 100644
--- a/tests/Integration/Console/StatusCommandTest.php
+++ b/tests/Integration/Console/StatusCommandTest.php
@@ -5,7 +5,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
-it('shows migration status', function (): void {
+it('shows migration status', function () {
$migrator = Mockery::mock(Migrator::class);
app()->instance(Migrator::class, $migrator);
diff --git a/tests/Integration/Factories/MigrationFactoryTest.php b/tests/Integration/Factories/MigrationFactoryTest.php
index 2914430..ac66a02 100644
--- a/tests/Integration/Factories/MigrationFactoryTest.php
+++ b/tests/Integration/Factories/MigrationFactoryTest.php
@@ -4,7 +4,7 @@
use DirectoryTree\OpenSearchMigrations\Filesystem\MigrationStorage;
use DirectoryTree\OpenSearchMigrations\MigrationInterface;
-it('creates migrations from files', function (string $fileName): void {
+it('creates migrations from files', function (string $fileName) {
$file = resolve(MigrationStorage::class)->find($fileName);
expect(resolve(MigrationFactory::class)->makeFromFile($file))->toBeInstanceOf(MigrationInterface::class);
diff --git a/tests/Integration/Filesystem/MigrationStorageTest.php b/tests/Integration/Filesystem/MigrationStorageTest.php
index e0bb6fa..7e8556e 100644
--- a/tests/Integration/Filesystem/MigrationStorageTest.php
+++ b/tests/Integration/Filesystem/MigrationStorageTest.php
@@ -3,7 +3,7 @@
use DirectoryTree\OpenSearchMigrations\Filesystem\MigrationFile;
use DirectoryTree\OpenSearchMigrations\Filesystem\MigrationStorage;
-it('creates files', function (): void {
+it('creates files', function () {
$storage = resolve(MigrationStorage::class);
$fileName = uniqid();
@@ -16,7 +16,7 @@
@unlink($file->path());
});
-it('creates the directory along with the file', function (): void {
+it('creates the directory along with the file', function () {
$directory = config('opensearch-migrations.storage_directory');
$firstLevelDirectory = $directory.'/nested';
$secondLevelDirectory = $firstLevelDirectory.'/directories';
@@ -33,7 +33,7 @@
@rmdir($firstLevelDirectory);
});
-it('prepares when the directory exists', function (): void {
+it('prepares when the directory exists', function () {
$directory = config('opensearch-migrations.storage_directory');
resolve(MigrationStorage::class)->prepare();
@@ -41,7 +41,7 @@
expect($directory)->toBeDirectory();
});
-it('creates the directory when preparing', function (): void {
+it('creates the directory when preparing', function () {
$directory = sys_get_temp_dir().'/opensearch_migrations_missing_storage';
config()->set('opensearch-migrations.storage_directory', $directory);
@@ -53,7 +53,7 @@
@rmdir($directory);
});
-it('finds existing files', function (string $fileName): void {
+it('finds existing files', function (string $fileName) {
$file = resolve(MigrationStorage::class)->find($fileName);
expect($file)->toBeInstanceOf(MigrationFile::class);
@@ -65,7 +65,7 @@
['2019_08_10_142230_update_test_index_mapping.php'],
]);
-it('does not find missing files', function (string $fileName): void {
+it('does not find missing files', function (string $fileName) {
expect(resolve(MigrationStorage::class)->find($fileName))->toBeNull();
})->with([
['2020_12_01_081000_create_test_index'],
@@ -74,7 +74,7 @@
['2020_08_10_142230_update_test_index_mapping.php'],
]);
-it('retrieves all migration files', function (): void {
+it('retrieves all migration files', function () {
$files = resolve(MigrationStorage::class)->all();
expect($files->map(fn (MigrationFile $file) => $file->name())->toArray())->toBe([
diff --git a/tests/Integration/MigratorTest.php b/tests/Integration/MigratorTest.php
index aa6916f..a10eb65 100644
--- a/tests/Integration/MigratorTest.php
+++ b/tests/Integration/MigratorTest.php
@@ -34,7 +34,7 @@ function outputExpectingLines(array $lines): OutputStyle
return $output;
}
-it('does not run a missing single migration', function (): void {
+it('does not run a missing single migration', function () {
$output = outputExpectingLines([
'Migration is not found: 3020_11_01_045023_drop_test_index',
]);
@@ -44,7 +44,7 @@ function outputExpectingLines(array $lines): OutputStyle
expect($migrator->migrateOne('3020_11_01_045023_drop_test_index'))->toBe($migrator);
});
-it('runs a single migration when it exists', function (): void {
+it('runs a single migration when it exists', function () {
Index::shouldReceive('putMapping')->once();
$output = outputExpectingLines([
@@ -61,7 +61,7 @@ function outputExpectingLines(array $lines): OutputStyle
])->exists())->toBeTrue();
});
-it('does not run all migrations when the directory is empty', function (): void {
+it('does not run all migrations when the directory is empty', function () {
$tmpDirectory = config('opensearch-migrations.storage_directory').'/tmp';
@mkdir($tmpDirectory);
@@ -78,7 +78,7 @@ function outputExpectingLines(array $lines): OutputStyle
@rmdir($tmpDirectory);
});
-it('runs all outstanding migrations', function (): void {
+it('runs all outstanding migrations', function () {
Index::shouldReceive('putMapping')->once();
$output = outputExpectingLines([
@@ -95,7 +95,7 @@ function outputExpectingLines(array $lines): OutputStyle
])->exists())->toBeTrue();
});
-it('does not roll back a missing single migration', function (): void {
+it('does not roll back a missing single migration', function () {
$output = outputExpectingLines([
'Migration is not found: 3020_11_01_045023_drop_test_index',
]);
@@ -105,7 +105,7 @@ function outputExpectingLines(array $lines): OutputStyle
expect($migrator->rollbackOne('3020_11_01_045023_drop_test_index'))->toBe($migrator);
});
-it('does not roll back a migration that has not run', function (): void {
+it('does not roll back a migration that has not run', function () {
$output = outputExpectingLines([
'Migration is not yet migrated: 2019_08_10_142230_update_test_index_mapping',
]);
@@ -115,7 +115,7 @@ function outputExpectingLines(array $lines): OutputStyle
expect($migrator->rollbackOne('2019_08_10_142230_update_test_index_mapping'))->toBe($migrator);
});
-it('rolls back a migrated single migration', function (): void {
+it('rolls back a migrated single migration', function () {
Index::shouldReceive('drop')->once();
$output = outputExpectingLines([
@@ -132,7 +132,7 @@ function outputExpectingLines(array $lines): OutputStyle
])->exists())->toBeFalse();
});
-it('does not roll back the last batch when some files are missing', function (): void {
+it('does not roll back the last batch when some files are missing', function () {
$output = outputExpectingLines([
'Migration is not found: 2019_03_10_101500_create_test_index',
]);
@@ -146,7 +146,7 @@ function outputExpectingLines(array $lines): OutputStyle
expect($migrator->rollbackLastBatch())->toBe($migrator);
});
-it('rolls back the last batch when all files are present', function (): void {
+it('rolls back the last batch when all files are present', function () {
Index::shouldReceive('putMapping')->once();
$output = outputExpectingLines([
@@ -167,7 +167,7 @@ function outputExpectingLines(array $lines): OutputStyle
])->exists())->toBeFalse();
});
-it('does not roll back all migrations when some files are missing', function (): void {
+it('does not roll back all migrations when some files are missing', function () {
$output = outputExpectingLines([
'Migration is not found: 2019_03_10_101500_create_test_index,2019_01_01_053550_drop_test_index',
]);
@@ -182,7 +182,7 @@ function outputExpectingLines(array $lines): OutputStyle
expect($migrator->rollbackAll())->toBe($migrator);
});
-it('rolls back all migrations when all files are present', function (): void {
+it('rolls back all migrations when all files are present', function () {
Index::shouldReceive('putMapping')->once();
Index::shouldReceive('drop')->once();
@@ -204,7 +204,7 @@ function outputExpectingLines(array $lines): OutputStyle
expect(DB::table($table)->where('migration', '2018_12_01_081000_create_test_index')->exists())->toBeFalse();
});
-it('displays status', function (): void {
+it('displays status', function () {
$output = Mockery::mock(OutputStyle::class);
$output->shouldReceive('table')->once()->with(
@@ -220,13 +220,13 @@ function outputExpectingLines(array $lines): OutputStyle
expect($migrator->showStatus())->toBe($migrator);
});
-it('prepares the repository and storage', function (): void {
+it('prepares the repository and storage', function () {
[, $migrator] = seededMigrator(Mockery::mock(OutputStyle::class));
expect($migrator->prepare())->toBe($migrator);
});
-it('creates the repository table when preparing', function (): void {
+it('creates the repository table when preparing', function () {
$output = Mockery::mock(OutputStyle::class);
[$table, $migrator] = seededMigrator($output);
@@ -236,7 +236,7 @@ function outputExpectingLines(array $lines): OutputStyle
expect(Schema::hasTable($table))->toBeTrue();
});
-it('creates the storage directory when preparing', function (): void {
+it('creates the storage directory when preparing', function () {
$directory = sys_get_temp_dir().'/opensearch_migrations_missing_directory';
config()->set('opensearch-migrations.storage_directory', $directory);
diff --git a/tests/Integration/RealOpenSearchMigrationCommandTest.php b/tests/Integration/RealOpenSearchMigrationCommandTest.php
index 87c163e..15b9922 100644
--- a/tests/Integration/RealOpenSearchMigrationCommandTest.php
+++ b/tests/Integration/RealOpenSearchMigrationCommandTest.php
@@ -11,7 +11,7 @@
uses(RealOpenSearchTestCase::class, RefreshDatabase::class);
-it('runs migration commands against opensearch', function (): void {
+it('runs migration commands against opensearch', function () {
$prefix = config('opensearch-migrations.index_name_prefix');
$client = app(Client::class);
$index = $prefix.'real_test';
@@ -40,7 +40,7 @@
expect($client->indices()->exists(['index' => $index]))->toBeFalse();
});
-it('runs index adapter operations against opensearch', function (): void {
+it('runs index adapter operations against opensearch', function () {
$indices = app(IndexManagerInterface::class);
$client = app(Client::class);
$prefix = config('opensearch-migrations.index_name_prefix');
@@ -49,7 +49,7 @@
$aliasName = $prefix.'adapter_real_alias';
try {
- $indices->create('adapter_real_test', function (Mapping $mapping, Settings $settings): void {
+ $indices->create('adapter_real_test', function (Mapping $mapping, Settings $settings) {
$mapping->text('title')->keyword('status');
$settings->index([
@@ -60,7 +60,7 @@
expect($client->indices()->exists(['index' => $index]))->toBeTrue();
- $indices->putMapping('adapter_real_test', function (Mapping $mapping): void {
+ $indices->putMapping('adapter_real_test', function (Mapping $mapping) {
$mapping->keyword('category');
});
diff --git a/tests/Integration/Repositories/MigrationRepositoryTest.php b/tests/Integration/Repositories/MigrationRepositoryTest.php
index 6481ea9..3cfad80 100644
--- a/tests/Integration/Repositories/MigrationRepositoryTest.php
+++ b/tests/Integration/Repositories/MigrationRepositoryTest.php
@@ -22,7 +22,7 @@ function seedMigrationRepositoryTable(): string
return $table;
}
-it('prepares the repository table when it is missing', function (): void {
+it('prepares the repository table when it is missing', function () {
$table = config('opensearch-migrations.table');
expect(Schema::hasTable($table))->toBeFalse();
@@ -32,7 +32,7 @@ function seedMigrationRepositoryTable(): string
expect(Schema::hasTable($table))->toBeTrue();
});
-it('inserts records', function (): void {
+it('inserts records', function () {
$table = seedMigrationRepositoryTable();
$repository = app(MigrationRepository::class);
@@ -44,7 +44,7 @@ function seedMigrationRepositoryTable(): string
])->exists())->toBeTrue();
});
-it('matches Laravel migration table structure', function (): void {
+it('matches Laravel migration table structure', function () {
$table = seedMigrationRepositoryTable();
$repository = app(MigrationRepository::class);
@@ -55,7 +55,7 @@ function seedMigrationRepositoryTable(): string
expect(DB::table($table)->max('id'))->toBe(3);
});
-it('uses the configured database connection for the repository table', function (): void {
+it('uses the configured database connection for the repository table', function () {
seedMigrationRepositoryTable();
config()->set('database.connections.opensearch_migrations', [
@@ -74,7 +74,7 @@ function seedMigrationRepositoryTable(): string
expect(Schema::connection('opensearch_migrations')->hasTable('custom_opensearch_migrations'))->toBeTrue();
});
-it('checks whether records exist', function (): void {
+it('checks whether records exist', function () {
seedMigrationRepositoryTable();
$repository = app(MigrationRepository::class);
@@ -83,7 +83,7 @@ function seedMigrationRepositoryTable(): string
expect($repository->exists('2019_12_05_092345_drop_test_index'))->toBeFalse();
});
-it('deletes records', function (): void {
+it('deletes records', function () {
$table = seedMigrationRepositoryTable();
$repository = app(MigrationRepository::class);
@@ -95,7 +95,7 @@ function seedMigrationRepositoryTable(): string
])->exists())->toBeFalse();
});
-it('gets all records', function (): void {
+it('gets all records', function () {
seedMigrationRepositoryTable();
expect(app(MigrationRepository::class)->getAll()->toArray())->toBe([
@@ -104,7 +104,7 @@ function seedMigrationRepositoryTable(): string
]);
});
-it('gets the last batch number', function (): void {
+it('gets the last batch number', function () {
$table = seedMigrationRepositoryTable();
$repository = app(MigrationRepository::class);
@@ -115,7 +115,7 @@ function seedMigrationRepositoryTable(): string
expect($repository->getLastBatchNumber())->toBeNull();
});
-it('gets the last batch records', function (): void {
+it('gets the last batch records', function () {
seedMigrationRepositoryTable();
expect(app(MigrationRepository::class)->getLastBatch()->toArray())->toBe([
@@ -123,7 +123,7 @@ function seedMigrationRepositoryTable(): string
]);
});
-it('prepares when the table exists', function (): void {
+it('prepares when the table exists', function () {
seedMigrationRepositoryTable();
app(MigrationRepository::class)->prepare();
@@ -131,7 +131,7 @@ function seedMigrationRepositoryTable(): string
expect(Schema::hasTable(config('opensearch-migrations.table')))->toBeTrue();
});
-it('prepares after creating a missing table', function (): void {
+it('prepares after creating a missing table', function () {
$table = seedMigrationRepositoryTable();
Schema::drop($table);
@@ -141,7 +141,7 @@ function seedMigrationRepositoryTable(): string
expect(Schema::hasTable($table))->toBeTrue();
});
-it('deletes all records', function (): void {
+it('deletes all records', function () {
seedMigrationRepositoryTable();
$repository = app(MigrationRepository::class);
diff --git a/tests/Integration/Support/MigrationPrefixTest.php b/tests/Integration/Support/MigrationPrefixTest.php
index d2b5d58..2d2aa92 100644
--- a/tests/Integration/Support/MigrationPrefixTest.php
+++ b/tests/Integration/Support/MigrationPrefixTest.php
@@ -2,13 +2,13 @@
use DirectoryTree\OpenSearchMigrations\Support\MigrationPrefix;
-it('prefixes index names', function (): void {
+it('prefixes index names', function () {
config()->set('opensearch-migrations.index_name_prefix', 'tenant_');
expect(MigrationPrefix::index('posts'))->toBe('tenant_posts');
});
-it('prefixes alias names', function (): void {
+it('prefixes alias names', function () {
config()->set('opensearch-migrations.alias_name_prefix', 'tenant_');
expect(MigrationPrefix::alias('posts_read'))->toBe('tenant_posts_read');
diff --git a/tests/Unit/Adapters/IndexManagerAdapterTest.php b/tests/Unit/Adapters/IndexManagerAdapterTest.php
index 9e1beef..916347d 100644
--- a/tests/Unit/Adapters/IndexManagerAdapterTest.php
+++ b/tests/Unit/Adapters/IndexManagerAdapterTest.php
@@ -7,7 +7,7 @@
use DirectoryTree\OpenSearchAdapter\Testing\Fakes\FakeIndexManager;
use DirectoryTree\OpenSearchMigrations\Adapters\IndexManagerAdapter;
-it('creates indexes without modifiers', function (string $prefix): void {
+it('creates indexes without modifiers', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
$indexManager = new FakeIndexManager;
@@ -18,13 +18,13 @@
$indexManager->assertCreated(new IndexBlueprint($prefix.'test'));
})->with('prefixes');
-it('creates indexes with modifiers', function (string $prefix): void {
+it('creates indexes with modifiers', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
$indexManager = new FakeIndexManager;
$adapter = new IndexManagerAdapter($indexManager);
- $adapter->create('test', function (Mapping $mapping, Settings $settings): void {
+ $adapter->create('test', function (Mapping $mapping, Settings $settings) {
$mapping->text('title');
$settings->index(['number_of_replicas' => 2]);
});
@@ -36,7 +36,7 @@
));
})->with('prefixes');
-it('creates indexes only when they do not exist', function (string $prefix): void {
+it('creates indexes only when they do not exist', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
$indexManager = new FakeIndexManager;
@@ -49,13 +49,13 @@
->assertCreated(new IndexBlueprint($prefix.'test'));
})->with('prefixes');
-it('updates mappings with modifiers', function (string $prefix): void {
+it('updates mappings with modifiers', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
$indexManager = new FakeIndexManager;
$adapter = new IndexManagerAdapter($indexManager);
- $adapter->putMapping('test', function (Mapping $mapping): void {
+ $adapter->putMapping('test', function (Mapping $mapping) {
$mapping->disableSource()->text('title');
});
@@ -65,13 +65,13 @@
);
})->with('prefixes');
-it('updates settings with modifiers', function (string $prefix): void {
+it('updates settings with modifiers', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
$indexManager = new FakeIndexManager;
$adapter = new IndexManagerAdapter($indexManager);
- $adapter->putSettings('test', function (Settings $settings): void {
+ $adapter->putSettings('test', function (Settings $settings) {
$settings->index(['number_of_replicas' => 2, 'refresh_interval' => -1]);
});
@@ -81,13 +81,13 @@
);
})->with('prefixes');
-it('pushes settings with modifiers', function (string $prefix): void {
+it('pushes settings with modifiers', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
$indexManager = new FakeIndexManager;
$adapter = new IndexManagerAdapter($indexManager);
- $adapter->pushSettings('test', function (Settings $settings): void {
+ $adapter->pushSettings('test', function (Settings $settings) {
$settings->index(['number_of_replicas' => 2]);
});
@@ -97,7 +97,7 @@
->assertOpened($prefix.'test');
})->with('prefixes');
-it('drops indexes', function (string $prefix): void {
+it('drops indexes', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
$indexManager = new FakeIndexManager;
@@ -108,7 +108,7 @@
$indexManager->assertDeleted($prefix.'test');
})->with('prefixes');
-it('drops indexes only when they exist', function (string $prefix): void {
+it('drops indexes only when they exist', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
$indexManager = new FakeIndexManager(existing: [$prefix.'test']);
@@ -121,7 +121,7 @@
->assertDeleted($prefix.'test');
})->with('prefixes');
-it('creates aliases', function (string $prefix): void {
+it('creates aliases', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
config()->set('opensearch-migrations.alias_name_prefix', $prefix);
@@ -133,7 +133,7 @@
$indexManager->assertAliasPut($prefix.'foo', new Alias($prefix.'bar'));
})->with('prefixes');
-it('deletes aliases', function (string $prefix): void {
+it('deletes aliases', function (string $prefix) {
config()->set('opensearch-migrations.index_name_prefix', $prefix);
config()->set('opensearch-migrations.alias_name_prefix', $prefix);
diff --git a/tests/Unit/Facades/IndexTest.php b/tests/Unit/Facades/IndexTest.php
index 5e2cb09..9946df4 100644
--- a/tests/Unit/Facades/IndexTest.php
+++ b/tests/Unit/Facades/IndexTest.php
@@ -1,20 +1,26 @@
toBeInstanceOf(IndexManagerInterface::class);
});
-it('fakes the index manager', function (): void {
+it('fakes the index manager', function () {
config()->set('opensearch-migrations.index_name_prefix', 'tenant_');
config()->set('opensearch-migrations.alias_name_prefix', 'tenant_');
$fake = Index::fake();
- Index::create('posts');
+ Index::create('posts', function (Mapping $mapping, Settings $settings) {
+ $mapping->text('title');
+ $settings->index(['number_of_replicas' => 0]);
+ });
Index::putAlias('posts', 'published_posts');
expect(Index::getFacadeRoot())->toBe($fake)
@@ -26,7 +32,97 @@
->assertAliasPut('posts', 'published_posts');
});
-it('fakes existing indices', function (): void {
+it('asserts created index definitions with a callback', function () {
+ config()->set('opensearch-migrations.index_name_prefix', 'tenant_');
+
+ $fake = Index::fake();
+
+ Index::create('posts', function (Mapping $mapping, Settings $settings) {
+ $mapping->text('title');
+ $settings->index(['number_of_replicas' => 0]);
+ });
+
+ $fake->assertCreated(
+ 'posts',
+ fn (?Mapping $mapping, ?Settings $settings) => (
+ $mapping?->toArray() === [
+ 'properties' => [
+ 'title' => ['type' => 'text'],
+ ],
+ ]
+ && $settings?->toArray() === [
+ 'index' => ['number_of_replicas' => 0],
+ ]
+ )
+ );
+});
+
+it('fails when a created index does not satisfy the callback', function () {
+ $fake = Index::fake();
+
+ Index::create('posts');
+
+ expect(fn () => $fake->assertCreated('posts', fn () => false))
+ ->toThrow(ExpectationFailedException::class);
+});
+
+it('asserts updated mappings with an optional callback', function () {
+ config()->set('opensearch-migrations.index_name_prefix', 'tenant_');
+
+ $fake = Index::fake();
+
+ Index::putMapping('posts', function (Mapping $mapping) {
+ $mapping->keyword('status');
+ });
+
+ $fake
+ ->assertMappingPut('posts')
+ ->assertMappingPut('posts', fn (Mapping $mapping) => $mapping->toArray() === [
+ 'properties' => [
+ 'status' => ['type' => 'keyword'],
+ ],
+ ]);
+});
+
+it('fails when an updated mapping does not satisfy the callback', function () {
+ $fake = Index::fake();
+
+ Index::putMapping('posts', function (Mapping $mapping) {
+ $mapping->keyword('status');
+ });
+
+ expect(fn () => $fake->assertMappingPut('posts', fn () => false))
+ ->toThrow(ExpectationFailedException::class);
+});
+
+it('asserts updated settings with an optional callback', function () {
+ config()->set('opensearch-migrations.index_name_prefix', 'tenant_');
+
+ $fake = Index::fake();
+
+ Index::putSettings('posts', function (Settings $settings) {
+ $settings->index(['refresh_interval' => -1]);
+ });
+
+ $fake
+ ->assertSettingsPut('posts')
+ ->assertSettingsPut('posts', fn (Settings $settings) => $settings->toArray() === [
+ 'index' => ['refresh_interval' => -1],
+ ]);
+});
+
+it('fails when updated settings do not satisfy the callback', function () {
+ $fake = Index::fake();
+
+ Index::putSettings('posts', function (Settings $settings) {
+ $settings->index(['refresh_interval' => -1]);
+ });
+
+ expect(fn () => $fake->assertSettingsPut('posts', fn () => false))
+ ->toThrow(ExpectationFailedException::class);
+});
+
+it('fakes existing indices', function () {
config()->set('opensearch-migrations.index_name_prefix', 'tenant_');
$fake = Index::fake(existing: ['posts']);
diff --git a/tests/Unit/Filesystem/MigrationFileTest.php b/tests/Unit/Filesystem/MigrationFileTest.php
index 58f352f..a68e696 100644
--- a/tests/Unit/Filesystem/MigrationFileTest.php
+++ b/tests/Unit/Filesystem/MigrationFileTest.php
@@ -4,10 +4,10 @@
const FULL_PATH = '/tmp/test.php';
-it('gets the full migration file path', function (): void {
+it('gets the full migration file path', function () {
expect((new MigrationFile(FULL_PATH))->path())->toBe(FULL_PATH);
});
-it('gets the migration file name without its extension', function (): void {
+it('gets the migration file name without its extension', function () {
expect((new MigrationFile(FULL_PATH))->name())->toBe(basename(FULL_PATH, '.php'));
});