Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
26 changes: 4 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -73,5 +53,7 @@
"DirectoryTree\\OpenSearchMigrations\\OpenSearchMigrationsServiceProvider"
]
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
51 changes: 24 additions & 27 deletions src/Testing/Fakes/FakeIndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion tests/Integration/Console/FreshCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Console/MakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Console/MigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Console/RefreshCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Console/ResetCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Console/RollbackCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Console/StatusCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Factories/MigrationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions tests/Integration/Filesystem/MigrationStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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';
Expand All @@ -33,15 +33,15 @@
@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();

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);
Expand All @@ -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);
Expand All @@ -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'],
Expand All @@ -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([
Expand Down
Loading
Loading