- 21 test files covering controllers, services, entities, enums, messages - CI: add test job with Xdebug coverage (clover + text) - SonarQube: configure coverage report path and test sources Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\MessageHandler;
|
|
|
|
use App\Message\MeilisearchMessage;
|
|
use App\MessageHandler\MeilisearchMessageHandler;
|
|
use App\Service\MeilisearchService;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class MeilisearchMessageHandlerTest extends TestCase
|
|
{
|
|
private MeilisearchService $meilisearch;
|
|
private MeilisearchMessageHandler $handler;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->meilisearch = $this->createMock(MeilisearchService::class);
|
|
$this->handler = new MeilisearchMessageHandler($this->meilisearch);
|
|
}
|
|
|
|
public function testHandleCreateIndex(): void
|
|
{
|
|
$this->meilisearch->expects(self::once())
|
|
->method('createIndex')
|
|
->with('events', 'uid');
|
|
|
|
($this->handler)(new MeilisearchMessage('createIndex', 'events', ['primaryKey' => 'uid']));
|
|
}
|
|
|
|
public function testHandleDeleteIndex(): void
|
|
{
|
|
$this->meilisearch->expects(self::once())
|
|
->method('deleteIndex')
|
|
->with('events');
|
|
|
|
($this->handler)(new MeilisearchMessage('deleteIndex', 'events'));
|
|
}
|
|
|
|
public function testHandleAddDocuments(): void
|
|
{
|
|
$docs = [['id' => 1]];
|
|
$this->meilisearch->expects(self::once())
|
|
->method('addDocuments')
|
|
->with('events', $docs);
|
|
|
|
($this->handler)(new MeilisearchMessage('addDocuments', 'events', ['documents' => $docs]));
|
|
}
|
|
|
|
public function testHandleUpdateDocuments(): void
|
|
{
|
|
$docs = [['id' => 1, 'title' => 'Updated']];
|
|
$this->meilisearch->expects(self::once())
|
|
->method('updateDocuments')
|
|
->with('events', $docs);
|
|
|
|
($this->handler)(new MeilisearchMessage('updateDocuments', 'events', ['documents' => $docs]));
|
|
}
|
|
|
|
public function testHandleDeleteDocument(): void
|
|
{
|
|
$this->meilisearch->expects(self::once())
|
|
->method('deleteDocument')
|
|
->with('events', 42);
|
|
|
|
($this->handler)(new MeilisearchMessage('deleteDocument', 'events', ['documentId' => 42]));
|
|
}
|
|
|
|
public function testHandleDeleteDocuments(): void
|
|
{
|
|
$this->meilisearch->expects(self::once())
|
|
->method('deleteDocuments')
|
|
->with('events', [1, 2, 3]);
|
|
|
|
($this->handler)(new MeilisearchMessage('deleteDocuments', 'events', ['ids' => [1, 2, 3]]));
|
|
}
|
|
|
|
public function testHandleUpdateSettings(): void
|
|
{
|
|
$settings = ['searchableAttributes' => ['title']];
|
|
$this->meilisearch->expects(self::once())
|
|
->method('updateSettings')
|
|
->with('events', $settings);
|
|
|
|
($this->handler)(new MeilisearchMessage('updateSettings', 'events', ['settings' => $settings]));
|
|
}
|
|
|
|
public function testUnknownActionThrowsException(): void
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Unknown action: invalid');
|
|
|
|
($this->handler)(new MeilisearchMessage('invalid', 'events'));
|
|
}
|
|
}
|