/**
  * @test
  * @covers ::result
  */
 public function it_should_error_when_an_invalid_response_is_returned_by_the_eventstore()
 {
     $this->setExpectedException(InvalidResponseException::class);
     $this->thenConnectionIsChecked();
     $invalidResponse = '';
     $projections = EventStore::forUrl('127.0.0.1', $this->httpClient);
     $this->httpClient->shouldReceive('send')->once()->with(m::on(function (Request $request) {
         return $request->getMethod() == 'GET' && (string) $request->getUri() === 'result-url';
     }))->andReturn(new Response(200, [], $invalidResponse));
     $projections->result(Definition::fromEventStore(['name' => '', 'mode' => '', 'status' => '', 'progress' => '', 'stateUrl' => '', 'resultUrl' => 'result-url', 'queryUrl' => '', 'enableCommandUrl' => '', 'disableCommandUrl' => '']));
 }
 /**
  * @test
  * @covers ::result
  */
 public function it_should_retrieve_a_partition_of_the_results_as_an_instance_of_a_value_object()
 {
     $definition = Definition::createNew(self::EXAMPLE_PROJECTION_NAME, '');
     $result = ['abc'];
     $expected = 'expected';
     $partition = 'streamName-Id';
     $this->givenDriverReturnsDefinition($definition);
     $this->thenDriverReturnsResult($definition, $result, $partition);
     $this->thenSerializerTransformsResultIntoAValueObject(self::EXAMPLE_CLASS_NAME, $result, $expected);
     $this->assertSame($expected, $this->repository->result($partition));
 }
 /**
  * @test
  * @covers ::withUpdatedQuery
  * @covers ::mode
  * @covers ::query
  * @covers ::name
  * @covers ::mayEmitNewEvents
  */
 public function it_should_update_the_query_and_return_a_new_object()
 {
     $name = 'Organisation';
     $query = 'MyNewQuery';
     $definition = Definition::createNew($name, 'MyQuery');
     $newDefinition = $definition->withUpdatedQuery($query);
     $this->assertNotSame($newDefinition, $definition);
     $this->assertSame($name, $newDefinition->name());
     $this->assertSame($query, $newDefinition->query());
     $this->assertSame(Definition::MODE_CONTINUOUS, $newDefinition->mode());
     $this->assertSame(false, $definition->mayEmitNewEvents());
 }
 /**
  * @param $definition
  *
  * @return mixed
  */
 public function query(Definition $definition)
 {
     $queryUrl = $definition->urls()['query'];
     $request = new Request('GET', $queryUrl);
     $this->sendRequest($request);
     $this->ensureStatusCodeIsGood($queryUrl);
     return $this->lastResponseAsJson()['query'];
 }