public function assertJsonStructure(array $structure, $data = null)
    {
        if (is_null($data)) {
            try {
                $data = $this->json();
            } catch (InvalidJSONException $exception) {
                PHPUnit::fail('Unable to decode json response!');
            }
        }

        foreach ($structure as $key => $value) {
            if (is_array($value)) {
                PHPUnit::assertArrayHasKey($key, $data);

                // Prevent infinite loops
                if (is_null($data[$key])) {
                    continue;
                }

                $this->assertJsonStructure($structure[$key], $data[$key]);
                continue;
            }

            PHPUnit::assertArrayHasKey($value, $data);
        }

        return $this;
    }
public function assertJsonStructure(array $structure, $data = null)
    {
        if (is_null($data)) {
            try {
                $data = $this->json();
            } catch (InvalidJSONException $exception) {
                PHPUnit::fail('Unable to decode json response!');
            }
        }

        foreach ($structure as $key => $value) {
            if (is_array($value)) {
                PHPUnit::assertArrayHasKey($key, $data);

                // Prevent infinite loops
                if (is_null($data[$key])) {
                    continue;
                }

                $this->assertJsonStructure($structure[$key], $data[$key]);
                continue;
            }

            PHPUnit::assertArrayHasKey($value, $data);
        }

        return $this;
    }
public function assertJsonStructure ( array $ structure , $ data = null ) { if ( is_null ( $ data ) ) { try { $ data = $ this -> json ( ) ; } catch ( InvalidJSONException $ exception ) { PHPUnit :: fail ( 'Unable to decode json response!' ) ; } } foreach ( $ structure as $ key => $ value ) { if ( is_array ( $ value ) ) { PHPUnit :: assertArrayHasKey ( $ key , $ data ) ; // Prevent infinite loops if ( is_null ( $ data [ $ key ] ) ) { continue ; } $ this -> assertJsonStructure ( $ structure [ $ key ] , $ data [ $ key ] ) ; continue ; } PHPUnit :: assertArrayHasKey ( $ value , $ data ) ; } return $ this ; }
Assert that the response has the given structure.

@param array $structure Expected structure
@params array $data Response data
@return $this
Assert that the response has the given structure .