Skip to content

Commit

Permalink
Fix use of converter declared in configuration + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elchristo committed May 3, 2017
1 parent 3c25f15 commit 84d7f27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Elchristo/Calendar/Converter/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ protected static function exists($name, array $convertibleEvents = [], $buildIfE
if (isset(self::$converters[$canonicalizeName])) {
return $canonicalizeName;
} else if (\is_subclass_of($name, ConverterInterface::class)) {
// passed classname
if ($buildIfExists === \true) {
self::build($name, $convertibleEvents);
}
return $canonicalizeName;
} else if (\array_key_exists($name, $convertibleEvents) && \is_array($convertibleEvents[$name])) {
// converter name declared in configuration
$classname = \current($convertibleEvents[$name]);
if ($buildIfExists === \true) {
self::build($classname, $convertibleEvents);
}
return self::canonicalizeName($classname);
} else {
// lookup in default namespace
$className = __NAMESPACE__ . '\\' . \ucfirst($name) . '\\' . \ucfirst($name);
Expand Down
1 change: 1 addition & 0 deletions tests/unit/ConvertibleEventFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function testCanConvertCalendarByGivenConverterName()
$config = $this->getConfigProvider();
$sourceBuilder = SourceBuilderFactory::create($config);
$calendar = new unit\Stub\TestCalendar($sourceBuilder, new Collection());
$calendar->setConfig($config);
$json = Converter::convert($calendar, 'json');
$this->assertJson($json);
}
Expand Down

0 comments on commit 84d7f27

Please sign in to comment.