Skip to content

Commit

Permalink
Fixed if we try to load AbstractProvider as provider
Browse files Browse the repository at this point in the history
  • Loading branch information
R2c authored and vagrant committed Apr 14, 2016
1 parent 5879133 commit 9678bc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Yasumi/Yasumi.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function create($class, $year = null, $locale = self::DEFAULT_LOCA
{
// Find and return holiday provider instance
$providerClass = sprintf('Yasumi\Provider\%s', str_replace('/', '\\', $class));
if (!class_exists($providerClass)) {
if (!class_exists($providerClass) || $class === 'AbstractProvider') {
throw new InvalidArgumentException(sprintf('Unable to find holiday provider "%s".', $class));
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Base/YasumiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ public function testCreateWithInvalidProvider()
Yasumi::create('Mars');
}

/**
* Tests that an InvalidArgumentException is thrown in case we try to load a Trait as provider.
*
* @expectedException InvalidArgumentException
*/
public function testCreateWithInvalidProviderBecauseItsATrait()
{
Yasumi::create('CommonHolidays');
}

/**
* Tests that an InvalidArgumentException is thrown in case we try to load the AbstractProvider as provider.
*
* @expectedException InvalidArgumentException
*/
public function testCreateWithAbstractClassProvider()
{
Yasumi::create('AbstractProvider');
}

/**
* Tests that an Yasumi\Exception\UnknownLocaleException is thrown in case an invalid locale is given.
*
Expand Down

0 comments on commit 9678bc4

Please sign in to comment.