From 7f4f5a501dcce659cacea700573256a1d563a4ee Mon Sep 17 00:00:00 2001 From: Jildert Miedema Date: Mon, 1 Dec 2014 21:42:43 +0100 Subject: [PATCH] coverage of exception --- src/Exception/IDPException.php | 6 ++-- test/src/Exception/IDPExceptionTest.php | 44 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 test/src/Exception/IDPExceptionTest.php diff --git a/src/Exception/IDPException.php b/src/Exception/IDPException.php index ec548c5..36eae2a 100644 --- a/src/Exception/IDPException.php +++ b/src/Exception/IDPException.php @@ -27,16 +27,18 @@ class IDPException extends \Exception public function getType() { + $result = 'Exception'; + if (isset($this->result['error'])) { $message = $this->result['error']; if (is_string($message)) { // OAuth 2.0 Draft 10 style - return $message; + $result = $message; } } - return 'Exception'; + return $result; } /** diff --git a/test/src/Exception/IDPExceptionTest.php b/test/src/Exception/IDPExceptionTest.php new file mode 100644 index 0000000..3debc62 --- /dev/null +++ b/test/src/Exception/IDPExceptionTest.php @@ -0,0 +1,44 @@ + 'message')); + + $this->assertEquals('message', $exception->getType()); + } + + public function testGetTypeMessage() + { + $exception = new IDPException(array('message' => 'message')); + + $this->assertEquals('Exception', $exception->getType()); + } + + public function testGetTypeEmpty() + { + $exception = new IDPException([]); + + $this->assertEquals('Exception', $exception->getType()); + } + + public function testAsString() + { + $exception = new IDPException(array('error' => 'message')); + + $this->assertEquals('message: message', (string)$exception); + } + + public function testAsStringWithCode() + { + $exception = new IDPException(array('error' => 'message', 'code' => 404)); + + $this->assertEquals('message: 404: message', (string)$exception); + } +} \ No newline at end of file