Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Dec 5, 2024
1 parent 87e3ce3 commit 1d520f0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 48 additions & 0 deletions tests/Unit/Subscription/Engine/SubscriptionCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Tests\Unit\Subscription\Engine;

use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionCollection;
use Patchlevel\EventSourcing\Subscription\Subscription;
use PHPUnit\Framework\TestCase;

use function iterator_to_array;

final class SubscriptionCollectionTest extends TestCase
{
public function testEmpty(): void
{
$collection = new SubscriptionCollection([]);

self::assertCount(0, $collection);
self::assertEquals([], iterator_to_array($collection));
self::assertEquals(0, $collection->lowestPosition());
}

public function testSomeSubscription(): void
{
$subscription1 = new Subscription('foo', position: 5);
$subscription2 = new Subscription('bar', position: 10);

$collection = new SubscriptionCollection([$subscription1, $subscription2]);

self::assertCount(2, $collection);
self::assertEquals([$subscription1, $subscription2], iterator_to_array($collection));
self::assertEquals(5, $collection->lowestPosition());
}

public function testRemove(): void
{
$subscription1 = new Subscription('foo', position: 5);
$subscription2 = new Subscription('bar', position: 10);

$collection = new SubscriptionCollection([$subscription1, $subscription2]);
$collection->remove($subscription1);

self::assertCount(1, $collection);
self::assertEquals([$subscription2], iterator_to_array($collection));
self::assertEquals(10, $collection->lowestPosition());
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Subscription/Engine/SubscriptionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function testFind(): void
$manager = new SubscriptionManager($store->reveal());
$result = $manager->find($criteria);

self::assertSame([$subscription], iterator_to_array($result));
self::assertSame([$subscription], $result);
}

public function testFindForUpdateWithoutLock(): void
Expand Down

0 comments on commit 1d520f0

Please sign in to comment.