mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
ExportInterface::getLabels should return a closure
This commit is contained in:
parent
49b3a7154e
commit
e19868e595
@ -315,18 +315,13 @@ class CSVFormatter implements FormatterInterface
|
|||||||
foreach ($results as $row) {
|
foreach ($results as $row) {
|
||||||
$line = array();
|
$line = array();
|
||||||
foreach ($headers as $key) {
|
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
|
//append result
|
||||||
foreach ($resultsKeys as $key) {
|
foreach ($resultsKeys as $key) {
|
||||||
$line[] = $labels[$key][$row[$key]];
|
$line[] = call_user_func($labels[$key], $row[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$r[] = $line;
|
$r[] = $line;
|
||||||
|
@ -574,7 +574,15 @@ class ExportManagerTest extends KernelTestCase
|
|||||||
Argument::is(array(0, 1)),
|
Argument::is(array(0, 1)),
|
||||||
Argument::Type('array')
|
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->getQueryKeys(Argument::Type('array'))->willReturn(array('export'));
|
||||||
$export->getTitle()->willReturn('dummy title');
|
$export->getTitle()->willReturn('dummy title');
|
||||||
$exportManager->addExport($export->reveal(), 'dummy');
|
$exportManager->addExport($export->reveal(), 'dummy');
|
||||||
@ -602,9 +610,14 @@ class ExportManagerTest extends KernelTestCase
|
|||||||
Argument::is(array('cat a', 'cat b')),
|
Argument::is(array('cat a', 'cat b')),
|
||||||
Argument::is(array())
|
Argument::is(array())
|
||||||
)
|
)
|
||||||
->willReturn(array(
|
->willReturn(function($value) {
|
||||||
'cat a' => 'label cat a', 'cat b' => 'label cat b'
|
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()->willReturn(null);
|
||||||
//$aggregator->addRole()->shouldBeCalled();
|
//$aggregator->addRole()->shouldBeCalled();
|
||||||
$exportManager->addAggregator($aggregator->reveal(), 'aggregator_foo');
|
$exportManager->addAggregator($aggregator->reveal(), 'aggregator_foo');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user