Skip to content

Commit

Permalink
assert correct exception msg thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
robmcvey committed Mar 15, 2015
1 parent b3c961b commit a59a057
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/Cake/Test/Case/View/JsonViewTest.php
Expand Up @@ -38,16 +38,6 @@ public function setUp() {
Configure::write('debug', 0);
}

/**
* tearDown method
*
* @return void
**/
public function tearDown() {
parent::tearDown();
restore_error_handler();
}

/**
* Generates testRenderWithoutView data.
*
Expand Down Expand Up @@ -339,7 +329,6 @@ public function testRenderWithViewAndNamed() {
/**
* JsonViewTest::testRenderInvalidJSON()
*
* @expectedException CakeException
* @return void
*/
public function testRenderInvalidJSON() {
Expand All @@ -350,13 +339,27 @@ public function testRenderInvalidJSON() {
// 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;

}
}

/**
Expand Down

0 comments on commit a59a057

Please sign in to comment.