-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from graze/error-codes
error code constants
- Loading branch information
Showing
9 changed files
with
1,067 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Graze\Gigya\Exceptions; | ||
|
||
use Exception; | ||
use Graze\Gigya\Response\ResponseInterface; | ||
use RuntimeException; | ||
|
||
/** | ||
* Class ResponseException | ||
* | ||
* Generic Response Exception | ||
* | ||
* @package Graze\Gigya\Exceptions | ||
*/ | ||
class ResponseException extends RuntimeException | ||
{ | ||
/** | ||
* @var ResponseInterface | ||
*/ | ||
protected $response; | ||
|
||
/** | ||
* @param ResponseInterface $response | ||
* @param string $message | ||
* @param Exception|null $previous | ||
*/ | ||
public function __construct(ResponseInterface $response, $message = '', Exception $previous = null) | ||
{ | ||
$this->response = $response; | ||
|
||
$message = (($message) ? $message . "\n" : '') . | ||
$response; | ||
|
||
parent::__construct($message, $response->getErrorCode(), $previous); | ||
} | ||
|
||
/** | ||
* @return ResponseInterface | ||
*/ | ||
public function getResponse() | ||
{ | ||
return $this->response; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Graze\Gigya\Test\Unit\Exception; | ||
|
||
use Graze\Gigya\Exceptions\ResponseException; | ||
use Graze\Gigya\Response\ResponseInterface; | ||
use Graze\Gigya\Test\TestCase; | ||
use Mockery as m; | ||
|
||
class ResponseExceptionTest extends TestCase | ||
{ | ||
public function testInstanceOfRuntimeException() | ||
{ | ||
$response = m::mock(ResponseInterface::class); | ||
$response->shouldReceive('getErrorCode') | ||
->andReturn(0); | ||
$exception = new ResponseException($response); | ||
|
||
static::assertInstanceOf('RuntimeException', $exception); | ||
} | ||
|
||
public function testExceptionIncludeResponseStringAndCode() | ||
{ | ||
$response = m::mock(ResponseInterface::class); | ||
$response->shouldReceive('getErrorCode') | ||
->andReturn(100001); | ||
$response->shouldReceive('__toString') | ||
->andReturn('some description from the response'); | ||
$exception = new ResponseException($response); | ||
|
||
static::setExpectedException( | ||
ResponseException::class, | ||
'some description from the response', | ||
100001 | ||
); | ||
|
||
throw $exception; | ||
} | ||
|
||
public function testGetResponse() | ||
{ | ||
$response = m::mock(ResponseInterface::class); | ||
$response->shouldReceive('getErrorCode') | ||
->andReturn(100001); | ||
$exception = new ResponseException($response); | ||
|
||
static::assertSame($response, $exception->getResponse()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Graze\Gigya\Test\Unit\Response; | ||
|
||
use Graze\Gigya\Response\ErrorCode; | ||
use Graze\Gigya\Test\TestCase; | ||
|
||
class ErrorCodeTest extends TestCase | ||
{ | ||
public function testGetName() | ||
{ | ||
static::assertEquals('Session migration error', ErrorCode::getName(ErrorCode::ERROR_SESSION_MIGRATION_ERROR)); | ||
static::assertEquals('Invalid Secret', ErrorCode::getName(ErrorCode::ERROR_INVALID_SECRET)); | ||
} | ||
|
||
public function testGetNameWithUnknownErrorCodeWillReturnNull() | ||
{ | ||
static::assertNull(ErrorCode::getName(3271863217367182)); | ||
} | ||
|
||
public function testGetDescription() | ||
{ | ||
static::assertEquals( | ||
'When accounts.login, accounts.socialLogin, accounts.finalizeRegistration, socialize.notifyLogin, or socialize.login is called and the policy (in the site Policies) requires 2-factor authentication, and the device is not already in the verified device list for the account. The first time the method is called, the device needs to be registered, and for the following calls, the device needs to be verified.', | ||
ErrorCode::getDescription(ErrorCode::ERROR_ACCOUNT_PENDING_TFA_VERIFICATION) | ||
); | ||
static::assertEquals( | ||
'If Protect Against Account Harvesting policy is enabled and neither Email Validation nor CAPTCHA Validation policies are enabled.', | ||
ErrorCode::getDescription(ErrorCode::ERROR_INVALID_POLICY_CONFIGURATION) | ||
); | ||
} | ||
|
||
public function testGetDescriptionWithUnknownErrorCodeWillReturnNull() | ||
{ | ||
static::assertNull(ErrorCode::getDescription(3271863217367182)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters