File tree 3 files changed +25
-1
lines changed
3 files changed +25
-1
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
/**
@@ -278,6 +279,13 @@ public function toArray(): array
278
279
*/
279
280
public static function createFromArray (array $ array ): self
280
281
{
282
+ if (
283
+ isset ($ array ['values ' ]) &&
284
+ !is_array ($ array ['values ' ])
285
+ ) {
286
+ throw InvalidFormatException::queryFormatNotValid ($ array );
287
+ }
288
+
281
289
return self ::create (
282
290
$ array ['field ' ] ?? 'uuid.type ' ,
283
291
$ array ['values ' ] ?? [],
Original file line number Diff line number Diff line change 15
15
16
16
namespace Apisearch \Tests \Query ;
17
17
18
+ use Apisearch \Exception \InvalidFormatException ;
18
19
use Apisearch \Query \Filter ;
19
20
use PHPUnit \Framework \TestCase ;
20
21
@@ -119,4 +120,19 @@ public function testCreateFromArrayWithDefaults()
119
120
$ this ->assertEquals (Filter::TYPE_FIELD , $ aggregation ->getFilterType ());
120
121
$ this ->assertEquals ([], $ aggregation ->getFilterTerms ());
121
122
}
123
+
124
+ /**
125
+ * Test wrong values format.
126
+ */
127
+ public function testWrongValuesFormat ()
128
+ {
129
+ try {
130
+ Filter::createFromArray ([
131
+ 'values ' => 'string ' ,
132
+ ]);
133
+ $ this ->fail ('InvalidFormatException should be thrown ' );
134
+ } catch (InvalidFormatException $ exception ) {
135
+ // Silent pass
136
+ }
137
+ }
122
138
}
Original file line number Diff line number Diff line change @@ -196,7 +196,7 @@ public function testCreateFromArrayAllValues()
196
196
}
197
197
198
198
/**
199
- * Test multi result
199
+ * Test multi result.
200
200
*/
201
201
public function testMultiResult ()
202
202
{
You can’t perform that action at this time.
0 commit comments