Commit ed561ab6 authored by Mike Ryan's avatar Mike Ryan

#70: Implemented KeyMapLookupTest.

parent 5147c0de
Pipeline #55455540 passed with stage
in 2 minutes and 29 seconds
......@@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `TaskPipeline` component for managing groups of tasks.
- `ComponentNotFound` and `DuplicateTask` exceptions added.
- Tests for `Extractor`, `KeyMap`, `Loader`, and `Task` components.
- Tests for `KeyMapLookup` component.
- Smoke test to make sure all provided examples keep working.
### Removed
......
......@@ -4,6 +4,8 @@ namespace Soong\Tests\Transformer;
use Soong\Contracts\Data\DataProperty;
use Soong\Contracts\KeyMap\KeyMap;
use Soong\Contracts\Task\EtlTask;
use Soong\Contracts\Task\TaskPipeline;
use Soong\Tests\Contracts\Transformer\TransFormerTestBase;
/**
......@@ -39,21 +41,39 @@ class KeyMapLookupTest extends TransFormerTestBase
'mapped to null' => [$configuration, 'baz', null],
'unmatched' => [$configuration, 'blah', null],
];
$returnMap = [];
foreach ($providedData as $description => $dataInstance) {
if ($description !== 'unmatched') {
$property = $this->createMock(DataProperty::class);
$property->method('getValue')->willReturn($dataInstance[1]);
$returnMap[] = [$property, $dataInstance[2]];
}
}
return $providedData;
}
/**
* Override TransformerTestBase::testTransformer, since we need more mocks.
*
* @dataProvider transformerDataProvider
*
* @param array $configuration
* Transformer configuration.
* @param mixed $source
* Source value to be transformed.
* @param mixed $expected
* Expected result of the transformation.
*/
public function testTransformer(array $configuration, $source, $expected)
{
// Mock the components used to retrieve the mapped key.
$keyMap = $this->createMock(KeyMap::class);
$keyMap->method('lookupLoadedKey')->will($this->returnValueMap($returnMap));
$keyMap->method('lookupLoadedKey')->willReturn([$expected]);
$task = $this->createMock(EtlTask::class);
$task->method('getKeyMap')->willReturn($keyMap);
$pipeline = $this->createMock(TaskPipeline::class);
$pipeline->method('getTask')->willReturn($task);
$configuration['pipeline'] = $pipeline;
// @todo Because this transformer depends on a static method with an
// explicit concrete class, we can't properly test it until
// https://gitlab.com/soongetl/soong/issues/70 is done.
return [];
// return $providedData;
/** @var \Soong\Transformer\KeyMapLookup $transformer */
$transformer = new $this->transformerClass($configuration);
$property = $this->createMock(DataProperty::class);
$property->method('getValue')->willReturn($source);
/** @var DataProperty $property */
$result = $transformer->transform($property);
$this->assertEquals($expected, $result->getValue(), "{$this->transformerClass} transformed");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment