-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy Redirect response exception (from core-library)
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the jquery-datatables-bundle package. | ||
* | ||
* (c) 2018 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Bundle\CommonBundle\Exception; | ||
|
||
use WBW\Library\Common\Traits\Strings\StringOriginUrlTrait; | ||
use WBW\Library\Common\Traits\Strings\StringRedirectUrlTrait; | ||
|
||
/** | ||
* Redirect response exception. | ||
* | ||
* @author webeweb <https://github.com/webeweb> | ||
* @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); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
lib/common/Tests/Exception/RedirectResponseExceptionTest.php
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the jquery-datatables-bundle package. | ||
* | ||
* (c) 2018 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Bundle\CommonBundle\Tests\Exception; | ||
|
||
use WBW\Bundle\CommonBundle\Exception\RedirectResponseException; | ||
use WBW\Bundle\CommonBundle\Tests\AbstractTestCase; | ||
|
||
/** | ||
* Redirect response exception test. | ||
* | ||
* @author webeweb <https://github.com/webeweb> | ||
* @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()); | ||
} | ||
} |