Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TooManyRequestsException #12

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
);
}
}

}