@@ -205,6 +205,36 @@ public function theReturnedDataIsAnInstanceOf(string $className)
205205 $ this ->assertInstanceOf ($ className , $ this ->lastReturn );
206206 }
207207
208+ /**
209+ * @Then the returned data is an array
210+ */
211+ public function theReturnedDataIsAnArray ()
212+ {
213+ $ this ->assertIsArray ($ this ->lastReturn );
214+ }
215+
216+ /**
217+ * @Then the returned data contains :count items
218+ */
219+ public function theReturnedDataContainsItems (int $ count )
220+ {
221+ $ this ->assertCount ($ count , $ this ->lastReturn );
222+ }
223+
224+ /**
225+ * @Then the returned data contains the following data
226+ */
227+ public function theReturnedDataContainsTheFollowingData (TableNode $ table )
228+ {
229+ $ returnData = $ this ->lastReturn ;
230+
231+ if (! is_array ($ returnData )) {
232+ throw new RuntimeException ('The returned data is not an array. ' );
233+ }
234+
235+ $ this ->assertTableNodeIsSameAsArray ($ table , $ returnData );
236+ }
237+
208238 /**
209239 * @Then the returned data has only the following properties
210240 */
@@ -257,54 +287,7 @@ public function theReturnedDataPropertyContainsTheFollowingData($property, Table
257287 throw new RuntimeException ('The returned data on property " ' . $ property . '" is not an array. ' );
258288 }
259289
260- foreach ($ table as $ row ) {
261- $ this ->assertArrayHasKey ($ row ['property ' ], $ returnData );
262-
263- $ value = $ returnData [$ row ['property ' ]];
264-
265- if ($ value instanceof SimpleXMLElement) {
266- $ value = strval ($ value );
267- }
268-
269- $ expected = $ row ['value ' ];
270-
271- // Handle expected empty array
272- if ($ value === [] && $ expected === '[] ' ) {
273- $ expected = [];
274- }
275-
276- // Handle expected int values
277- if (is_int ($ value ) && ctype_digit ($ expected )) {
278- $ expected = intval ($ expected );
279- }
280-
281- // Handle expected float values
282- if (is_float ($ value ) && is_numeric ($ expected )) {
283- $ expected = floatval ($ expected );
284- }
285-
286- // Handle expected null value
287- if ($ value === null && $ expected === 'null ' ) {
288- $ expected = null ;
289- }
290-
291- // Handle expected true value
292- if ($ value === true && $ expected === 'true ' ) {
293- $ expected = true ;
294- }
295-
296- // Handle expected false value
297- if ($ value === false && $ expected === 'false ' ) {
298- $ expected = false ;
299- }
300-
301- // Handle placeholder %redmine_id%
302- if (is_string ($ expected )) {
303- $ expected = str_replace ('%redmine_id% ' , strval ($ this ->redmine ->getVersionId ()), $ expected );
304- }
305-
306- $ this ->assertSame ($ expected , $ value , 'Error with property " ' . $ row ['property ' ] . '" ' );
307- }
290+ $ this ->assertTableNodeIsSameAsArray ($ table , $ returnData );
308291 }
309292
310293 /**
@@ -384,4 +367,56 @@ private function getItemFromArray(array $array, $key): mixed
384367
385368 return $ array ;
386369 }
370+
371+ private function assertTableNodeIsSameAsArray (TableNode $ table , array $ data )
372+ {
373+ foreach ($ table as $ row ) {
374+ $ this ->assertArrayHasKey ($ row ['property ' ], $ data , 'Possible keys are: ' . implode (', ' , array_keys ($ data )));
375+
376+ $ value = $ data [$ row ['property ' ]];
377+
378+ if ($ value instanceof SimpleXMLElement) {
379+ $ value = strval ($ value );
380+ }
381+
382+ $ expected = $ row ['value ' ];
383+
384+ // Handle expected empty array
385+ if ($ value === [] && $ expected === '[] ' ) {
386+ $ expected = [];
387+ }
388+
389+ // Handle expected int values
390+ if (is_int ($ value ) && ctype_digit ($ expected )) {
391+ $ expected = intval ($ expected );
392+ }
393+
394+ // Handle expected float values
395+ if (is_float ($ value ) && is_numeric ($ expected )) {
396+ $ expected = floatval ($ expected );
397+ }
398+
399+ // Handle expected null value
400+ if ($ value === null && $ expected === 'null ' ) {
401+ $ expected = null ;
402+ }
403+
404+ // Handle expected true value
405+ if ($ value === true && $ expected === 'true ' ) {
406+ $ expected = true ;
407+ }
408+
409+ // Handle expected false value
410+ if ($ value === false && $ expected === 'false ' ) {
411+ $ expected = false ;
412+ }
413+
414+ // Handle placeholder %redmine_id%
415+ if (is_string ($ expected )) {
416+ $ expected = str_replace ('%redmine_id% ' , strval ($ this ->redmine ->getVersionId ()), $ expected );
417+ }
418+
419+ $ this ->assertSame ($ expected , $ value , 'Error with property " ' . $ row ['property ' ] . '" ' );
420+ }
421+ }
387422}
0 commit comments