/** @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(HttpProjection::class, HttpProjection::create('127.0.0.1', '2113', 'admin', 'changeit')); }
protected function assertThatProjectionExists($projectionId) { $this->assertNotNull($this->projection->readProjection($projectionId)); }