Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Mar 22, 2024
1 parent 9f986eb commit ac00376
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Service/Indexer/BackgroundIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getStatus(): IndexerStatus
private function getIndexer(): InternalResourceIndexer
{
$progressHandler = new BackgroundIndexerProgressState(
$this->index->name(''),
$this->index,
$this->statusStore,
$this->logger
);
Expand Down
6 changes: 5 additions & 1 deletion test/Console/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions test/Console/Command/DumpIndexDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,13 +25,33 @@ 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([
['sp_id' => '123']
]);

$dumperCommand = new DumpIndexDocument(
$resourceChannelFactory,
$dumper
);

Expand All @@ -52,6 +74,10 @@ public function testExecute(): void
$output = $this->commandTester->getDisplay();
$this->assertEquals(
<<<EOF
Channel: WWW
============
{
"sp_id": "123"
}
Expand Down
36 changes: 32 additions & 4 deletions test/Console/Command/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\Indexer;
use Atoolo\Search\Console\Command\Io\IndexerProgressBar;
Expand All @@ -17,19 +19,39 @@
#[CoversClass(Indexer::class)]
class IndexerTest extends TestCase
{
private ResourceChannelFactory $resourceChannelFactory;
private CommandTester $commandTester;

/**
* @throws Exception
*/
public function setUp(): void
{
$resourceChannel = new ResourceChannel(
'',
'WWW',
'',
'',
false,
'',
'',
'',
'test',
[]
);

$this->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,
);
Expand All @@ -51,8 +73,11 @@ public function testExecuteIndexAll(): void
$this->assertEquals(
<<<EOF
Channel: WWW
============
Index all resources
===================
-------------------
EOF,
Expand All @@ -74,8 +99,11 @@ public function testExecuteIndexPath(): void
$this->assertEquals(
<<<EOF
Channel: WWW
============
Index resource paths
====================
--------------------
* a.php
* b.php
Expand All @@ -95,7 +123,6 @@ public function testExecuteIndexWithErrors(): void
$indexer = $this->createStub(
InternalResourceIndexer::class
);

$progressBar = $this->createStub(
IndexerProgressBar::class
);
Expand All @@ -104,6 +131,7 @@ public function testExecuteIndexWithErrors(): void
->willReturn([new \Exception('errortest')]);

$command = new Indexer(
$this->resourceChannelFactory,
$progressBar,
$indexer,
);
Expand Down Expand Up @@ -136,7 +164,6 @@ public function testExecuteIndexWithErrorsAndStackTrace(): void
$indexer = $this->createStub(
InternalResourceIndexer::class
);

$progressBar = $this->createStub(
IndexerProgressBar::class
);
Expand All @@ -145,6 +172,7 @@ public function testExecuteIndexWithErrorsAndStackTrace(): void
->willReturn([new \Exception('errortest')]);

$command = new Indexer(
$this->resourceChannelFactory,
$progressBar,
$indexer,
);
Expand Down
26 changes: 25 additions & 1 deletion test/Console/Command/MoreLikeThisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -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]);

Expand All @@ -59,6 +79,10 @@ public function testExecute(): void
$output = $this->commandTester->getDisplay();
$this->assertEquals(
<<<EOF
Channel: WWW
============
1 Results:
/test2.php
Query-Time: 10ms
Expand Down
29 changes: 26 additions & 3 deletions test/Console/Command/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\Search;
use Atoolo\Search\Dto\Search\Result\Facet;
Expand All @@ -26,6 +28,24 @@ class SearchTest 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('/test.php');
Expand All @@ -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]);

Expand All @@ -67,13 +87,16 @@ public function testExecute(): void
$this->assertEquals(
<<<EOF
Channel: WWW
============
Results (1)
===========
-----------
/test.php
Facets
======
------
objectType
----------
Expand Down
26 changes: 25 additions & 1 deletion test/Console/Command/SuggestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\SolrSuggestBuilder;
use Atoolo\Search\Console\Command\Suggest;
Expand All @@ -25,6 +27,24 @@ class SuggestTest extends TestCase
*/
public function setUp(): void
{
$resourceChannel = new ResourceChannel(
'',
'WWW',
'',
'',
false,
'',
'',
'',
'test',
[]
);

$resourceChannelFactory = $this->createStub(
ResourceChannelFactory::class
);
$resourceChannelFactory->method('create')
->willReturn($resourceChannel);
$result = new SuggestResult(
[
new Suggestion('security', 10),
Expand All @@ -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]);

Expand All @@ -56,6 +76,10 @@ public function testExecute(): void
$output = $this->commandTester->getDisplay();
$this->assertEquals(
<<<EOF
Channel: WWW
============
security (10)
section (5)
Query-Time: 10ms
Expand Down
5 changes: 4 additions & 1 deletion test/Service/Indexer/BackgroundIndexerProgressStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Atoolo\Search\Dto\Indexer\IndexerStatus;
use Atoolo\Search\Service\Indexer\BackgroundIndexerProgressState;
use Atoolo\Search\Service\Indexer\IndexerStatusStore;
use Atoolo\Search\Service\IndexName;
use Exception;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -20,9 +21,11 @@ class BackgroundIndexerProgressStateTest extends TestCase

public function setUp(): void
{
$indexName = $this->createMock(IndexName::class);
$indexName->method('name')->willReturn('test');
$this->statusStore = $this->createMock(IndexerStatusStore::class);
$this->state = new BackgroundIndexerProgressState(
'test',
$indexName,
$this->statusStore
);
}
Expand Down

0 comments on commit ac00376

Please sign in to comment.