Skip to content

Commit

Permalink
Tweak EventListenerInvokerTest
Browse files Browse the repository at this point in the history
..and prepare for PhpUnit 9 compatibility
  • Loading branch information
bwaidelich committed Mar 23, 2020
1 parent d915fd7 commit c9c4279
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Tests/Unit/EventListener/EventListenerInvokerTest.php
Expand Up @@ -8,11 +8,13 @@
use Neos\EventSourcing\EventListener\AppliedEventsStorage\AppliedEventsStorageInterface;
use Neos\EventSourcing\EventListener\EventListenerInterface;
use Neos\EventSourcing\EventListener\EventListenerInvoker;
use Neos\EventSourcing\EventListener\Exception\EventCouldNotBeAppliedException;
use Neos\EventSourcing\EventListener\ProvidesAppliedEventsStorageInterface;
use Neos\EventSourcing\EventStore\EventStore;
use Neos\EventSourcing\EventStore\EventStream;
use Neos\EventSourcing\EventStore\StreamAwareEventListenerInterface;
use Neos\EventSourcing\EventStore\StreamName;
use Neos\EventSourcing\Tests\Unit\EventListener\Fixture\AppliedEventsStorageEventListener;
use Neos\Flow\Tests\UnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;

Expand Down Expand Up @@ -70,6 +72,7 @@ public function setUp(): void

/**
* @test
* @throws EventCouldNotBeAppliedException
*/
public function catchUpPassesRespectsReservedSequenceNumber(): void
{
Expand All @@ -81,14 +84,13 @@ public function catchUpPassesRespectsReservedSequenceNumber(): void

/**
* @test
* @throws EventCouldNotBeAppliedException
*/
public function catchUpPassesRespectsProvidesAppliedEventsStorageInterface(): void
{
/** @var EventListenerInterface|MockObject $mockEventListener */
$mockEventListener = $this->getMockBuilder([EventListenerInterface::class, ProvidesAppliedEventsStorageInterface::class])->getMock();
$mockEventListener->method('getAppliedEventsStorage')->willReturn($this->mockAppliedEventsStorage);
$eventListener = new AppliedEventsStorageEventListener($this->mockAppliedEventsStorage);

$this->eventListenerInvoker = new EventListenerInvoker($this->mockEventStore, $mockEventListener, $this->mockConnection);
$this->eventListenerInvoker = new EventListenerInvoker($this->mockEventStore, $eventListener, $this->mockConnection);

$this->mockAppliedEventsStorage->expects($this->atLeastOnce())->method('reserveHighestAppliedEventSequenceNumber')->willReturn(123);
$this->mockEventStore->expects($this->once())->method('load')->with(StreamName::all(), 124)->willReturn($this->mockEventStream);
Expand All @@ -97,6 +99,7 @@ public function catchUpPassesRespectsProvidesAppliedEventsStorageInterface(): vo

/**
* @test
* @throws EventCouldNotBeAppliedException
*/
public function catchUpPassesRespectsStreamAwareEventListenerInterface(): void
{
Expand All @@ -116,7 +119,7 @@ private function buildMockEventListener(StreamName $streamName = null): EventLis
}
$listenerCode .= ' {';
if ($streamName !== null) {
$listenerCode .= 'public static function listensToStream(): ' . StreamName::class . ' { return ' . StreamName::class . '::fromString(\'' . (string)$streamName . '\'); }';
$listenerCode .= 'public static function listensToStream(): ' . StreamName::class . ' { return ' . StreamName::class . '::fromString(\'' . $streamName . '\'); }';
}
$listenerCode .= '}';

Expand Down
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);

namespace Neos\EventSourcing\Tests\Unit\EventListener\Fixture;

use Neos\EventSourcing\EventListener\AppliedEventsStorage\AppliedEventsStorageInterface;
use Neos\EventSourcing\EventListener\EventListenerInterface;
use Neos\EventSourcing\EventListener\ProvidesAppliedEventsStorageInterface;

class AppliedEventsStorageEventListener implements EventListenerInterface, ProvidesAppliedEventsStorageInterface
{

/**
* @var AppliedEventsStorageInterface
*/
private $appliedEventsStorage;

public function __construct(AppliedEventsStorageInterface $appliedEventsStorage)
{
$this->appliedEventsStorage = $appliedEventsStorage;
}

public function getAppliedEventsStorage(): AppliedEventsStorageInterface
{
return $this->appliedEventsStorage;
}
}

0 comments on commit c9c4279

Please sign in to comment.