Improve test coverage.

This commit is contained in:
James Cole
2018-05-11 09:51:47 +02:00
parent 50874c9cf7
commit 5a560b42ef
13 changed files with 684 additions and 138 deletions

View File

@@ -67,7 +67,7 @@ class ConfigureMappingHandler implements ConfigurationInterface
$specifics = $config['specifics'] ?? [];
$names = array_keys($specifics);
foreach ($names as $name) {
if (!\in_array($name, $validSpecifics)) {
if (!\in_array($name, $validSpecifics, true)) {
continue;
}
$class = config(sprintf('csv.import_specifics.%s', $name));
@@ -109,6 +109,26 @@ class ConfigureMappingHandler implements ConfigurationInterface
return new MessageBag;
}
/**
* Create the "mapper" class that will eventually return the correct data for the user
* to map against. For example: a list of asset accounts. A list of budgets. A list of tags.
*
* @param string $column
*
* @return MapperInterface
* @throws FireflyException
*/
public function createMapper(string $column): MapperInterface
{
$mapperClass = config('csv.import_roles.' . $column . '.mapper');
$mapperName = sprintf('FireflyIII\\Import\Mapper\\%s', $mapperClass);
if (!class_exists($mapperName)) {
throw new FireflyException(sprintf('Class "%s" does not exist. Cannot map "%s"', $mapperName, $column)); // @codeCoverageIgnore
}
return app($mapperName);
}
/**
* For each column in the configuration of the job, will:
* - validate the role.
@@ -327,24 +347,4 @@ class ConfigureMappingHandler implements ConfigurationInterface
$this->attachments = app(AttachmentHelperInterface::class);
$this->columnConfig = [];
}
/**
* Create the "mapper" class that will eventually return the correct data for the user
* to map against. For example: a list of asset accounts. A list of budgets. A list of tags.
*
* @param string $column
*
* @return MapperInterface
* @throws FireflyException
*/
private function createMapper(string $column): MapperInterface
{
$mapperClass = config('csv.import_roles.' . $column . '.mapper');
$mapperName = sprintf('FireflyIII\\Import\Mapper\\%s', $mapperClass);
if (!class_exists($mapperName)) {
throw new FireflyException(sprintf('Class "%s" does not exist. Cannot map "%s"', $mapperName, $column)); // @codeCoverageIgnore
}
return app($mapperName);
}
}
}