Skip to content

Commit

Permalink
Added missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
curzio-della-santa committed Dec 19, 2018
1 parent 7144502 commit 1aeacea
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/Factory/Client/ClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DetailTest\AlgoliaSearch\Factory\Client;

use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Factory\FactoryInterface;

use AlgoliaSearch\Client;
Expand All @@ -14,18 +15,25 @@ class ClientFactoryTest extends FactoryTestCase
{
public function testCreateService()
{
$client = $this->createClient();
$client = $this->createClient('test-id','test-key' );

$this->assertInstanceOf(Client::CLASS, $client);
}

protected function createClient(): Client
public function testCreateServiceThrowsExceptionForInvalidApplicationId()
{
$this->expectException(ServiceNotCreatedException::CLASS);
$this->expectExceptionMessage('AlgoliaSearch requires an applicationID');
$this->createClient(null, null);
}

protected function createClient(?string $applicationID, ?string $apiKey, ?array $hostsArray = null, ?array $options = []): Client
{
$moduleOptions = $this->prophesize(ModuleOptions::CLASS);
$moduleOptions->getApplicationId()->willReturn('test-id');
$moduleOptions->getApiKey()->willReturn('test-key');
$moduleOptions->getHosts()->willReturn(null);
$moduleOptions->getOptions()->willReturn([]);
$moduleOptions->getApplicationId()->willReturn($applicationID);
$moduleOptions->getApiKey()->willReturn($apiKey);
$moduleOptions->getHosts()->willReturn($hostsArray);
$moduleOptions->getOptions()->willReturn($options);

$services = $this->getServices();
$services->get(ModuleOptions::CLASS)->willReturn($moduleOptions->reveal());
Expand Down

0 comments on commit 1aeacea

Please sign in to comment.