Skip to content

Commit

Permalink
test: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed May 17, 2024
1 parent 8c414f8 commit e0f6cc5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/Console/Command/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
98 changes: 92 additions & 6 deletions test/Console/Command/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -47,6 +48,7 @@ public function setUp(): void
);
$this->resourceChannelFactory->method('create')
->willReturn($resourceChannel);

$indexerA = $this->createStub(
\Atoolo\Search\Indexer::class
);
Expand All @@ -56,6 +58,7 @@ public function setUp(): void
->willReturn('indexer_a');
$indexerA->method('getName')
->willReturn('Indexer A');

$indexerB = $this->createStub(
\Atoolo\Search\Indexer::class
);
Expand All @@ -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(
Expand All @@ -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(
<<<EOF
Channel: WWW
============
[ERROR] No indexer available
EOF,
$output
);
// phpcs:enable
}
public function testExecuteSelectIndexer(): void
{

$this->commandTester->setInputs(['0']);

$this->commandTester->execute([]);

$this->commandTester->assertCommandIsSuccessful();
Expand All @@ -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)
--------------------------------------------------
Expand Down Expand Up @@ -133,8 +219,8 @@ public function testExecuteIndexerA(): void
============
Index with Indexer "Indexer A"
------------------------------
Index with Indexer "Indexer A" (source: indexer_a)
--------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion test/Service/Search/ExternalResourceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e0f6cc5

Please sign in to comment.