/**
  * {@inheritdoc}
  */
 public function discover($service)
 {
     if (null === ($identity = $this->registry->get($service))) {
         throw new ServiceNotFoundException(sprintf('Service "%s" not found', $service));
     }
     return new Endpoint($identity, $this->driver);
 }
 public function testLookupWithInvalidResponseEntry()
 {
     $newIdentity = new Identity('foo', ['http://localhost']);
     $this->backend->expects(self::exactly(2))->method('get')->with('foo')->willReturnOnConsecutiveCalls(null, $newIdentity);
     $this->discovery->expects(self::once())->method('call')->with(new Discover())->willReturn(new Promise(function () {
         return new Response([['name' => 'foo', 'urls' => ['http://localhost']], ['invalid']]);
     }));
     $this->backend->expects(self::once())->method('register')->with($newIdentity);
     $identity = $this->registry->get('foo');
     self::assertSame($newIdentity, $identity);
 }
 /**
  * @param Identity $identity
  *
  * @return $this
  */
 public function register(Identity $identity)
 {
     $this->registry->register($identity);
     return $this;
 }
 /**
  * ArrayDiscovery should throw an exception for undefined service.
  */
 public function testDiscoveryException()
 {
     $this->registry->expects(self::once())->method('get')->with('bar')->willReturn(null);
     $this->expectException(ServiceNotFoundException::class);
     $this->discovery->discover('bar');
 }