diff --git a/Export/Formatter/CSVFormatter.php b/Export/Formatter/CSVFormatter.php index 589c0cad0..c0ea2df35 100644 --- a/Export/Formatter/CSVFormatter.php +++ b/Export/Formatter/CSVFormatter.php @@ -315,18 +315,13 @@ class CSVFormatter implements FormatterInterface foreach ($results as $row) { $line = array(); foreach ($headers as $key) { - if (!array_key_exists($row[$key], $labels[$key])) { - throw new \LogicException("The value '".$row[$key]."' " - . "is not available from the labels defined by aggregator or report. " - . "The key provided by aggregator or report is '$key'"); - } - $line[] = $labels[$key][$row[$key]]; + $line[] = call_user_func($labels[$key], $row[$key]); } //append result foreach ($resultsKeys as $key) { - $line[] = $labels[$key][$row[$key]]; + $line[] = call_user_func($labels[$key], $row[$key]); } $r[] = $line; diff --git a/Test/AbstractExportTestHelper.php b/Test/Export/AbstractExportTestHelper.php similarity index 100% rename from Test/AbstractExportTestHelper.php rename to Test/Export/AbstractExportTestHelper.php diff --git a/Tests/Export/ExportManagerTest.php b/Tests/Export/ExportManagerTest.php index be9e75d65..8faf49def 100644 --- a/Tests/Export/ExportManagerTest.php +++ b/Tests/Export/ExportManagerTest.php @@ -574,7 +574,15 @@ class ExportManagerTest extends KernelTestCase Argument::is(array(0, 1)), Argument::Type('array') ) - ->willReturn(array( 1 => 1, 0 => 0)); + ->willReturn(function($value) { + switch($value) { + case 0: + case 1: + return $value; + default: throw new \RuntimeException(sprintf("The value %s is not valid", $value)); + } + }); + $export->getQueryKeys(Argument::Type('array'))->willReturn(array('export')); $export->getTitle()->willReturn('dummy title'); $exportManager->addExport($export->reveal(), 'dummy'); @@ -602,9 +610,14 @@ class ExportManagerTest extends KernelTestCase Argument::is(array('cat a', 'cat b')), Argument::is(array()) ) - ->willReturn(array( - 'cat a' => 'label cat a', 'cat b' => 'label cat b' - )); + ->willReturn(function($value) { + switch ($value) { + case 'cat a' : return 'label cat a'; + case 'cat b' : return 'label cat b'; + default: + throw new \RuntimeException(sprintf("This value (%s) is not valid", $value)); + } + }); $aggregator->addRole()->willReturn(null); //$aggregator->addRole()->shouldBeCalled(); $exportManager->addAggregator($aggregator->reveal(), 'aggregator_foo');