assert correct exception msg thrown

This commit is contained in:
Rob McVey 2015-03-15 10:36:06 +00:00
parent b3c961bc9e
commit a59a057133

View file

@ -38,16 +38,6 @@ class JsonViewTest extends CakeTestCase {
Configure::write('debug', 0);
}
/**
* tearDown method
*
* @return void
**/
public function tearDown() {
parent::tearDown();
restore_error_handler();
}
/**
* Generates testRenderWithoutView data.
*
@ -339,7 +329,6 @@ class JsonViewTest extends CakeTestCase {
/**
* JsonViewTest::testRenderInvalidJSON()
*
* @expectedException CakeException
* @return void
*/
public function testRenderInvalidJSON() {
@ -350,13 +339,27 @@ class JsonViewTest extends CakeTestCase {
// non utf-8 stuff
$data = array('data' => array('foo' => 'bar' . chr('0x97')));
// Use a custom error handler
set_error_handler(array($this, 'jsonEncodeErrorHandler'));
$Controller->set($data);
$Controller->set('_serialize', 'data');
$View = new JsonView($Controller);
$output = $View->render();
// Use a custom error handler
set_error_handler(array($this, 'jsonEncodeErrorHandler'));
try {
$View->render();
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();
return;
}
}
/**