-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from CorpusPHP/TooManyRequestsException
Add TooManyRequestsException
- Loading branch information
Showing
6 changed files
with
75 additions
and
8 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
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ parameters: | |
level: 9 | ||
paths: | ||
- src | ||
phpVersion: 70200 | ||
phpVersion: 70300 |
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,14 @@ | ||
<?php | ||
|
||
namespace Corpus\Http\Exceptions\ClientError; | ||
|
||
use Corpus\Http\Status; | ||
|
||
class TooManyRequestsException extends AbstractClientErrorException { | ||
|
||
/** @inheritdoc */ | ||
public function getHttpStatusCode() : int { | ||
return Status::TooManyRequests; | ||
} | ||
|
||
} |
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,45 @@ | ||
<?php | ||
|
||
|
||
use Corpus\Http\Exceptions\AbstractHttpException; | ||
use Corpus\Http\Status; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ExceptionNamingTest extends TestCase { | ||
|
||
public function testNaming() : void { | ||
$dir = new \RecursiveDirectoryIterator(__DIR__ . '/../src/Exceptions'); | ||
$ite = new \RecursiveIteratorIterator($dir); | ||
$files = new \RegexIterator($ite, "/Exception\\.php$/"); | ||
foreach( $files as $file ) { | ||
require_once $file; | ||
} | ||
|
||
$classes = array_filter(get_declared_classes(), function ($class) { | ||
return is_subclass_of($class, AbstractHttpException::class); | ||
}); | ||
|
||
foreach($classes as $className) { | ||
$reflect = new \ReflectionClass($className); | ||
if($reflect->isAbstract()) { | ||
continue; | ||
} | ||
|
||
$inst = $this->getMockBuilder($className) | ||
->onlyMethods([]) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
assert($inst instanceof AbstractHttpException); | ||
|
||
$shortName = $reflect->getShortName(); | ||
$constName = preg_replace('/Exception$/', '', $shortName); | ||
|
||
$this->assertSame( | ||
constant(Status::class . '::' . $constName), | ||
$inst->getHttpStatusCode() | ||
); | ||
} | ||
} | ||
|
||
} |