From d3c24be84b38cabef19892f4b2dbf6d838a4fc2c Mon Sep 17 00:00:00 2001 From: Rob McVey Date: Sat, 14 Mar 2015 13:12:09 +0000 Subject: [PATCH] add a custom error handler for tests of json_encode --- lib/Cake/Test/Case/View/JsonViewTest.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/JsonViewTest.php b/lib/Cake/Test/Case/View/JsonViewTest.php index 11a11f994..3a772b853 100644 --- a/lib/Cake/Test/Case/View/JsonViewTest.php +++ b/lib/Cake/Test/Case/View/JsonViewTest.php @@ -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. * @@ -310,7 +324,7 @@ class JsonViewTest extends CakeTestCase { /** * JsonViewTest::testRenderInvalidJSON() * - * @expectedException CakeException + * expectedException CakeException * @return void */ public function testRenderInvalidJSON() { @@ -320,6 +334,9 @@ class JsonViewTest extends CakeTestCase { // non utf-8 stuff $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('_serialize', 'data');