coverage of exception

1.0
Jildert Miedema 2014-12-01 21:42:43 +01:00
parent 781be84aa4
commit 7f4f5a501d
2 changed files with 48 additions and 2 deletions

View File

@ -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;
}
/**

View File

@ -0,0 +1,44 @@
<?php
namespace League\OAuth2\Client\Test\Exception;
use League\OAuth2\Client\Exception\IDPException;
class IDPExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testGetTypeErrorMessage()
{
$exception = new IDPException(array('error' => '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);
}
}