Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2 #10

Merged
merged 3 commits into from Sep 29, 2015
Merged

0.2 #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/RedCode/Currency/Rate/Provider/ProviderFactory.php
Expand Up @@ -2,9 +2,6 @@

namespace RedCode\Currency\Rate\Provider;

/**
* @author maZahaca
*/
class ProviderFactory
{
private $providers;
Expand All @@ -13,14 +10,14 @@ class ProviderFactory
* @param ICurrencyRateProvider[] $providers
* @throws \Exception
*/
public function __construct($providers)
public function __construct($providers = [])
{
if (is_array($providers)) {
foreach ($providers as $provider) {
if (!($provider instanceof ICurrencyRateProvider)) {
throw new \Exception('Provider must be instance of ICurrencyRateProvider');
}
$this->providers[$provider->getName()] = $provider;
$this->addProvider($provider);
}
}
}
Expand All @@ -36,6 +33,18 @@ public function get($name)
}
}

/**
* Add a provider to factory
* @param ICurrencyRateProvider $provider
* @return $this
*/
public function addProvider(ICurrencyRateProvider $provider)
{
$this->providers[$provider->getName()] = $provider;

return $this;
}

/**
* @return ICurrencyRateProvider[]
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/ProviderFactoryTest.php
Expand Up @@ -45,6 +45,15 @@ public function testProviderFactoryCreate()
$this->assertNull($factory->get('WrongProviderName'));
}

public function testProviderFactoryAddProvider()
{
$factory = new ProviderFactory();
$factory->addProvider($this->provider);
$provider = $factory->get($this->providerName);

$this->assertInstanceOf(self::PROVIDER_INTERFACE, $provider);
}

/**
* @expectedException \Exception
* @expectedExceptionMessage Provider must be instance of ICurrencyRateProvider
Expand Down