Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 519d439

Browse files
authored
Merge pull request #49 from apisearch-io/fix/added-aggregation-checks
Exception when wrong aggregation name
2 parents c14965f + ca40158 commit 519d439

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Query/Aggregation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace Apisearch\Query;
1717

18+
use Apisearch\Exception\InvalidFormatException;
1819
use Apisearch\Model\HttpTransportable;
1920

2021
/**
@@ -283,6 +284,10 @@ public function toArray(): array
283284
*/
284285
public static function createFromArray(array $array): self
285286
{
287+
if (empty($array['name'])) {
288+
throw InvalidFormatException::queryFormatNotValid($array);
289+
}
290+
286291
return self::create(
287292
$array['name'],
288293
$array['field'] ?? 'uuid.type',

Tests/Query/AggregationTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ public function testCreate()
4848
$this->assertEquals(10, $aggregation->getLimit());
4949
}
5050

51+
/**
52+
* Test creation with bad name.
53+
*
54+
* @expectedException \Apisearch\Exception\InvalidFormatException
55+
*/
56+
public function testCreateBadName()
57+
{
58+
Aggregation::createFromArray([]);
59+
}
60+
61+
/**
62+
* Test creation with empty name.
63+
*
64+
* @expectedException \Apisearch\Exception\InvalidFormatException
65+
*/
66+
public function testCreateEmptyName()
67+
{
68+
Aggregation::createFromArray([
69+
'name' => '',
70+
]);
71+
}
72+
5173
/**
5274
* Test creation with default values.
5375
*/

0 commit comments

Comments
 (0)