B
B
BonBon Slick2018-12-06 10:16:24
PHPUnit
BonBon Slick, 2018-12-06 10:16:24

Why is the test failing?

Should contain [{"email":"[email protected]"}] in [{"email":"[email protected]"},...{"email":"[email protected]",}...}]
Failed asserting that an array has the subset Array &0 (
    0 => Array &1 (
        'email' => '[email protected]'
    )
).
--- Expected
+++ Actual
@@ @@
     [0] => Array
         (
-            [email] => [email protected]
+            [email] => [email protected]

There is data in json if array would be like this
array:3 [
  "status" => "success"
  "data" => array:5 [
    0 => array:5 [
      "email" => "[email protected]"
    ]
    1 => array:5 [
      "email" => "[email protected]"
...

assert
static::assertArraySubset(
      [
        [
          'email' => '[email protected]',
        ],
      ],
      $content['data'],
      true,
      \sprintf(
        'Should contain %s in %s',
        \json_encode([['email' => '[email protected]',],]),
        \json_encode($content['data'])
      )
    );

The test only passes if [email protected] is first in the array.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Artyom, 2018-12-06
@dark1112

static::assertArraySubset(
      [
        1 => [
          'email' => '[email protected]',
        ],
      ],
      $content['data'],
      true,
      \sprintf(
        'Should contain %s in %s',
        \json_encode([['email' => '[email protected]',],]),
        \json_encode($content['data'])
      )
    );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question