protected function assertThatStreamDoesNotExist($streamId) { $exception = null; try { $this->eventStore->readStream($streamId); } catch (\Exception $exception) { } $this->assertInstanceOf(StreamDoesNotExist::class, $exception); }
/** @test */ public function custom_events() { $streamId = Uuid::uuid4()->toString(); $eventStore = \HttpEventStore\Http\HttpEventStore::create('127.0.0.1', '2113'); $event1 = new \tests\HttpEventStore\fixtures\CustomEvent('productWasAddedToBasket', ['productId' => 'product1', 'name' => 'Teapot']); $event2 = new \tests\HttpEventStore\fixtures\CustomEvent('productWasRemovedFromBasket', ['productId' => 'product1']); $eventStore->writeStream($streamId, [$event1, $event2]); $this->assertCount(2, $eventStore->readStream($streamId)); }
/** @test */ public function usage() { $streamId = Uuid::uuid4()->toString(); $eventStore = \HttpEventStore\Http\HttpEventStore::create('127.0.0.1', '2113'); $event1 = new \HttpEventStore\WritableEvent('productWasAddedToBasket', ['productId' => 'product1', 'name' => 'Teapot']); $event2 = new \HttpEventStore\WritableEvent('productWasRemovedFromBasket', ['productId' => 'product1']); // Writing to a Stream $eventStore->writeStream($streamId, [$event1, $event2]); // Creating a projection $projection = \HttpEventStore\Http\HttpProjection::create('127.0.0.1', '2113', 'admin', 'changeit'); $countOfEventsQuery = <<<STR fromStream('{$streamId}'). when({ \$init : function(s,e) {return {count : 0}}, \$any : function(s,e) {return {count : s.count +1}} }) ; STR; $projectionId = 'projection-' . $streamId; $projection->createProjection($projectionId, $countOfEventsQuery); // Reading of a projection $countOfEvents = $projection->readProjection($projectionId); $this->assertEquals(['count' => 2], $countOfEvents); }
/** @test */ public function it_can_be_created_with_factory_method() { $this->assertInstanceOf(HttpEventStore::class, HttpEventStore::create('127.0.0.1', '2113')); }