/** * Returns the description of the failure * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. * * @param mixed $other Evaluated value or object. * * @return string */ protected function failureDescription($other) { if ($other === '') { return 'an empty string is valid JSON'; } json_decode($other); $error = PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError(json_last_error()); return sprintf('%s is valid JSON (%s)', $this->exporter->shortenedExport($other), $error); }
/** * @dataProvider determineJsonErrorDataprovider * @covers PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError */ public function testDetermineJsonError($expected, $error, $prefix) { $this->assertEquals($expected, PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError($error, $prefix)); }
/** * Asserts that two given JSON encoded objects or arrays are not equal. * * @param string $expectedJson * @param string $actualJson * @param string $message */ public static function assertJsonStringNotEqualsJsonString($expectedJson, $actualJson, $message = '') { $expected = json_decode($expectedJson); if ($jsonError = json_last_error()) { $message .= PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError($jsonError, PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::translateTypeToPrefix('expected')); } $actual = json_decode($actualJson); if ($jsonError = json_last_error()) { $message .= PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError($jsonError, PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::translateTypeToPrefix('actual')); } self::assertNotEquals($expected, $actual, $message); }
/** * Returns the description of the failure * * The beginning of failure messages is "Failed asserting that" in most * cases. This method should return the second part of that sentence. * * @param mixed $other Evaluated value or object. * @return string */ protected function failureDescription($other) { json_decode($other); $error = PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError(json_last_error()); return sprintf('%s is valid JSON (%s)', PHPUnit_Util_Type::shortenedExport($other), $error); }
/** * Finds the last occurd JSON error. * * @param string $messagePrefix * @return string The last JSON error prefixed with $messagePrefix. */ protected function getJsonError($messagePrefix = 'Json error!') { return PHPUnit_Framework_Constraint_JsonMatches_ErrorMessageProvider::determineJsonError(json_last_error(), $messagePrefix); }