Skip to content
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
75 changes: 37 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@ name: CI
on: [push, pull_request]

jobs:
build-test:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [8.0, 8.1, 8.2]
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

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

# - name: Submit coverage to Coveralls
# # We use php-coveralls library for this, as the official Coveralls GitHub Action lacks support for clover reports:
# # https://github.com/coverallsapp/github-action/issues/15
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# COVERALLS_PARALLEL: true
# COVERALLS_FLAG_NAME: ${{ github.job }}-PHP-${{ matrix.php_version }} ${{ matrix.composer_flags }}
# run: |
# composer global require php-coveralls/php-coveralls
# ~/.composer/vendor/bin/php-coveralls -v

build-test:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [8.1, 8.2, 8.3, 8.4]
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

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

# - name: Submit coverage to Coveralls
# # We use php-coveralls library for this, as the official Coveralls GitHub Action lacks support for clover reports:
# # https://github.com/coverallsapp/github-action/issues/15
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# COVERALLS_PARALLEL: true
# COVERALLS_FLAG_NAME: ${{ github.job }}-PHP-${{ matrix.php_version }} ${{ matrix.composer_flags }}
# run: |
# composer global require php-coveralls/php-coveralls
# ~/.composer/vendor/bin/php-coveralls -v
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
}
],
"require": {
"php": "^7.3||^8.0",
"altorouter/altorouter": "^2.0.2",
"mindplay/middleman": "^3.0.3",
"php-di/invoker": "^2.3.0",
"psr/container": "^1.0",
"psr/http-message": "^1.0",
"php": ">=8.1",
"altorouter/altorouter": "^2.0.3",
"laminas/laminas-diactoros": "^3.6.0",
"mindplay/middleman": "^4.0.4",
"php-di/invoker": "^2.3.6",
"psr/container": "^2.0.2",
"psr/http-message": "^2.0",
"psr/http-server-middleware": "^1.0",
"spatie/macroable": "^1.0",
"laminas/laminas-diactoros": "^2.4"
"spatie/macroable": "^1.0"
},
"require-dev": {
"php-di/php-di": "^6.3.4",
"phpunit/phpunit": "^9.5",
"php-coveralls/php-coveralls": "^2.4",
"mockery/mockery": "^1.4.3",
"php-coveralls/php-coveralls": "^2.4",
"php-di/php-di": "^7.1.1",
"phpunit/phpunit": "^10.5",
"squizlabs/php_codesniffer": "^3.6.0"
},
"autoload": {
Expand All @@ -49,4 +49,4 @@
"config": {
"sort-packages": true
}
}
}
31 changes: 11 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Rareloop Router Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Rareloop Router Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
6 changes: 3 additions & 3 deletions src/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function __construct(
array $methods,
string $uri,
$action,
Invoker $invoker = null,
MiddlewareResolver $resolver = null
?Invoker $invoker = null,
?MiddlewareResolver $resolver = null
) {
$this->invoker = $invoker;
$this->middlewareResolver = $resolver;
Expand Down Expand Up @@ -77,7 +77,7 @@ public function handle(ServerRequest $request, RouteParams $params): ResponseInt
return $this->middlewareResolver->resolve($name);
});

return $dispatcher->dispatch($request);
return $dispatcher->handle($request);
}

private function gatherMiddleware(): array
Expand Down
12 changes: 6 additions & 6 deletions src/RouteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RouteAction
* @param mixed $action
* @param Rareloop/Router/Invoker $invoker
*/
public function __construct($action, Invoker $invoker = null)
public function __construct($action, ?Invoker $invoker = null)
{
$this->invoker = $invoker;
$this->callable = $this->createCallableFromAction($action);
Expand Down Expand Up @@ -65,7 +65,7 @@ public function invoke(ServerRequestInterface $request, RouteParams $params)
* @param mixed $action
* @return callable
*/
private function createCallableFromAction($action) : callable
private function createCallableFromAction($action): callable
{
// Check if this looks like it could be a class/method string
if (!is_callable($action) && is_string($action)) {
Expand All @@ -80,7 +80,7 @@ private function createCallableFromAction($action) : callable
*
* @return boolean
*/
private function isControllerAction() : bool
private function isControllerAction(): bool
{
return !empty($this->controllerName) && !empty($this->controllerMethod);
}
Expand Down Expand Up @@ -127,7 +127,7 @@ private function createControllerFromClassName($className)
*
* @return bool
*/
private function providesMiddleware() : bool
private function providesMiddleware(): bool
{
$controller = $this->getController();

Expand All @@ -143,7 +143,7 @@ private function providesMiddleware() : bool
*
* @return array
*/
public function getMiddleware() : array
public function getMiddleware(): array
{
if (!$this->providesMiddleware()) {
return [];
Expand All @@ -170,7 +170,7 @@ function ($controllerMiddleware) {
* @param string $string e.g. `MyController@myMethod`
* @return Closure
*/
private function convertClassStringToFactory($string) : Closure
private function convertClassStringToFactory($string): Closure
{
$this->controllerName = null;
$this->controllerMethod = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Router implements Routable
private $invoker = null;
private $baseMiddleware = [];

public function __construct(ContainerInterface $container = null, MiddlewareResolver $resolver = null)
public function __construct(?ContainerInterface $container = null, ?MiddlewareResolver $resolver = null)
{
if (isset($container)) {
$this->setContainer($container);
Expand Down Expand Up @@ -194,7 +194,7 @@ function ($request) use ($route, $params) {
return $this->middlewareResolver->resolve($name);
});

return $dispatcher->dispatch($request);
return $dispatcher->handle($request);
}

public function has(string $name)
Expand Down
15 changes: 8 additions & 7 deletions tests/ControllerMiddlewareOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use PHPUnit\Framework\TestCase;
use Rareloop\Router\ControllerMiddlewareOptions;
use PHPUnit\Framework\Attributes\Test;

class ControllerMiddlewareOptionsTest extends TestCase
{
/** @test */
#[Test]
public function by_default_no_methods_are_excluded()
{
$options = new ControllerMiddlewareOptions;
Expand All @@ -16,15 +17,15 @@ public function by_default_no_methods_are_excluded()
$this->assertFalse($options->excludedForMethod('bar'));
}

/** @test */
#[Test]
public function only_is_chainable()
{
$options = new ControllerMiddlewareOptions;

$this->assertSame($options, $options->only('foo'));
}

/** @test */
#[Test]
public function can_use_only_to_limit_methods()
{
$options = new ControllerMiddlewareOptions;
Expand All @@ -35,7 +36,7 @@ public function can_use_only_to_limit_methods()
$this->assertTrue($options->excludedForMethod('bar'));
}

/** @test */
#[Test]
public function can_use_only_to_limit_multiple_methods()
{
$options = new ControllerMiddlewareOptions;
Expand All @@ -47,15 +48,15 @@ public function can_use_only_to_limit_multiple_methods()
$this->assertTrue($options->excludedForMethod('baz'));
}

/** @test */
#[Test]
public function except_is_chainable()
{
$options = new ControllerMiddlewareOptions;

$this->assertSame($options, $options->except('foo'));
}

/** @test */
#[Test]
public function can_use_except_to_limit_methods()
{
$options = new ControllerMiddlewareOptions;
Expand All @@ -66,7 +67,7 @@ public function can_use_except_to_limit_methods()
$this->assertFalse($options->excludedForMethod('bar'));
}

/** @test */
#[Test]
public function can_use_except_to_limit_multiple_methods()
{
$options = new ControllerMiddlewareOptions;
Expand Down
5 changes: 3 additions & 2 deletions tests/ControllerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Rareloop\Router\ControllerMiddleware;
use Rareloop\Router\ControllerMiddlewareOptions;
use Rareloop\Router\Test\Middleware\AddHeaderMiddleware;
use PHPUnit\Framework\Attributes\Test;

class ControllerMiddlewareTest extends TestCase
{
/** @test */
#[Test]
public function can_retrieve_middleware()
{
$middleware = new AddHeaderMiddleware('X-Header', 'testing123');
Expand All @@ -20,7 +21,7 @@ public function can_retrieve_middleware()
$this->assertSame($middleware, $controllerMiddleware->middleware());
}

/** @test */
#[Test]
public function can_retrieve_options()
{
$middleware = new AddHeaderMiddleware('X-Header', 'testing123');
Expand Down
Loading
Loading