/** * @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 testDuration() { $interactionA = $this->createMock(Profile\Interaction::class); $interactionA->expects($this->any())->method('getDuration')->willReturn(1.5); $interactionB = $this->createMock(Profile\Interaction::class); $interactionB->expects($this->any())->method('getDuration')->willReturn(0.5); $this->profile->add($interactionA)->add($interactionB); $duration = $this->profile->getDuration(); $this->assertEquals(2, $duration); }
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()); }
public function indexAction() { $this->profile->add(Profile\Interaction::broadcast(new Message\Request('qux', '1.0', []))->start()->stop(usleep(15000)))->add(Profile\Interaction::publish(new Location('foo'), new Message\Request('baz', '1.0', []))->start()->stop(usleep(10000)))->add(Profile\Interaction::call(new Location('bar'), new Message\Request('boom', '1.0', []))->start()->reply(new Message\Response('reply'))->stop(usleep(25000)))->add(Profile\Interaction::call(new Location('bar'), new Message\Request('bug', '1.0', []))->start()->fail(new \Exception('oops...'))->stop(usleep(25000))); return new Response('<html><body><h1>Test Web Profiler</h1><p>Check out this awesome toolbar below!</p></body></html>'); }