diff --git a/lib/common/Exception/RedirectResponseException.php b/lib/common/Exception/RedirectResponseException.php new file mode 100644 index 00000000..e48c0083 --- /dev/null +++ b/lib/common/Exception/RedirectResponseException.php @@ -0,0 +1,46 @@ + + * @package WBW\Bundle\CommonBundle\Exception + */ +class RedirectResponseException extends AbstractException { + + use StringOriginUrlTrait; + use StringRedirectUrlTrait; + + /** + * Constructor. + * + * @param string $redirectUrl The redirect. + * @param string|null $originUrl The route. + */ + public function __construct(string $redirectUrl, ?string $originUrl) { + + $format = 'You\'re not allowed to access to "%s"'; + $message = sprintf($format, $originUrl); + + parent::__construct($message, 403); + + $this->setOriginUrl($originUrl); + $this->setRedirectUrl($redirectUrl); + } +} diff --git a/lib/common/Tests/Exception/RedirectResponseExceptionTest.php b/lib/common/Tests/Exception/RedirectResponseExceptionTest.php new file mode 100644 index 00000000..0c1e8a4f --- /dev/null +++ b/lib/common/Tests/Exception/RedirectResponseExceptionTest.php @@ -0,0 +1,44 @@ + + * @package WBW\Bundle\CommonBundle\Tests\Exception + */ +class RedirectResponseExceptionTest extends AbstractTestCase { + + /** + * Test __construct() + * + * @return void + */ + public function test__construct(): void { + + $originUrl = "https://github.com/webeweb"; + $redirectUrl = "https://github.com"; + + $obj = new RedirectResponseException($redirectUrl, $originUrl); + + $this->assertEquals('You\'re not allowed to access to "https://github.com/webeweb"', $obj->getMessage()); + + $this->assertEquals($originUrl, $obj->getOriginUrl()); + $this->assertEquals($redirectUrl, $obj->getRedirectUrl()); + } +}