diff --git a/src/Console/Command/Indexer.php b/src/Console/Command/Indexer.php index 7641644..bafe1c6 100644 --- a/src/Console/Command/Indexer.php +++ b/src/Console/Command/Indexer.php @@ -89,6 +89,8 @@ private function getSelectableIndexer(?string $source): array $selectableIndexer = []; foreach ($this->indexers->getIndexers() as $indexer) { + $s = $indexer->getSource(); + $n = $indexer->getName(); if (!empty($source) && $indexer->getSource() !== $source) { continue; } diff --git a/test/Console/Command/IndexerTest.php b/test/Console/Command/IndexerTest.php index 7b85133..6323846 100644 --- a/test/Console/Command/IndexerTest.php +++ b/test/Console/Command/IndexerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; @@ -47,6 +48,7 @@ public function setUp(): void ); $this->resourceChannelFactory->method('create') ->willReturn($resourceChannel); + $indexerA = $this->createStub( \Atoolo\Search\Indexer::class ); @@ -56,6 +58,7 @@ public function setUp(): void ->willReturn('indexer_a'); $indexerA->method('getName') ->willReturn('Indexer A'); + $indexerB = $this->createStub( \Atoolo\Search\Indexer::class ); @@ -65,10 +68,23 @@ public function setUp(): void ->willReturn('indexer_b'); $indexerB->method('getName') ->willReturn('Indexer B'); + + $indexerC = $this->createStub( + \Atoolo\Search\Indexer::class + ); + $indexerC->method('enabled') + ->willReturn(true); + $indexerC->method('getSource') + ->willReturn('indexer_c'); + $indexerC->method('getName') + ->willReturn('Indexer C'); + $indexers = new IndexerCollection([ $indexerA, - $indexerB + $indexerB, + $indexerC ]); + $progressBar = $this->createStub(IndexerProgressBar::class); $command = new Indexer( @@ -83,8 +99,69 @@ public function setUp(): void $this->commandTester = new CommandTester($command); } - public function testExecuteAllEnabledIndexer(): void + public function testExecuteWithoutIndexer(): void { + $resourceChannel = new ResourceChannel( + '', + 'WWW', + '', + '', + false, + '', + '', + '', + '', + '', + 'test', + [] + ); + $resourceChannelFactory = $this->createStub( + ResourceChannelFactory::class + ); + $resourceChannelFactory->method('create') + ->willReturn($resourceChannel); + + $progressBar = $this->createStub(IndexerProgressBar::class); + $indexers = new IndexerCollection([]); + $command = new Indexer( + $resourceChannelFactory, + $progressBar, + $indexers, + ); + $application = new Application([$command]); + + $command = $application->find('search:indexer'); + $commandTester = new CommandTester($command); + $commandTester->execute([]); + + $this->assertEquals( + Command::FAILURE, + $commandTester->getStatusCode(), + 'command should failed' + ); + + // the output of the command in the console + $output = $commandTester->getDisplay(); + // phpcs:disable + $this->assertEquals( + <<commandTester->setInputs(['0']); + $this->commandTester->execute([]); $this->commandTester->assertCommandIsSuccessful(); @@ -98,8 +175,17 @@ public function testExecuteAllEnabledIndexer(): void ============ -Index with Indexer "Indexer A" ------------------------------- +Several indexers are available. +------------------------------- + +Please select the indexer you want to use [0] + [0] Indexer A (source: indexer_a) + [1] Indexer C (source: indexer_c) + > 0 + You have just selected: Indexer A (source: indexer_a) + +Index with Indexer "Indexer A" (source: indexer_a) +-------------------------------------------------- @@ -133,8 +219,8 @@ public function testExecuteIndexerA(): void ============ -Index with Indexer "Indexer A" ------------------------------- +Index with Indexer "Indexer A" (source: indexer_a) +-------------------------------------------------- diff --git a/test/Service/Search/ExternalResourceFactoryTest.php b/test/Service/Search/ExternalResourceFactoryTest.php index 8d2e218..1ee8ad7 100644 --- a/test/Service/Search/ExternalResourceFactoryTest.php +++ b/test/Service/Search/ExternalResourceFactoryTest.php @@ -92,7 +92,8 @@ private function createDocument(string $url, string $title = ''): Document ->method('getFields') ->willReturn([ 'url' => $url, - 'title' => $title + 'title' => $title, + 'description' => ['test'] ]); return $document; }