/** * @param LocationInterface $location * @param Request $request * * @return Response\Promise * * @throws \Exception */ public function call(LocationInterface $location, Request $request) { $interaction = Interaction::call($location, $request); $this->profile->add($interaction); $interaction->start(); try { $promise = $this->driver->call($location, $request); } catch (\Exception $exception) { $interaction->fail($exception); $interaction->stop(); throw $exception; } $interaction->stop(); return new Response\Promise(function ($timeout) use($promise, $interaction) { $interaction->start(); try { $response = $promise->resolve($timeout); } catch (\Exception $exception) { $interaction->stop(); $interaction->fail($exception); throw $exception; } $interaction->reply($response); $interaction->stop(); return $response; }); }
public function testCallException() { $this->innerDriver->expects($this->once())->method('call')->willThrowException(new \RuntimeException()); try { $this->driver->call(new Location('foo'), new Request('foo', '0')); } catch (\RuntimeException $e) { } $interactions = $this->profile->all(); $broadcast = reset($interactions); $this->assertEquals(Profile\Interaction::TYPE_CALL, $broadcast->getType()); $this->assertNotNull($broadcast->getLocation()); $this->assertTrue($broadcast->isFailure()); $this->assertNotNull($broadcast->getStartedAt()); $this->assertNotNull($broadcast->getFinishedAt()); $this->assertNotNull($broadcast->getRequest()); $this->assertNotNull($broadcast->getException()); }