Skip to content

Commit

Permalink
BUGFIX: Fix failinig tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paxuclus committed Jul 6, 2022
1 parent e8088e0 commit 2c0ff69
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
90 changes: 90 additions & 0 deletions Tests/Unit/Domain/Service/ArrayQueryResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);

namespace Netlogix\Migrations\Tests\Unit\Domain\Service;

use ArrayObject;
use Neos\Flow\Persistence\Doctrine\Query;
use Neos\Flow\Persistence\QueryInterface;
use Neos\Flow\Persistence\QueryResultInterface;

class ArrayQueryResult implements QueryResultInterface
{

private $result;
private $iterator;

public function __construct(array $result)
{
$this->result = $result;
$this->iterator = (new ArrayObject($result))->getIterator();
}

public function current()
{
return $this->iterator->current();
}

public function next()
{
$this->iterator->next();
}

public function key()
{
return $this->iterator->key();
}

public function valid()
{
return $this->iterator->valid();
}

public function rewind()
{
$this->iterator->rewind();
}

public function offsetExists($offset)
{
return $this->iterator->offsetExists($offset);
}

public function offsetGet($offset)
{
return $this->iterator->offsetGet($offset);
}

public function offsetSet($offset, $value)
{
$this->iterator->offsetSet($offset, $value);
}

public function offsetUnset($offset)
{
$this->iterator->offsetUnset($offset);
}

public function count()
{
return $this->iterator->count();
}

public function getQuery(): QueryInterface
{
return new Query('foo');
}

public function getFirst()
{
reset($this->result);

return current($this->result);
}

public function toArray(): array
{
return $this->result;
}

}
8 changes: 4 additions & 4 deletions Tests/Unit/Domain/Service/MigrationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function Can_Return_UnexecutedMigrations(): void
->willReturn($migrationMock);

$this->migrationStatusRepository->method('findAll')
->willReturn([]);
->willReturn(new ArrayQueryResult([]));

$this->assertCount(2, $this->migrationService->findUnexecutedMigrations());
}
Expand All @@ -110,7 +110,7 @@ public function Can_Filter_Executed_Migrations_In_Get_UnexecutedMigrations(): vo
->willReturn('20191001142901');

$this->migrationStatusRepository->method('findAll')
->willReturn([$migrationStatusMock]);
->willReturn(new ArrayQueryResult([$migrationStatusMock]));

$migrations = $this->migrationService->findUnexecutedMigrations();

Expand All @@ -137,7 +137,7 @@ public function Can_Return_A_Single_Migration(): void
->willReturn('20191001142901');

$this->migrationStatusRepository->method('findAll')
->willReturn([$migrationStatusMock]);
->willReturn(new ArrayQueryResult([$migrationStatusMock]));

$migration = $this->migrationService->getMigrationByVersion('20191001142901');

Expand Down Expand Up @@ -165,7 +165,7 @@ public function Will_Throw_Unknown_Migration_If_Migration_Not_Found(): void
->willReturn('20191001142901');

$this->migrationStatusRepository->method('findAll')
->willReturn([$migrationStatusMock]);
->willReturn(new ArrayQueryResult([$migrationStatusMock]));

$this->migrationService->getMigrationByVersion('1458');
}
Expand Down

0 comments on commit 2c0ff69

Please sign in to comment.