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 Apr 15, 2024
1 parent a7e6f3f commit 04b8639
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 2 deletions.
20 changes: 20 additions & 0 deletions test/Console/Command/Io/IndexerProgressBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public function setUp(): void
$this->progressBar->init($this->progressHandler);
}

public function testPrepare(): void
{
$this->progressHandler
->expects($this->once())
->method('prepare')
->with('test');
$this->progressBar->prepare('test');
}

public function testStart(): void
{
$this->progressHandler
Expand All @@ -45,6 +54,17 @@ public function testStart(): void
$this->progressBar->start(10);
}

public function testStartAfterPrepare(): void
{
$this->progressBar->prepare('test');

$this->progressHandler
->expects($this->once())
->method('start')
->with(10);
$this->progressBar->start(10);
}

/**
* @throws ExceptionInterface
*/
Expand Down
37 changes: 36 additions & 1 deletion test/Dto/Indexer/IndexerStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function setUp(): void
);
}

public function testGetStatus(): void
public function testGetStatusLine(): void
{
$this->assertEquals(
'[FINISHED] ' .
Expand All @@ -57,6 +57,41 @@ public function testGetStatus(): void
"unexpected status line"
);
}

public function testGetStatusLineForPreparing(): void
{

$startTime = new DateTime();
$startTime->setDate(2024, 1, 31);
$startTime->setTime(11, 15, 10);

$endTime = new DateTime();
$endTime->setDate(2024, 1, 31);
$endTime->setTime(12, 16, 11);

$status = new IndexerStatus(
IndexerStatusState::PREPARING,
$startTime,
$endTime,
10,
5,
4,
$startTime,
6,
2,
'prepare message'
);

$this->assertEquals(
'[PREPARING] ' .
'start: 31.01.2024 11:15, ' .
'time: 01h 01m 01s, ' .
'message: prepare message',
$status->getStatusLine(),
"unexpected status line"
);
}

public function testEmpty(): void
{
$status = IndexerStatus::empty();
Expand Down
7 changes: 7 additions & 0 deletions test/Service/Indexer/BackgroundIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public function testIndex(): void
$this->indexer->index();
}

public function testUpdate(): void
{
$this->internalResourceIndexer->expects($this->once())
->method('update');
$this->indexer->update(['/index.php']);
}

public function testIndexIfLocked(): void
{
$lockFactory = $this->createStub(LockFactory::class);
Expand Down
55 changes: 55 additions & 0 deletions test/Service/Indexer/IndexerProgressStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Atoolo\Search\Test\Service\Indexer;

use Atoolo\Search\Dto\Indexer\IndexerStatus;
use Atoolo\Search\Dto\Indexer\IndexerStatusState;
use Atoolo\Search\Service\Indexer\IndexerProgressState;
use Atoolo\Search\Service\Indexer\IndexerStatusStore;
use Atoolo\Search\Service\IndexName;
Expand All @@ -20,18 +21,39 @@ class IndexerProgressStateTest extends TestCase
private IndexerStatusStore&MockObject $statusStore;
private IndexerProgressState $state;

private ?IndexerStatus $status = null;

public function setUp(): void
{
$indexName = $this->createMock(IndexName::class);
$indexName->method('name')->willReturn('test');

$this->status = IndexerStatus::empty();

$this->statusStore = $this->createMock(IndexerStatusStore::class);
$that = $this;
$this->statusStore->method('load')
->willReturnCallback(function () use ($that) {
return $that->status;
});
$this->state = new IndexerProgressState(
$indexName,
$this->statusStore,
'source'
);
}

public function testPrepare(): void
{
$this->state->prepare('prepare message');

$this->assertMatchesRegularExpression(
'/\[PREPARING].*prepare message.*/',
$this->state->getStatus()->getStatusLine(),
"unexpected status line"
);
}

public function testStart(): void
{
$this->state->start(10);
Expand All @@ -43,6 +65,39 @@ public function testStart(): void
);
}

public function testStartAfterPrepare(): void
{

$startTime = new \DateTime();
$startTime->setDate(2024, 1, 31);
$startTime->setTime(11, 15, 10);

$endTime = new \DateTime();
$endTime->setDate(2024, 1, 31);
$endTime->setTime(12, 16, 11);

$this->status = new IndexerStatus(
IndexerStatusState::PREPARING,
$startTime,
$endTime,
0,
0,
0,
$endTime,
0,
0,
'prepare message'
);

$this->state->start(10);

$this->assertMatchesRegularExpression(
'/\[RUNNING].*start: 31\.01\.2024 11:15,.*processed: 0\/10,/',
$this->state->getStatus()->getStatusLine(),
"unexpected status line"
);
}

public function testUpdate(): void
{

Expand Down
3 changes: 2 additions & 1 deletion test/Service/Indexer/IndexerStatusStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function testStore(): void
'"skipped":4,' .
'"lastUpdate":"2024-01-31T13:17:12+00:00",' .
'"updated":6,' .
'"errors":2' .
'"errors":2,' .
'"prepareMessage":""' .
'}';

$this->assertEquals($expected, $json, 'unexpected json string');
Expand Down

0 comments on commit 04b8639

Please sign in to comment.