Skip to content

Merge StreamStore into Store interface #761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 4.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/pages/UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ $subscriptionEngine = new DefaultSubscriptionEngine(

## Store

### StreamStore

`StreamStore` interface was merged with `Store` interface.

### DoctrineDbalStore

`DoctrineDbalStore` has been removed in favor of `StreamDoctrineDbalStore`.
Expand All @@ -73,7 +77,10 @@ And all the associated classes:
* `Patchlevel\EventSourcing\Store\Criteria\AggregateIdCriterion`
* `Patchlevel\EventSourcing\Store\DoctrineDbalStore`
* `Patchlevel\EventSourcing\Store\DoctrineDbalStoreStream`
* `Patchlevel\EventSourcing\Store\ReadOnlyStore`

### StreamReadOnlyStore

`StreamReadOnlyStore` has been removed in favor of `ReadOnlyStore`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be written as "merged in" like stream store and store I think.


## Message

Expand Down
4 changes: 2 additions & 2 deletions docs/pages/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ It passes all methods to the underlying store, but throws an `StoreIsReadOnly` e
operations.

```php
use Patchlevel\EventSourcing\Store\StreamReadOnlyStore;
use Patchlevel\EventSourcing\Store\ReadOnlyStore;
use Patchlevel\EventSourcing\Store\StreamStore;

/** @var StreamStore $store */
$readOnlyStore = new StreamReadOnlyStore($store);
$readOnlyStore = new ReadOnlyStore($store);
```
## Schema

Expand Down
3 changes: 1 addition & 2 deletions src/Repository/DefaultRepository.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

declare(strict_types=1);
Expand Down Expand Up @@ -25,7 +25,6 @@
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Store\Stream;
use Patchlevel\EventSourcing\Store\StreamStartHeader;
use Patchlevel\EventSourcing\Store\StreamStore;
use Patchlevel\EventSourcing\Store\UniqueConstraintViolation;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -253,7 +252,7 @@
);

try {
if ($archiveTo !== null && $this->store instanceof StreamStore) {
if ($archiveTo !== null) {
$this->store->transactional(
function () use ($messages, $streamName, $archiveTo): void {
$this->store->save(...$messages);
Expand Down
2 changes: 1 addition & 1 deletion src/Store/InMemoryStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

use const ARRAY_FILTER_USE_BOTH;

final class InMemoryStore implements StreamStore
final class InMemoryStore implements Store
{
/** @param array<positive-int|0, Message> $messages */
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Patchlevel\EventSourcing\Store\Criteria\Criteria;
use Psr\Log\LoggerInterface;

final class StreamReadOnlyStore implements StreamStore
final class ReadOnlyStore implements Store
{
public function __construct(
private readonly StreamStore $store,
private readonly Store $store,
private readonly LoggerInterface|null $logger = null,
) {
}
Expand Down
7 changes: 7 additions & 0 deletions src/Store/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ public function save(Message ...$messages): void;
* @template ClosureReturn
*/
public function transactional(Closure $function): void;

/** @return list<string> */
public function streams(): array;

public function remove(Criteria|null $criteria = null): void;

public function archive(Criteria|null $criteria = null): void;
}
2 changes: 1 addition & 1 deletion src/Store/StreamDoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
use function str_contains;
use function str_replace;

final class StreamDoctrineDbalStore implements StreamStore, SubscriptionStore, DoctrineSchemaConfigurator
final class StreamDoctrineDbalStore implements Store, SubscriptionStore, DoctrineSchemaConfigurator
{
/**
* PostgreSQL has a limit of 65535 parameters in a single query.
Expand Down
17 changes: 0 additions & 17 deletions src/Store/StreamStore.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Integration/Store/StreamDoctrineDbalStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Patchlevel\EventSourcing\Store\Header\RecordedOnHeader;
use Patchlevel\EventSourcing\Store\Header\StreamNameHeader;
use Patchlevel\EventSourcing\Store\StreamDoctrineDbalStore;
use Patchlevel\EventSourcing\Store\StreamStore;
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Store\UniqueConstraintViolation;
use Patchlevel\EventSourcing\Tests\DbalManager;
use Patchlevel\EventSourcing\Tests\Integration\Store\Events\ExternEvent;
Expand All @@ -36,7 +36,7 @@
final class StreamDoctrineDbalStoreTest extends TestCase
{
private Connection $connection;
private StreamStore $store;
private Store $store;

private ClockInterface $clock;

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Repository/DefaultRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public function testLoadAggregateWithoutSnapshot(): void

public function testSaveAggregateInOtherStream(): void
{
$store = $this->createMock(StreamStore::class);
$store = $this->createMock(Store::class);
$store
->expects($this->once())
->method('save')
Expand All @@ -717,7 +717,7 @@ public function testSaveAggregateInOtherStream(): void

public function testLoadAggregateFromOtherStream(): void
{
$store = $this->createMock(StreamStore::class);
$store = $this->createMock(Store::class);

$store
->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@

use Patchlevel\EventSourcing\Message\Message;
use Patchlevel\EventSourcing\Store\Criteria\Criteria;
use Patchlevel\EventSourcing\Store\ReadOnlyStore;
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Store\StoreIsReadOnly;
use Patchlevel\EventSourcing\Store\StreamReadOnlyStore;
use Patchlevel\EventSourcing\Store\StreamStore;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(StreamReadOnlyStore::class)]
final class StreamReadOnlyStoreTest extends TestCase
#[CoversClass(ReadOnlyStore::class)]
final class ReadOnlyStoreTest extends TestCase
{
public function testLoad(): void
{
$criteria = new Criteria();

$parentStore = $this->createMock(StreamStore::class);
$parentStore = $this->createMock(Store::class);
$parentStore->expects($this->atLeastOnce())->method('load')->with($criteria, 8, 42, true);

$store = new StreamReadOnlyStore($parentStore);
$store = new ReadOnlyStore($parentStore);
$store->load($criteria, 8, 42, true);
}

public function testCount(): void
{
$criteria = new Criteria();

$parentStore = $this->createMock(StreamStore::class);
$parentStore = $this->createMock(Store::class);
$parentStore->expects($this->atLeastOnce())->method('count')->with($criteria);

$store = new StreamReadOnlyStore($parentStore);
$store = new ReadOnlyStore($parentStore);
$store->count($criteria);
}

Expand All @@ -42,10 +42,10 @@ public function testSave(): void
$message = new Message(new class () {
});

$parentStore = $this->createMock(StreamStore::class);
$parentStore = $this->createMock(Store::class);
$parentStore->expects($this->never())->method('save')->with($message);

$store = new StreamReadOnlyStore($parentStore);
$store = new ReadOnlyStore($parentStore);
$this->expectException(StoreIsReadOnly::class);
$store->save($message);
}
Expand All @@ -55,19 +55,19 @@ public function testTransactional(): void
$callback = static function (): void {
};

$parentStore = $this->createMock(StreamStore::class);
$parentStore = $this->createMock(Store::class);
$parentStore->expects($this->atLeastOnce())->method('transactional')->with($callback);

$store = new StreamReadOnlyStore($parentStore);
$store = new ReadOnlyStore($parentStore);
$store->transactional($callback);
}

public function testStreams(): void
{
$parentStore = $this->createMock(StreamStore::class);
$parentStore = $this->createMock(Store::class);
$parentStore->expects($this->atLeastOnce())->method('streams')->willReturn(['foo', 'bar']);

$store = new StreamReadOnlyStore($parentStore);
$store = new ReadOnlyStore($parentStore);

self::assertEquals(['foo', 'bar'], $store->streams());
}
Expand All @@ -76,10 +76,10 @@ public function testRemove(): void
{
$criteria = new Criteria();

$parentStore = $this->createMock(StreamStore::class);
$parentStore = $this->createMock(Store::class);
$parentStore->expects($this->never())->method('remove')->with($criteria);

$store = new StreamReadOnlyStore($parentStore);
$store = new ReadOnlyStore($parentStore);
$this->expectException(StoreIsReadOnly::class);
$store->remove($criteria);
}
Expand All @@ -88,10 +88,10 @@ public function testArchive(): void
{
$criteria = new Criteria();

$parentStore = $this->createMock(StreamStore::class);
$parentStore = $this->createMock(Store::class);
$parentStore->expects($this->never())->method('archive')->with($criteria);

$store = new StreamReadOnlyStore($parentStore);
$store = new ReadOnlyStore($parentStore);
$this->expectException(StoreIsReadOnly::class);
$store->archive($criteria);
}
Expand Down
Loading