Skip to content

Commit

Permalink
Updated: Checking if is a callable
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromdev committed Mar 5, 2017
1 parent 53edcef commit 8d9f3c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Service/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ protected function create(ContainerInterface $container, $config)
throw $this->getException('transport', Transport::class, ServiceNotCreatedException::class, $transport);
}
$endpoint = $container->get($config['endpoint']);

if (!is_callable($endpoint)) {
throw $this->getException('endpoint', 'callable', ServiceNotCreatedException::class, $endpoint);
}
return new Client($transport, $endpoint);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Service/ClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,22 @@ public function testThrowExceptionWhenTransportVariableIsNotAnInstanceOfElastics

$factory->createService($clientContainer);
}

/**
* @expectedException \Zend\ServiceManager\Exception\ServiceNotCreatedException
*/
public function testThrowExceptionWhenEndpointVariableIsNotACallable()
{
$config = $this->getConfig();
$transportContainer = $this->getContainerWithTransportDependencies($config);
$clientContainer = $this->createServiceLocatorMock(['get']);
$this->mockMappedReturn($clientContainer, 'get', [
'Config' => $config,
'elasticsearch.transport.default' => $this->getTransport($transportContainer, 'default'),
'elasticsearch.endpoint.default' => new stdClass(),
]);
$factory = new ClientFactory('default');

$factory->createService($clientContainer);
}
}

0 comments on commit 8d9f3c0

Please sign in to comment.