Added / route with redirects
parent
e948091066
commit
2e51fbff9d
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Http\Exceptions;
|
||||
|
||||
class HttpPermanentRedirect extends HttpRedirect
|
||||
{
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct(
|
||||
string $url,
|
||||
array $headers = []
|
||||
) {
|
||||
parent::__construct($url, 301, $headers);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Http\Exceptions;
|
||||
|
||||
class HttpRedirect extends HttpException
|
||||
{
|
||||
/**
|
||||
* @param string $url
|
||||
* @param int $statusCode
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct(
|
||||
string $url,
|
||||
int $statusCode = 302,
|
||||
array $headers = []
|
||||
) {
|
||||
$headers = array_merge([
|
||||
'Location' => $url,
|
||||
], $headers);
|
||||
|
||||
parent::__construct($statusCode, '', $headers);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Http\Exceptions;
|
||||
|
||||
class HttpTemporaryRedirect extends HttpRedirect
|
||||
{
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct(
|
||||
string $url,
|
||||
array $headers = []
|
||||
) {
|
||||
parent::__construct($url, 302, $headers);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Http;
|
||||
|
||||
use Engelsystem\Http\Exceptions\HttpPermanentRedirect;
|
||||
use Engelsystem\Http\Exceptions\HttpRedirect;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HttpPermanentRedirectTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Engelsystem\Http\Exceptions\HttpPermanentRedirect::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$exception = new HttpPermanentRedirect('https://lorem.ipsum/foo/bar');
|
||||
$this->assertInstanceOf(HttpRedirect::class, $exception);
|
||||
$this->assertEquals(301, $exception->getStatusCode());
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Http;
|
||||
|
||||
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
||||
use Engelsystem\Http\Exceptions\HttpRedirect;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HttpRedirectTest extends TestCase
|
||||
{
|
||||
use ArraySubsetAsserts;
|
||||
|
||||
/**
|
||||
* @covers \Engelsystem\Http\Exceptions\HttpRedirect::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$exception = new HttpRedirect('https://lorem.ipsum/foo/bar');
|
||||
$this->assertEquals(302, $exception->getStatusCode());
|
||||
$this->assertArraySubset(['Location' => 'https://lorem.ipsum/foo/bar'], $exception->getHeaders());
|
||||
|
||||
$exception = new HttpRedirect('/test', 301, ['lorem' => 'ipsum']);
|
||||
$this->assertEquals(301, $exception->getStatusCode());
|
||||
$this->assertArraySubset(['lorem' => 'ipsum'], $exception->getHeaders());
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Unit\Http;
|
||||
|
||||
use Engelsystem\Http\Exceptions\HttpRedirect;
|
||||
use Engelsystem\Http\Exceptions\HttpTemporaryRedirect;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HttpTemporaryRedirectTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Engelsystem\Http\Exceptions\HttpTemporaryRedirect::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$exception = new HttpTemporaryRedirect('https://lorem.ipsum/foo/bar');
|
||||
$this->assertInstanceOf(HttpRedirect::class, $exception);
|
||||
$this->assertEquals(302, $exception->getStatusCode());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue