Skip to content

Commit

Permalink
Add PHP 8.1 support (#18)
Browse files Browse the repository at this point in the history
* Add PHP 8.1 support

* Update testing matrix

* Update CI workflow

* Update PHPUnit to v9

* Increase min PHPUnit version

Co-authored-by: Joe Lambert <[email protected]>
  • Loading branch information
joelambert and joelambert authored Jul 27, 2022
1 parent 818af59 commit e265c8e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [7.3, 7.4, 8.0]
php_version: [7.4, 8.0, 8.1]
composer_flags: ['', '--prefer-lowest']

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: xdebug

- uses: php-actions/composer@v5
with:
php_version: ${{ matrix.php_version }}
args: ${{ matrix.composer_flags }}
command: update
- uses: php-actions/phpunit@v3
with:
version: 8
php_version: ${{ matrix.php_version }}
args: '--coverage-clover ./tests/logs/clover.xml'
php_extensions: xdebug

- name: Run tests
run: ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml
env:
XDEBUG_MODE: coverage

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"require-dev": {
"php-di/php-di": "^6.3.4",
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^9.5",
"php-coveralls/php-coveralls": "^2.4",
"mockery/mockery": "^1.4.3",
"squizlabs/php_codesniffer": "^3.6.0"
Expand Down
6 changes: 3 additions & 3 deletions src/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($params, $router)
$this->middleware += $middleware;
}

$this->prefix = trim($prefix, ' /');
$this->prefix = is_string($prefix) ? trim($prefix, ' /') : null;
$this->router = $router;
}

Expand All @@ -43,12 +43,12 @@ private function appendPrefixToUri(string $uri)
return $this->prefix . '/' . ltrim($uri, '/');
}

public function map(array $verbs, string $uri, $callback) : Route
public function map(array $verbs, string $uri, $callback): Route
{
return $this->router->map($verbs, $this->appendPrefixToUri($uri), $callback)->middleware($this->middleware);
}

public function group($params, $callback) : RouteGroup
public function group($params, $callback): RouteGroup
{
if (is_string($params)) {
$params = $this->appendPrefixToUri($params);
Expand Down
5 changes: 5 additions & 0 deletions src/RouteParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,32 @@ public function __get($key)
return $this->params[$key];
}

#[\ReturnTypeWillChange]
public function rewind()
{
$this->position = 0;
}

#[\ReturnTypeWillChange]
public function current()
{
return $this->params[$this->key()];
}

#[\ReturnTypeWillChange]
public function key()
{
$keys = array_keys($this->params);
return $keys[$this->position];
}

#[\ReturnTypeWillChange]
public function next()
{
$this->position++;
}

#[\ReturnTypeWillChange]
public function valid()
{
return $this->position < count($this->params);
Expand Down
4 changes: 2 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ public function url(string $name, $params = [])
try {
return $this->altoRouter->generate($name, $params);
} catch (\Exception $e) {
throw new NamedRouteNotFoundException($name, null);
throw new NamedRouteNotFoundException($name);
}
}

public function group($params, $callback) : Router
public function group($params, $callback): Router
{
$group = new RouteGroup($params, $this);

Expand Down

0 comments on commit e265c8e

Please sign in to comment.