Skip to content

Commit

Permalink
add a custom error handler for tests of json_encode
Browse files Browse the repository at this point in the history
  • Loading branch information
robmcvey committed Mar 14, 2015
1 parent 5002bd4 commit d3c24be
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/Cake/Test/Case/View/JsonViewTest.php
Expand Up @@ -156,6 +156,20 @@ public static function renderWithoutViewProvider() {
);
}

/**
* 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.
*
Expand Down Expand Up @@ -310,7 +324,7 @@ public function testRenderWithViewAndNamed() {
/**
* JsonViewTest::testRenderInvalidJSON()
*
* @expectedException CakeException
* expectedException CakeException
* @return void
*/
public function testRenderInvalidJSON() {
Expand All @@ -320,6 +334,9 @@ public function testRenderInvalidJSON() {

// 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');
Expand Down

0 comments on commit d3c24be

Please sign in to comment.