add a custom error handler for tests of json_encode

This commit is contained in:
Rob McVey 2015-03-14 13:12:09 +00:00
parent 5002bd4dbe
commit d3c24be84b

View file

@ -156,6 +156,20 @@ class JsonViewTest extends CakeTestCase {
); );
} }
/**
* Custom error handler for use while testing methods that use json_encode
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
* @return void
* @throws CakeException
**/
public function jsonEncodeErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
throw new CakeException($errstr, 0, $errno, $errfile, $errline);
}
/** /**
* Test render with a valid string in _serialize. * Test render with a valid string in _serialize.
* *
@ -310,7 +324,7 @@ class JsonViewTest extends CakeTestCase {
/** /**
* JsonViewTest::testRenderInvalidJSON() * JsonViewTest::testRenderInvalidJSON()
* *
* @expectedException CakeException * expectedException CakeException
* @return void * @return void
*/ */
public function testRenderInvalidJSON() { public function testRenderInvalidJSON() {
@ -321,6 +335,9 @@ class JsonViewTest extends CakeTestCase {
// non utf-8 stuff // non utf-8 stuff
$data = array('data' => array('foo' => 'bar' . chr('0x97'))); $data = array('data' => array('foo' => 'bar' . chr('0x97')));
// Use a custom error handler
$phpUnitErrorHandler = set_error_handler(array($this, 'jsonEncodeErrorHandler'));
$Controller->set($data); $Controller->set($data);
$Controller->set('_serialize', 'data'); $Controller->set('_serialize', 'data');
$View = new JsonView($Controller); $View = new JsonView($Controller);