Skip to content

Commit

Permalink
Merge pull request #12 from CorpusPHP/TooManyRequestsException
Browse files Browse the repository at this point in the history
Add TooManyRequestsException
  • Loading branch information
donatj authored Sep 9, 2024
2 parents 9d17bc6 + 4fcfacd commit fe779a4
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']

runs-on: ${{ matrix.operating-system }}

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ HTTP Status Codes and Exceptions

## Requirements

- **php**: ^7.2 | ^8.0
- **php**: ^7.3 | ^8.0

## Installing

Expand Down Expand Up @@ -67,6 +67,14 @@ function getHttpStatusCode() : int
function getHttpStatusCode() : int
```

### Class: Corpus\Http\Exceptions\ClientError\TooManyRequestsException

#### Method: TooManyRequestsException->getHttpStatusCode

```php
function getHttpStatusCode() : int
```

### Class: Corpus\Http\Exceptions\ClientError\UnauthorizedException

#### Method: UnauthorizedException->getHttpStatusCode
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
}
],
"require": {
"php": "^7.2 | ^8.0"
"php": "^7.3 | ^8.0"
},
"autoload": {
"psr-4": {
"Corpus\\Http\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "~7.5 | ~9.0",
"squizlabs/php_codesniffer": "^3.5",
"corpus/coding-standard": "^0.6.0",
"friendsofphp/php-cs-fixer": "^2.17",
"phpstan/phpstan": "^1.12"
"friendsofphp/php-cs-fixer": "^3.4",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.5"
},
"config": {
"allow-plugins": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ parameters:
level: 9
paths:
- src
phpVersion: 70200
phpVersion: 70300
14 changes: 14 additions & 0 deletions src/Exceptions/ClientError/TooManyRequestsException.php
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;
}

}
45 changes: 45 additions & 0 deletions test/ExceptionNamingTest.php
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()
);
}
}

}

0 comments on commit fe779a4

Please sign in to comment.