-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
246 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Infrastructure/IndexManagement/Job/UpdateIndexAlias.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace JeroenG\Explorer\Infrastructure\IndexManagement\Job; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use JeroenG\Explorer\Application\IndexAdapterInterface; | ||
use JeroenG\Explorer\Domain\IndexManagement\IndexConfigurationInterface; | ||
use JeroenG\Explorer\Domain\IndexManagement\IndexConfigurationRepositoryInterface; | ||
|
||
final class UpdateIndexAlias implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
private function __construct(public string $index) | ||
{ | ||
} | ||
|
||
public static function createFor(IndexConfigurationInterface $indexConfiguration): self | ||
{ | ||
$modelClassName = $indexConfiguration->getModel(); | ||
$model = new $modelClassName(); | ||
|
||
return (new self($indexConfiguration->getName())) | ||
->onQueue($model->syncWithSearchUsingQueue()) | ||
->onConnection($model->syncWithSearchUsing()); | ||
} | ||
|
||
public function handle( | ||
IndexAdapterInterface $indexAdapter, | ||
IndexConfigurationRepositoryInterface $indexConfigurationRepository | ||
): void { | ||
$indexConfiguration = $indexConfigurationRepository->findForIndex($this->index); | ||
$indexAdapter->pointToAlias($indexConfiguration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JeroenG\Explorer\Tests\Support\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use JeroenG\Explorer\Application\Aliased; | ||
use JeroenG\Explorer\Application\Explored; | ||
use Laravel\Scout\Searchable; | ||
|
||
class SyncableModel extends Model | ||
{ | ||
public function syncWithSearchUsingQueue(): string | ||
{ | ||
return ':queue:'; | ||
} | ||
|
||
public function syncWithSearchUsing(): string | ||
{ | ||
return ':connection:'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JeroenG\Explorer\Tests\Unit\IndexManagement\Job; | ||
|
||
use JeroenG\Explorer\Application\IndexAdapterInterface; | ||
use JeroenG\Explorer\Domain\IndexManagement\DirectIndexConfiguration; | ||
use JeroenG\Explorer\Domain\IndexManagement\IndexConfigurationRepositoryInterface; | ||
use JeroenG\Explorer\Infrastructure\IndexManagement\Job\UpdateIndexAlias; | ||
use JeroenG\Explorer\Tests\Support\Models\SyncableModel; | ||
use Mockery; | ||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
use PHPUnit\Framework\Assert; | ||
|
||
final class UpdateIndexAliasTest extends MockeryTestCase | ||
{ | ||
public function testJobCreation(): void | ||
{ | ||
$config = DirectIndexConfiguration::create( | ||
name: ':index:', | ||
properties: [], | ||
settings: [], | ||
model: SyncableModel::class, | ||
); | ||
|
||
$subject = UpdateIndexAlias::createFor($config); | ||
|
||
Assert::assertSame(':queue:', $subject->queue); | ||
Assert::assertSame(':connection:', $subject->connection); | ||
Assert::assertSame(':index:', $subject->index); | ||
|
||
} | ||
|
||
public function testHandleCallsPointToIndex(): void | ||
{ | ||
$adapter = Mockery::mock(IndexAdapterInterface::class); | ||
$repository = Mockery::mock(IndexConfigurationRepositoryInterface::class); | ||
|
||
$config = DirectIndexConfiguration::create( | ||
name: ':index:', | ||
properties: [], | ||
settings: [], | ||
model: SyncableModel::class, | ||
); | ||
|
||
$repository | ||
->expects('findForIndex') | ||
->with(':index:') | ||
->andReturn($config); | ||
|
||
$adapter | ||
->expects('pointToAlias') | ||
->with($config); | ||
|
||
UpdateIndexAlias::createFor($config) | ||
->handle($adapter, $repository); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters