mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
assert correct exception msg thrown
This commit is contained in:
parent
b3c961bc9e
commit
a59a057133
1 changed files with 18 additions and 15 deletions
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue