This repository was archived by the owner on Jun 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 15
15
16
16
namespace Apisearch \Query ;
17
17
18
+ use Apisearch \Exception \InvalidFormatException ;
18
19
use Apisearch \Model \HttpTransportable ;
19
20
20
21
/**
@@ -283,6 +284,10 @@ public function toArray(): array
283
284
*/
284
285
public static function createFromArray (array $ array ): self
285
286
{
287
+ if (empty ($ array ['name ' ])) {
288
+ throw InvalidFormatException::queryFormatNotValid ($ array );
289
+ }
290
+
286
291
return self ::create (
287
292
$ array ['name ' ],
288
293
$ array ['field ' ] ?? 'uuid.type ' ,
Original file line number Diff line number Diff line change @@ -48,6 +48,28 @@ public function testCreate()
48
48
$ this ->assertEquals (10 , $ aggregation ->getLimit ());
49
49
}
50
50
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
+
51
73
/**
52
74
* Test creation with default values.
53
75
*/
You can’t perform that action at this time.
0 commit comments