From ac00376c56f45a5d0a63ded2b4a25a0a5f337d8e Mon Sep 17 00:00:00 2001 From: Holger Veltrup Date: Fri, 22 Mar 2024 11:29:55 +0100 Subject: [PATCH] test: fix tests --- src/Service/Indexer/BackgroundIndexer.php | 2 +- test/Console/ApplicationTest.php | 6 +++- .../Console/Command/DumpIndexDocumentTest.php | 26 ++++++++++++++ test/Console/Command/IndexerTest.php | 36 ++++++++++++++++--- test/Console/Command/MoreLikeThisTest.php | 26 +++++++++++++- test/Console/Command/SearchTest.php | 29 +++++++++++++-- test/Console/Command/SuggestTest.php | 26 +++++++++++++- .../BackgroundIndexerProgressStateTest.php | 5 ++- 8 files changed, 144 insertions(+), 12 deletions(-) diff --git a/src/Service/Indexer/BackgroundIndexer.php b/src/Service/Indexer/BackgroundIndexer.php index 4c5b8c2..6a1337c 100644 --- a/src/Service/Indexer/BackgroundIndexer.php +++ b/src/Service/Indexer/BackgroundIndexer.php @@ -64,7 +64,7 @@ public function getStatus(): IndexerStatus private function getIndexer(): InternalResourceIndexer { $progressHandler = new BackgroundIndexerProgressState( - $this->index->name(''), + $this->index, $this->statusStore, $this->logger ); diff --git a/test/Console/ApplicationTest.php b/test/Console/ApplicationTest.php index 7ac7003..54d8558 100644 --- a/test/Console/ApplicationTest.php +++ b/test/Console/ApplicationTest.php @@ -4,6 +4,7 @@ namespace Atoolo\Search\Test\Console; +use Atoolo\Resource\ResourceChannelFactory; use Atoolo\Search\Console\Application; use Atoolo\Search\Console\Command\Indexer; use Atoolo\Search\Console\Command\InternalResourceIndexerBuilder; @@ -22,12 +23,15 @@ class ApplicationTest extends TestCase */ public function testConstruct(): void { + $resourceChannelFactory = $this->createStub( + ResourceChannelFactory::class + ); $indexer = $this->createStub( InternalResourceIndexer::class ); $progressBar = $this->createStub(IndexerProgressBar::class); $application = new Application([ - new Indexer($progressBar, $indexer) + new Indexer($resourceChannelFactory, $progressBar, $indexer) ]); $command = $application->get('atoolo:indexer'); $this->assertInstanceOf( diff --git a/test/Console/Command/DumpIndexDocumentTest.php b/test/Console/Command/DumpIndexDocumentTest.php index 55ef55c..ad381ab 100644 --- a/test/Console/Command/DumpIndexDocumentTest.php +++ b/test/Console/Command/DumpIndexDocumentTest.php @@ -4,6 +4,8 @@ namespace Atoolo\Search\Test\Console\Command; +use Atoolo\Resource\ResourceChannel; +use Atoolo\Resource\ResourceChannelFactory; use Atoolo\Search\Console\Application; use Atoolo\Search\Console\Command\DumpIndexDocument; use Atoolo\Search\Console\Command\IndexDocumentDumperBuilder; @@ -23,6 +25,25 @@ class DumpIndexDocumentTest extends TestCase */ public function setUp(): void { + $resourceChannel = new ResourceChannel( + '', + 'WWW', + '', + '', + false, + '', + '', + '', + 'test', + [] + ); + + $resourceChannelFactory = $this->createStub( + ResourceChannelFactory::class + ); + $resourceChannelFactory->method('create') + ->willReturn($resourceChannel); + $dumper = $this->createStub(IndexDocumentDumper::class); $dumper->method('dump') ->willReturn([ @@ -30,6 +51,7 @@ public function setUp(): void ]); $dumperCommand = new DumpIndexDocument( + $resourceChannelFactory, $dumper ); @@ -52,6 +74,10 @@ public function testExecute(): void $output = $this->commandTester->getDisplay(); $this->assertEquals( <<resourceChannelFactory = $this->createStub( + ResourceChannelFactory::class + ); + $this->resourceChannelFactory->method('create') + ->willReturn($resourceChannel); $indexer = $this->createStub( InternalResourceIndexer::class ); $progressBar = $this->createStub(IndexerProgressBar::class); $command = new Indexer( + $this->resourceChannelFactory, $progressBar, $indexer, ); @@ -51,8 +73,11 @@ public function testExecuteIndexAll(): void $this->assertEquals( <<assertEquals( <<createStub( InternalResourceIndexer::class ); - $progressBar = $this->createStub( IndexerProgressBar::class ); @@ -104,6 +131,7 @@ public function testExecuteIndexWithErrors(): void ->willReturn([new \Exception('errortest')]); $command = new Indexer( + $this->resourceChannelFactory, $progressBar, $indexer, ); @@ -136,7 +164,6 @@ public function testExecuteIndexWithErrorsAndStackTrace(): void $indexer = $this->createStub( InternalResourceIndexer::class ); - $progressBar = $this->createStub( IndexerProgressBar::class ); @@ -145,6 +172,7 @@ public function testExecuteIndexWithErrorsAndStackTrace(): void ->willReturn([new \Exception('errortest')]); $command = new Indexer( + $this->resourceChannelFactory, $progressBar, $indexer, ); diff --git a/test/Console/Command/MoreLikeThisTest.php b/test/Console/Command/MoreLikeThisTest.php index 05139b5..4c3faca 100644 --- a/test/Console/Command/MoreLikeThisTest.php +++ b/test/Console/Command/MoreLikeThisTest.php @@ -5,6 +5,8 @@ namespace Atoolo\Search\Test\Console\Command; use Atoolo\Resource\Resource; +use Atoolo\Resource\ResourceChannel; +use Atoolo\Resource\ResourceChannelFactory; use Atoolo\Search\Console\Application; use Atoolo\Search\Console\Command\MoreLikeThis; use Atoolo\Search\Dto\Search\Result\SearchResult; @@ -24,6 +26,24 @@ class MoreLikeThisTest extends TestCase */ public function setUp(): void { + $resourceChannel = new ResourceChannel( + '', + 'WWW', + '', + '', + false, + '', + '', + '', + 'test', + [] + ); + + $resourceChannelFactory = $this->createStub( + ResourceChannelFactory::class + ); + $resourceChannelFactory->method('create') + ->willReturn($resourceChannel); $resultResource = $this->createStub(Resource::class); $resultResource->method('getLocation') ->willReturn('/test2.php'); @@ -39,7 +59,7 @@ public function setUp(): void $solrMoreLikeThis->method('moreLikeThis') ->willReturn($result); - $command = new MoreLikeThis($solrMoreLikeThis); + $command = new MoreLikeThis($resourceChannelFactory, $solrMoreLikeThis); $application = new Application([$command]); @@ -59,6 +79,10 @@ public function testExecute(): void $output = $this->commandTester->getDisplay(); $this->assertEquals( <<createStub( + ResourceChannelFactory::class + ); + $resourceChannelFactory->method('create') + ->willReturn($resourceChannel); $resultResource = $this->createStub(Resource::class); $resultResource->method('getLocation') ->willReturn('/test.php'); @@ -47,7 +67,7 @@ public function setUp(): void $solrSelect->method('search') ->willReturn($result); - $command = new Search($solrSelect); + $command = new Search($resourceChannelFactory, $solrSelect); $application = new Application([$command]); @@ -67,13 +87,16 @@ public function testExecute(): void $this->assertEquals( <<createStub( + ResourceChannelFactory::class + ); + $resourceChannelFactory->method('create') + ->willReturn($resourceChannel); $result = new SuggestResult( [ new Suggestion('security', 10), @@ -36,7 +56,7 @@ public function setUp(): void $solrSuggest->method('suggest') ->willReturn($result); - $command = new Suggest($solrSuggest); + $command = new Suggest($resourceChannelFactory, $solrSuggest); $application = new Application([$command]); @@ -56,6 +76,10 @@ public function testExecute(): void $output = $this->commandTester->getDisplay(); $this->assertEquals( <<createMock(IndexName::class); + $indexName->method('name')->willReturn('test'); $this->statusStore = $this->createMock(IndexerStatusStore::class); $this->state = new BackgroundIndexerProgressState( - 'test', + $indexName, $this->statusStore ); }