/** * Compare two strings containing YAML to ensure that @a $actualYaml contains at * least what the YAML string @a $expectedYaml contains. * * @return whether or not @a $actualYaml contains @a $expectedJson * @retval true @a $actualYaml contains @a $expectedJson * @retval false @a $actualYaml does not contain @a $expectedJson * * @param[in] $actualYaml the YAML string to be tested * @param[in] $expectedYaml the expected YAML string */ function checkThatYamlStringContainsYamlString($actualYaml, $expectedYaml) { $actualValue = spyc_load($actualYaml); $expectedValue = spyc_load($expectedYaml); if (!$actualValue) { return false; } return compareContents($expectedValue, $actualValue); }
/** * Compare two strings containing JSON to ensure that @a $actualJson contains at * least what the JSON string @a $expectedJson contains. * * @return whether or not @a $actualJson contains @a $expectedJson * @retval true @a $actualJson contains @a $expectedJson * @retval false @a $actualJson does not contain @a $expectedJson * * @param[in] $actualJson the JSON string to be tested * @param[in] $expectedJson the expected JSON string * * Examples: * expected: {'a':1,'array':[1,3,5]} * * 1 ) * actual: {'a':1,'b':2,'c':3,'array':[1,2,3,4,5]} * return: true * * 2 ) * actual: {'b':2,'c':3,'array':[1,2,3,4,5]} * return: false * element 'a' is missing from the root object * * 3 ) * actual: {'a':0,'b':2,'c':3,'array':[1,2,3,4,5]} * return: false * the value of element 'a' is not 1 * * 4 ) * actual: {'a':1,'b':2,'c':3,'array':[1,2,4,5]} * return: false * the contents of 'array' does not include 3 */ function checkThatJsonStringContainsJsonString($actualJson, $expectedJson) { $actualValue = json_decode($actualJson); $expectedValue = json_decode($expectedJson); if (!$actualValue) { return false; } return compareContents($expectedValue, $actualValue); }