Skip to content

Commit 786c51e

Browse files
authored
Merge pull request #2 from DirectoryTree/agent/fix-index-fake-assertions
Fix fake index assertion callback semantics
2 parents f6afad2 + 753741a commit 786c51e

19 files changed

Lines changed: 196 additions & 122 deletions

.github/workflows/run-tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ jobs:
5050

5151
- name: Install dependencies
5252
run: |
53-
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))'
54-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --no-blocking
55-
composer update --prefer-dist --no-interaction --no-blocking
53+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
54+
composer update --prefer-dist --no-interaction
5655
5756
- name: Wait for OpenSearch
5857
run: |

composer.json

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"require": {
2929
"php": "^8.2",
30-
"directorytree/opensearch-adapter": "^1.0",
30+
"directorytree/opensearch-adapter": "^1.2.1",
3131
"directorytree/opensearch-client": "^1.0",
3232
"illuminate/console": "^11.0|^12.0|^13.0",
3333
"illuminate/database": "^11.0|^12.0|^13.0",
@@ -41,26 +41,6 @@
4141
"orchestra/testbench": "^9.0|^10.0|^11.0",
4242
"pestphp/pest": "^3.0"
4343
},
44-
"repositories": [
45-
{
46-
"type": "path",
47-
"url": "../OpenSearchAdapter",
48-
"options": {
49-
"versions": {
50-
"directorytree/opensearch-adapter": "1.0.1"
51-
}
52-
}
53-
},
54-
{
55-
"type": "path",
56-
"url": "../OpenSearchClient",
57-
"options": {
58-
"versions": {
59-
"directorytree/opensearch-client": "1.0.0"
60-
}
61-
}
62-
}
63-
],
6444
"config": {
6545
"allow-plugins": {
6646
"php-http/discovery": true,
@@ -73,5 +53,7 @@
7353
"DirectoryTree\\OpenSearchMigrations\\OpenSearchMigrationsServiceProvider"
7454
]
7555
}
76-
}
56+
},
57+
"minimum-stability": "dev",
58+
"prefer-stable": true
7759
}

src/Testing/Fakes/FakeIndexManager.php

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,18 @@ public function assertChecked(string $index): static
144144

145145
/**
146146
* Assert that the given index was created.
147+
*
148+
* @param (callable(?Mapping, ?Settings): bool)|null $callback
147149
*/
148-
public function assertCreated(string $index, ?callable $modifier = null): static
150+
public function assertCreated(string $index, ?callable $callback = null): static
149151
{
150-
$this->manager->assertCreated($this->blueprint($index, $modifier));
152+
$this->manager->assertCreated(
153+
MigrationPrefix::index($index),
154+
$callback ? fn (IndexBlueprint $index): bool => $callback(
155+
$index->mapping(),
156+
$index->settings(),
157+
) : null,
158+
);
151159

152160
return $this;
153161
}
@@ -164,24 +172,30 @@ public function assertNotCreated(string $index): static
164172

165173
/**
166174
* Assert that the given index mapping was updated.
175+
*
176+
* @param (callable(Mapping): bool)|null $callback
167177
*/
168-
public function assertMappingPut(string $index, callable $modifier): static
178+
public function assertMappingPut(string $index, ?callable $callback = null): static
169179
{
170-
$modifier($mapping = new Mapping);
171-
172-
$this->manager->assertMappingPut(MigrationPrefix::index($index), $mapping);
180+
$this->manager->assertMappingPut(
181+
MigrationPrefix::index($index),
182+
$callback,
183+
);
173184

174185
return $this;
175186
}
176187

177188
/**
178189
* Assert that the given index settings were updated.
190+
*
191+
* @param (callable(Settings): bool)|null $callback
179192
*/
180-
public function assertSettingsPut(string $index, callable $modifier): static
193+
public function assertSettingsPut(string $index, ?callable $callback = null): static
181194
{
182-
$modifier($settings = new Settings);
183-
184-
$this->manager->assertSettingsPut(MigrationPrefix::index($index), $settings);
195+
$this->manager->assertSettingsPut(
196+
MigrationPrefix::index($index),
197+
$callback,
198+
);
185199

186200
return $this;
187201
}
@@ -243,21 +257,4 @@ public function assertAliasDeleted(string $index, string $alias): static
243257

244258
return $this;
245259
}
246-
247-
/**
248-
* Create an index blueprint for an assertion.
249-
*/
250-
protected function blueprint(string $index, ?callable $modifier = null): IndexBlueprint
251-
{
252-
if (isset($modifier)) {
253-
$modifier(
254-
$mapping = new Mapping,
255-
$settings = new Settings,
256-
);
257-
258-
return new IndexBlueprint(MigrationPrefix::index($index), $mapping, $settings);
259-
}
260-
261-
return new IndexBlueprint(MigrationPrefix::index($index));
262-
}
263260
}

tests/Integration/Console/FreshCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\Console\Input\ArrayInput;
88
use Symfony\Component\Console\Output\NullOutput;
99

10-
it('drops indices and migrations', function (): void {
10+
it('drops indices and migrations', function () {
1111
$migrator = Mockery::mock(Migrator::class);
1212
$repository = Mockery::mock(MigrationRepository::class);
1313
$index = Mockery::mock(IndexManagerInterface::class);

tests/Integration/Console/MakeCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Console\Input\ArrayInput;
66
use Symfony\Component\Console\Output\BufferedOutput;
77

8-
it('creates migration files', function (): void {
8+
it('creates migration files', function () {
99
$migrations = Mockery::mock(MigrationStorage::class);
1010
app()->instance(MigrationStorage::class, $migrations);
1111

tests/Integration/Console/MigrateCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Console\Input\ArrayInput;
66
use Symfony\Component\Console\Output\NullOutput;
77

8-
it('runs one migration when a file name is provided', function (): void {
8+
it('runs one migration when a file name is provided', function () {
99
$migrator = Mockery::mock(Migrator::class);
1010
app()->instance(Migrator::class, $migrator);
1111

@@ -20,7 +20,7 @@
2020
expect($command->run(new ArrayInput(['--force' => true, 'fileName' => 'test_file_name']), new NullOutput))->toBe(0);
2121
});
2222

23-
it('runs all migrations when a file name is not provided', function (): void {
23+
it('runs all migrations when a file name is not provided', function () {
2424
$migrator = Mockery::mock(Migrator::class);
2525
app()->instance(Migrator::class, $migrator);
2626

tests/Integration/Console/RefreshCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Console\Input\ArrayInput;
66
use Symfony\Component\Console\Output\NullOutput;
77

8-
it('resets and reruns all migrations', function (): void {
8+
it('resets and reruns all migrations', function () {
99
$migrator = Mockery::mock(Migrator::class);
1010
app()->instance(Migrator::class, $migrator);
1111

tests/Integration/Console/ResetCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Console\Input\ArrayInput;
66
use Symfony\Component\Console\Output\NullOutput;
77

8-
it('rolls back all migrations', function (): void {
8+
it('rolls back all migrations', function () {
99
$migrator = Mockery::mock(Migrator::class);
1010
app()->instance(Migrator::class, $migrator);
1111

tests/Integration/Console/RollbackCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Console\Input\ArrayInput;
66
use Symfony\Component\Console\Output\NullOutput;
77

8-
it('rolls back one migration when a file name is provided', function (): void {
8+
it('rolls back one migration when a file name is provided', function () {
99
$migrator = Mockery::mock(Migrator::class);
1010
app()->instance(Migrator::class, $migrator);
1111

@@ -20,7 +20,7 @@
2020
expect($command->run(new ArrayInput(['--force' => true, 'fileName' => 'test_file_name']), new NullOutput))->toBe(0);
2121
});
2222

23-
it('rolls back the last batch when a file name is not provided', function (): void {
23+
it('rolls back the last batch when a file name is not provided', function () {
2424
$migrator = Mockery::mock(Migrator::class);
2525
app()->instance(Migrator::class, $migrator);
2626

tests/Integration/Console/StatusCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Console\Input\ArrayInput;
66
use Symfony\Component\Console\Output\NullOutput;
77

8-
it('shows migration status', function (): void {
8+
it('shows migration status', function () {
99
$migrator = Mockery::mock(Migrator::class);
1010
app()->instance(Migrator::class, $migrator);
1111

0 commit comments

Comments
 (0)