Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

exSnake's avatar

How to read test expected vs actual result

I have this result, but I did not understand how to read it. What did he expect and what did he get?

Unable to find JSON: 
  
  [[
      {
          "id": 0,
          "code_es": "ES1234A",
          "customer_id": 0,
          "denomination": "DEFAULT",
          "toponim": "TOPONIMTEST",
          "address": "STREETEST",
          "street_number": "2/B",
          "postal_code": "12345",
          "city": "TESTCITY",
          "province": "TT",
          "type": "MAGAZINE",
          "created_at": "2023-03-10T16:07:01.000000Z",
          "updated_at": "2023-03-10T16:07:01.000000Z",
          "location_closures": [
              {
                  "id": 0,
                  "location_id": 0,
                  "date": "2012-01-01T00:00:00.000000Z",
                  "created_at": "2023-03-10T16:07:01.000000Z",
                  "updated_at": "2023-03-10T16:07:01.000000Z"
              }
          ]
      },
      {
          "id": 1,
          "code_es": "ES5532A",
          "customer_id": 2,
          "denomination": "TESTDENOMINATION",
          "toponim": "BORG",
          "address": "STREET TEST 2",
          "street_number": "83",
          "postal_code": "67890",
          "city": "TESTCITY 2",
          "province": "CC",
          "type": "AGENCYTEST",
          "created_at": "2023-03-10T16:07:05.000000Z",
          "updated_at": "2023-03-10T16:07:05.000000Z",
          "location_closures": [
              {
                  "id": 1,
                  "location_id": 1,
                  "date": "2017-01-06T00:00:00.000000Z",
                  "created_at": "2023-03-10T16:07:06.000000Z",
                  "updated_at": "2023-03-10T16:07:06.000000Z"
              },
              {
                  "id": 2,
                  "location_id": 1,
                  "date": "2017-01-11T00:00:00.000000Z",
                  "created_at": "2023-03-10T16:07:06.000000Z",
                  "updated_at": "2023-03-10T16:07:06.000000Z"
              }
          ]
      }
  ]]
  
  within response JSON:
  
  [[
      {
          "id": 1,
          "code_es": "ES5532A",
          "customer_id": 2,
          "denomination": "TESTDENOMINATION",
          "toponim": "BORG",
          "address": "STREET TEST 2",
          "street_number": "83",
          "postal_code": "67890",
          "city": "TESTCITY 2",
          "province": "CC",
          "type": "AGENCYTEST",
          "created_at": "2023-03-10T16:07:05.000000Z",
          "updated_at": "2023-03-10T16:07:05.000000Z",
          "location_closures": [
              {
                  "id": 1,
                  "location_id": 1,
                  "date": "2017-01-06T00:00:00.000000Z",
                  "created_at": "2023-03-10T16:07:06.000000Z",
                  "updated_at": "2023-03-10T16:07:06.000000Z"
              },
              {
                  "id": 2,
                  "location_id": 1,
                  "date": "2017-01-11T00:00:00.000000Z",
                  "created_at": "2023-03-10T16:07:06.000000Z",
                  "updated_at": "2023-03-10T16:07:06.000000Z"
              }
          ]
      },
      {
          "id": 0,
          "code_es": "ES1234A",
          "customer_id": 0,
          "denomination": "DEFAULT",
          "toponim": "TOPONIMTEST",
          "address": "STREETEST",
          "street_number": "2/B",
          "postal_code": "12345",
          "city": "TESTCITY",
          "province": "TT",
          "type": "MAGAZINE",
          "created_at": "2023-03-10T16:07:01.000000Z",
          "updated_at": "2023-03-10T16:07:01.000000Z",
          "location_closures": [
              {
                  "id": 0,
                  "location_id": 0,
                  "date": "2012-01-01T00:00:00.000000Z",
                  "created_at": "2023-03-10T16:07:01.000000Z",
                  "updated_at": "2023-03-10T16:07:01.000000Z"
              }
          ]
      }
  ]].
  
  
  Failed asserting that an array has the subset Array &0 (
      0 => Array &1 (
          'id' => 0
          'code_es' => 'ES1234A'
          'customer_id' => 0
          'denomination' => 'DEFAULT'
          'toponim' => 'TOPONIMTEST'
          'address' => 'STREETEST'
          'street_number' => '2/B'
          'postal_code' => '12345'
          'city' => 'TESTCITY'
          'province' => 'TT'
          'type' => 'MAGAZINE'
          'created_at' => '2023-03-10T16:07:01.000000Z'
          'updated_at' => '2023-03-10T16:07:01.000000Z'
          'location_closures' => Array &2 (
              0 => Array &3 (
                  'id' => 0
                  'location_id' => 0
                  'date' => '2012-01-01T00:00:00.000000Z'
                  'created_at' => '2023-03-10T16:07:01.000000Z'
                  'updated_at' => '2023-03-10T16:07:01.000000Z'
              )
          )
      )
      1 => Array &4 (
          'id' => 1
          'code_es' => 'ES5532A'
          'customer_id' => 2
          'denomination' => 'TESTDENOMINATION'
          'toponim' => 'BORG'
          'address' => 'STREET TEST 2'
          'street_number' => '83'
          'postal_code' => '67890'
          'city' => 'TESTCITY 2'
          'province' => 'CC'
          'type' => 'AGENCYTEST'
          'created_at' => '2023-03-10T16:07:05.000000Z'
          'updated_at' => '2023-03-10T16:07:05.000000Z'
          'location_closures' => Array &5 (
              0 => Array &6 (
                  'id' => 1
                  'location_id' => 1
                  'date' => '2017-01-06T00:00:00.000000Z'
                  'created_at' => '2023-03-10T16:07:06.000000Z'
                  'updated_at' => '2023-03-10T16:07:06.000000Z'
              )
              1 => Array &7 (
                  'id' => 2
                  'location_id' => 1
                  'date' => '2017-01-11T00:00:00.000000Z'
                  'created_at' => '2023-03-10T16:07:06.000000Z'
                  'updated_at' => '2023-03-10T16:07:06.000000Z'
              )
          )
      )
  ).

  at tests/Feature/Http/Controllers/Api/LocationControllerTest.php:35
     31▕         $this->locationOneOfCustomerOne->load('locationClosures');
     32▕         $this
     33▕             ->actingAs($this->userAuthorizedToView)
     34▕             ->getJson(route('api.locations.index', ['withclosures' => '1']))
  ➜  35▕             ->assertJson($locations->toArray());
     36▕     }
     37▕ }
     38▕ 
  --- Expected
  +++ Actual
  @@ @@
   array (
     0 => 
     array (
  -    'id' => 0,
  -    'code_es' => 'ES1234A',
  -    'customer_id' => 0,
  -    'denomination' => 'DEFAULT',
  -    'toponim' => 'TOPONIMTEST',
  -    'address' => 'STREETEST',
  -    'street_number' => '2/B',
  -    'postal_code' => '12345',
  -    'city' => 'TESTCITY',
  -    'province' => 'TT',
  -    'type' => 'MAGAZINE',
  -    'created_at' => '2023-03-10T16:07:01.000000Z',
  -    'updated_at' => '2023-03-10T16:07:01.000000Z',
  -    'location_closures' => 
  -    array (
  -      0 => 
  -      array (
  -        'id' => 0,
  -        'location_id' => 0,
  -        'date' => '2012-01-01T00:00:00.000000Z',
  -        'created_at' => '2023-03-10T16:07:01.000000Z',
  -        'updated_at' => '2023-03-10T16:07:01.000000Z',
  -      ),
  -      1 => 
  -      array (
  -        'id' => 2,
  -        'location_id' => 1,
  -        'date' => '2017-01-11T00:00:00.000000Z',
  -        'created_at' => '2023-03-10T16:07:06.000000Z',
  -        'updated_at' => '2023-03-10T16:07:06.000000Z',
  -      ),
  -    ),
  -  ),
  -  1 => 
  -  array (
       'id' => 1,
       'code_es' => 'ES5532A',
       'customer_id' => 2,
  @@ @@
           'date' => '2017-01-11T00:00:00.000000Z',
           'created_at' => '2023-03-10T16:07:06.000000Z',
           'updated_at' => '2023-03-10T16:07:06.000000Z',
  +      ),
  +    ),
  +  ),
  +  1 => 
  +  array (
  +    'id' => 0,
  +    'code_es' => 'ES1234A',
  +    'customer_id' => 0,
  +    'denomination' => 'DEFAULT',
  +    'toponim' => 'TOPONIMTEST',
  +    'address' => 'STREETEST',
  +    'street_number' => '2/B',
  +    'postal_code' => '12345',
  +    'city' => 'TESTCITY',
  +    'province' => 'TT',
  +    'type' => 'MAGAZINE',
  +    'created_at' => '2023-03-10T16:07:01.000000Z',
  +    'updated_at' => '2023-03-10T16:07:01.000000Z',
  +    'location_closures' => 
  +    array (
  +      0 => 
  +      array (
  +        'id' => 0,
  +        'location_id' => 0,
  +        'date' => '2012-01-01T00:00:00.000000Z',
  +        'created_at' => '2023-03-10T16:07:01.000000Z',
  +        'updated_at' => '2023-03-10T16:07:01.000000Z',
         ),
       ),
     ),
   )

Unable to find JSON is the result correct? Expected and actual to me seem the same, how can I read this error?

This is the test method:

/** @test */
    public function apiLocationIndexWithClosureParameterReturnLocationsWithClosures()
    {
        $locations = Location::with('locationClosures')
            ->has('locationClosures', '>', 0)->get();
        $this->locationOneOfCustomerOne->load('locationClosures');
        $this
            ->actingAs($this->userAuthorizedToView)
            ->getJson(route('api.locations.index', ['withclosures' => '1']))
            ->assertJson($locations->toArray());
    }
0 likes
0 replies

Please or to participate in this conversation.