Skip to content

Commit

Permalink
fix upcasting iterator
Browse files Browse the repository at this point in the history
resolves #389
  • Loading branch information
prolic committed Apr 17, 2020
1 parent 654e023 commit 8d2934b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Plugin/UpcastingPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Prooph\EventStore\Plugin;

use Iterator;
use Prooph\Common\Event\ActionEvent;
use Prooph\EventStore\ActionEventEmitterEventStore;
use Prooph\EventStore\StreamIterator\StreamIterator;
use Prooph\EventStore\Upcasting\Upcaster;
use Prooph\EventStore\Upcasting\UpcastingIterator;

Expand All @@ -38,7 +38,7 @@ public function attachToEventStore(ActionEventEmitterEventStore $eventStore): vo
$upcaster = function (ActionEvent $actionEvent): void {
$streamEvents = $actionEvent->getParam('streamEvents');

if (! $streamEvents instanceof Iterator) {
if (! $streamEvents instanceof StreamIterator) {
return;
}

Expand Down
17 changes: 11 additions & 6 deletions src/Upcasting/UpcastingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

/**
* This file is part of prooph/event-store.
* (c) 2014-2019 prooph software GmbH <contact@prooph.de>
* (c) 2015-2019 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
* (c) 2014-2020 prooph software GmbH <contact@prooph.de>
* (c) 2015-2020 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,18 +13,18 @@

namespace Prooph\EventStore\Upcasting;

use Iterator;
use Prooph\Common\Messaging\Message;
use Prooph\EventStore\StreamIterator\StreamIterator;

final class UpcastingIterator implements Iterator
final class UpcastingIterator implements StreamIterator
{
/**
* @var Upcaster
*/
private $upcaster;

/**
* @var Iterator
* @var StreamIterator
*/
private $innerIterator;

Expand All @@ -33,7 +33,7 @@ final class UpcastingIterator implements Iterator
*/
private $storedMessages = [];

public function __construct(Upcaster $upcaster, Iterator $iterator)
public function __construct(Upcaster $upcaster, StreamIterator $iterator)
{
$this->upcaster = $upcaster;
$this->innerIterator = $iterator;
Expand Down Expand Up @@ -114,4 +114,9 @@ public function rewind(): void
$this->innerIterator->rewind();
$this->position = 0;
}

public function count(): int
{
return $this->innerIterator->count();
}
}
2 changes: 1 addition & 1 deletion tests/Projection/InMemoryEventStoreProjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function it_persists_after_blocksize_processed_events_for_multiple_handle
*/
public function it_throws_exception_when_trying_to_run_two_projections_at_the_same_time(): void
{
$this->markTestSkipped('InMemoryProjectionManager cannot guard agains concurrent projections');
$this->markTestSkipped('InMemoryProjectionManager cannot guard against concurrent projections');
}

/**
Expand Down
16 changes: 11 additions & 5 deletions tests/Upcasting/UpcastingIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use PHPUnit\Framework\TestCase;
use Prooph\Common\Messaging\Message;
use Prooph\EventStore\StreamIterator\StreamIterator;
use Prooph\EventStore\Upcasting\SingleEventUpcaster;
use Prooph\EventStore\Upcasting\UpcastingIterator;

Expand Down Expand Up @@ -51,12 +52,12 @@ public function it_iterates(): void
$message4->metadata()->willReturn(['foo' => 'baz'])->shouldBeCalled();
$message4 = $message4->reveal();

$iterator = new \ArrayIterator([
$iterator = new class([
$message1,
$message2,
$message3,
$message4,
]);
]) extends \ArrayIterator implements StreamIterator {};

$upcastingIterator = new UpcastingIterator($this->createUpcaster(), $iterator);

Expand Down Expand Up @@ -93,7 +94,7 @@ public function it_iterates_on_iterator_with_removed_messages_only(): void
$message->metadata()->willReturn(['foo' => 'baz'])->shouldBeCalled();
$message = $message->reveal();

$iterator = new \ArrayIterator([$message]);
$iterator = new class([$message]) extends \ArrayIterator implements StreamIterator {};

$upcastingIterator = new UpcastingIterator($this->createUpcaster(), $iterator);

Expand All @@ -107,7 +108,7 @@ public function it_iterates_on_iterator_with_removed_messages_only(): void
*/
public function it_iterates_over_array_iterator(): void
{
$iterator = new \ArrayIterator();
$iterator = new class() extends \ArrayIterator implements StreamIterator {};;

$upcastingIterator = new UpcastingIterator($this->createUpcaster(), $iterator);

Expand All @@ -121,7 +122,12 @@ public function it_iterates_over_array_iterator(): void
*/
public function it_iterates_over_empty_iterator(): void
{
$iterator = new \EmptyIterator();
$iterator = new class() extends \EmptyIterator implements StreamIterator {
public function count(): int
{
return 0;
}
};

$upcastingIterator = new UpcastingIterator($this->createUpcaster(), $iterator);

Expand Down

0 comments on commit 8d2934b

Please sign in to comment.