-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http and server structure + error handler
* http and server structures * add error handler
- Loading branch information
Showing
11 changed files
with
350 additions
and
11 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
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 mattvb91\CaddyPhp\Config\Apps\Http\Server\Routes\Handle; | ||
|
||
use mattvb91\CaddyPhp\Interfaces\Apps\Servers\Routes\Handle\HandlerInterface; | ||
|
||
class Error implements HandlerInterface | ||
{ | ||
private string $_error; | ||
|
||
private string|int $_statusCode; | ||
|
||
public function setError(string $error): static | ||
{ | ||
$this->_error = $error; | ||
|
||
return $this; | ||
} | ||
|
||
public function setStatusCode(int|string $statusCode): static | ||
{ | ||
$this->_statusCode = $statusCode; | ||
|
||
return $this; | ||
} | ||
|
||
|
||
public function toArray(): array | ||
{ | ||
$config = [ | ||
'handler' => $this->getHandler() | ||
]; | ||
|
||
if(isset($this->_error)) { | ||
$config['error'] = $this->_error; | ||
} | ||
|
||
if(isset($this->_statusCode)) { | ||
$config['status_code'] = $this->_statusCode; | ||
} | ||
|
||
return $config; | ||
} | ||
|
||
public function getHandler(): string | ||
{ | ||
return 'error'; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Tests\Integration\Apps\Http; | ||
|
||
use mattvb91\CaddyPhp\Caddy; | ||
use mattvb91\CaddyPhp\Config\Apps\Http; | ||
use Tests\TestCase; | ||
|
||
class ServerTest extends TestCase | ||
{ | ||
/** | ||
* @coversNothing | ||
*/ | ||
public function test_server() | ||
{ | ||
$server = $this->getServerForTest(); | ||
|
||
$caddy = (new Caddy()) | ||
->addApp((new Http())->addServer('test', $server)); | ||
|
||
$this->assertCaddyConfigLoaded($caddy); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Apps\Http\Server\Routes; | ||
|
||
use mattvb91\CaddyPhp\Config\Apps\Http\Server\Routes\Handle\Error; | ||
use Tests\TestCase; | ||
|
||
class HandlerTest extends TestCase | ||
{ | ||
/** | ||
* @covers \mattvb91\CaddyPhp\Config\Apps\Http\Server\Routes\Handle\Error::getHandler | ||
* @covers \mattvb91\CaddyPhp\Config\Apps\Http\Server\Routes\Handle\Error::toArray | ||
* @covers \mattvb91\CaddyPhp\Config\Apps\Http\Server\Routes\Handle\Error::setError | ||
* @covers \mattvb91\CaddyPhp\Config\Apps\Http\Server\Routes\Handle\Error::setStatusCode | ||
*/ | ||
public function test_error_hander() | ||
{ | ||
$error = (new Error()) | ||
->setStatusCode(501) | ||
->setError('this is an error'); | ||
|
||
$this->assertEquals([ | ||
'handler' => 'error', | ||
'status_code' => 501, | ||
'error' => 'this is an error' | ||
], $error->toArray()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/Unit/Apps/RoutesTest.php → ...it/Apps/Http/Server/Routes/RoutesTest.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
Oops, something went wrong.