Skip to content

Commit b688b01

Browse files
committed
Throw exception if description field doesnt exist
1 parent 11282dc commit b688b01

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/Extension/Core/Stage/Aggregator/DescribeAggregator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public function __invoke(): Generator
2626
$samples[$hash][$field] = [];
2727
}
2828

29+
if (false === isset($data[$field])) {
30+
throw new InvalidArgumentException(sprintf(
31+
'Field "%s" does not exist in data with fields "%s"',
32+
$field, implode('", "', array_keys($data))
33+
));
34+
}
35+
2936
$samples[$hash][$field][] = $data[$field];
3037
}
3138

tests/Unit/Extension/Core/Stage/Aggregator/DescribeAggregatorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PhpBench\Pipeline\Tests\Unit\Extension\Core\Stage\Aggregator;
44

55
use PhpBench\Pipeline\Tests\Unit\Extension\Core\CoreTestCase;
6+
use InvalidArgumentException;
67

78
class DescribeAggregatorTest extends CoreTestCase
89
{
@@ -77,4 +78,22 @@ public function testItGroupsByMultipleColumns()
7778
$this->assertArrayHasKey('two, one', $result);
7879
$this->assertArrayHasKey('three, three', $result);
7980
}
81+
82+
public function testThrowsExceptionIfGroupByFieldDoesntExist()
83+
{
84+
$this->expectException(InvalidArgumentException::class);
85+
$this->expectExceptionMessage('Field "tie" does not exist in data with fields "one", "two", "time"');
86+
$this->pipeline()
87+
->stage(function () {
88+
yield;
89+
yield ['one' => 'one', 'two' => 'two', 'time' => 10];
90+
})
91+
->stage('aggregator/describe', [
92+
'group_by' => ['one' ],
93+
'describe' => ['tie'],
94+
])
95+
->run();
96+
97+
}
98+
8099
}

0 commit comments

Comments
 (0)