Skip to content

Commit

Permalink
Copy Redirect response exception (from core-library)
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Apr 27, 2024
1 parent 0d38556 commit 5c6b80d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/common/Exception/RedirectResponseException.php
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 lib/common/Tests/Exception/RedirectResponseExceptionTest.php
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());
}
}

0 comments on commit 5c6b80d

Please sign in to comment.