Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seeResponseMatchesJsonType issue on multiple arrays of arrays #91

Open
MitakaMitaka opened this issue Aug 13, 2021 · 1 comment
Open

Comments

@MitakaMitaka
Copy link

MitakaMitaka commented Aug 13, 2021

What are you trying to achieve?

Trying to use seeResponseMatchesJsonType on a response from multiple arrays of arrays

What do you get instead?

After several iterations I get an error

1) testCest: Test Get the SUSPENDED Venues!
 Test  tests/api/testCest.php:suspendedVenues
 Step  See response matches json type {"businessHourID":"integer","workingDay":"string","specialHourDate":"string|null","fromTime":"string|null","toTime":"string|null","isClosed":"boolean"},"$..businessHours[22]"
 Fail  Key `businessHourID` doesn't exist in []

Provide test source code if related
The code I use is

// businessHours array from the venue payload
    public static $businessHoursArrayResponse = [
        'businessHourID'  => 'integer',
        'workingDay'      => 'string',
        'specialHourDate' => 'string|null',
        'fromTime'        => 'string|null',
        'toTime'          => 'string|null',
        'isClosed'        => 'boolean'
    ];
...
$businessHoursArray = $I->grabDataFromResponseByJsonPath('$..businessHours.*');
        for ($i=0; $i < count($businessHoursArray); $i++){
            if (!empty($businessHoursArray[$i])) {
                $I->seeResponseMatchesJsonType(self::$businessHoursArrayResponse, '$..businessHours['.$i.']');
            }
        }

var_dump($businessHoursArray) prints an array of 53 valid arrays no missing keys or anything.

Details

  • Codeception version: v4.1.20
  • PHP Version: 7.2.24
  • Operating System: Ubuntu
  • Installation type: Phar
  • List of installed packages (composer show)
  • Suite configuration:
actor: ApiTester
modules:
  enabled:
    - Asserts
    - Helper\Api
    - REST:
        depends: PhpBrowser
        url: '****'
        part: Json
        curl:
          CURLOPT_RETURNTRANSFER: true
@Naktibalda
Copy link
Member

I think that JsonSchema would be a more convenient approach for validating data in lists.
https://codeception.com/docs/modules/REST#seeResponseIsValidOnJsonSchema

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants