|
| 1 | +<?php namespace Tests\EventSourcery\Laravel; |
| 2 | + |
| 3 | +use EventSourcery\EventSourcery\EventSourcing\StreamId; |
| 4 | +use EventSourcery\EventSourcery\PersonalData\CryptographicDetails; |
| 5 | +use EventSourcery\EventSourcery\PersonalData\EncryptionKey; |
| 6 | +use EventSourcery\EventSourcery\PersonalData\InitializationVector; |
| 7 | +use EventSourcery\EventSourcery\PersonalData\PersonalKey; |
| 8 | +use EventSourcery\Laravel\LaravelPersonalCryptographyStore; |
| 9 | +use EventSourcery\Laravel\RelationalEventStore; |
| 10 | +use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase; |
| 11 | +use Tests\EventSourcery\Laravel\Stubs\TestEmail; |
| 12 | +use Tests\EventSourcery\Laravel\Stubs\TestPersonalEvent; |
| 13 | +use Tests\EventSourcery\Laravel\Stubs\TestEvent; |
| 14 | + |
| 15 | +class RelationalEventStoreTest extends TestCase { |
| 16 | + |
| 17 | + use InteractsWithDatabase; |
| 18 | + |
| 19 | + /** @var RelationalEventStore */ |
| 20 | + private $dataStore; |
| 21 | + |
| 22 | + /** @var LaravelPersonalCryptographyStore */ |
| 23 | + private $cryptoStore; |
| 24 | + |
| 25 | + function setUp() { |
| 26 | + parent::setUp(); |
| 27 | + $this->dataStore = $this->app->make(RelationalEventStore::class); |
| 28 | + $this->cryptoStore = new LaravelPersonalCryptographyStore(); |
| 29 | + |
| 30 | + $person = PersonalKey::fromString("123"); |
| 31 | + |
| 32 | + $crypto = new CryptographicDetails( |
| 33 | + EncryptionKey::generate(), |
| 34 | + InitializationVector::generate() |
| 35 | + ); |
| 36 | + |
| 37 | + $this->cryptoStore->addPerson($person, $crypto); |
| 38 | + } |
| 39 | + |
| 40 | + public function testItCanStoreAnEventWithPersonalData() { |
| 41 | + $event = new TestPersonalEvent(new TestEmail(PersonalKey::fromString("123"), "test@abc.com")); |
| 42 | + $this->dataStore->storeEvent($event); |
| 43 | + $this->assertDatabaseHas('event_store', [ |
| 44 | + 'event_name' => "TestPersonalEvent", |
| 45 | + ]); |
| 46 | + } |
| 47 | + |
| 48 | + public function testItCanDeSerializeAnEventWithPersonalData() { |
| 49 | + $event = new TestPersonalEvent(new TestEmail(PersonalKey::fromString("123"), "test@abc.com")); |
| 50 | + $this->dataStore->storeEvent($event); |
| 51 | + $events = $this->dataStore->getStream(StreamId::fromString(0)); |
| 52 | + $this->assertTrue($event == $events->toDomainEvents()->first()); |
| 53 | + } |
| 54 | + |
| 55 | + public function testItCanStoreASimpleEvent() { |
| 56 | + $event = new TestEvent(1); |
| 57 | + $this->dataStore->storeEvent($event); |
| 58 | + $this->assertDatabaseHas('event_store', [ |
| 59 | + 'event_name' => "TestEvent", |
| 60 | + 'event_data' => json_encode([ |
| 61 | + 'eventName' => "TestEvent", |
| 62 | + 'fields' => [ |
| 63 | + 'number' => 1 |
| 64 | + ] |
| 65 | + ]) |
| 66 | + ]); |
| 67 | + } |
| 68 | +} |
0 commit comments