Assert exception msg contains UTF-8

The different versions of PHP throw several various messages for UTF-8
sequences, so this just performs a basic regex check
This commit is contained in:
Rob McVey 2015-03-15 11:01:51 +00:00
parent a59a057133
commit d94e05cf76
2 changed files with 2 additions and 6 deletions

View file

@ -351,12 +351,8 @@ class JsonViewTest extends CakeTestCase {
restore_error_handler();
$this->fail('Failed asserting that exception of type "CakeException" is thrown.');
} catch (CakeException $e) {
$expected = array(
'Failed to parse JSON',
'Malformed UTF-8 characters, possibly incorrectly encoded'
);
$this->assertContains($e->getMessage(), $expected);
restore_error_handler();
$this->assertRegExp('/UTF-8/', $e->getMessage());
return;
}

View file

@ -152,7 +152,7 @@ class JsonView extends View {
}
if (function_exists('json_last_error') && json_last_error() !== JSON_ERROR_NONE) {
throw new CakeException(sprintf('JSON_ERROR: %s', json_last_error_msg()));
throw new CakeException(json_last_error_msg());
} elseif ($json === false) {
throw new CakeException('Failed to parse JSON');
}