Skip to content

Commit

Permalink
improve phpstan tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ncou committed May 29, 2019
1 parent e1046f3 commit 0570a94
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"phpstan/phpstan": "^0.9.2"
"phpstan/phpstan": "^0.11.7",
"phpstan/phpstan-strict-rules": "^0.11"
},
"autoload": {
"psr-4": {
Expand All @@ -30,7 +31,7 @@
"@phpstan"
],
"phpunit": "phpunit --colors=always",
"phpstan": "phpstan analyse src --level=7",
"phpstan": "phpstan analyze -l max -c phpstan.neon ./src",
"test-coverage": "phpunit --coverage-clover clover.xml"
},
"minimum-stability": "dev",
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
fileExtensions:
- php
reportUnmatchedIgnoredErrors: true
ignoreErrors:
# @see src/Dispatcher
- '#PHPDoc tag @param for parameter \$middleware with type array\|string\|Zend\\Stratigility\\MiddlewarePipe is not subtype of native type array\<int, mixed\>#'
5 changes: 3 additions & 2 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

namespace Chiron\Pipe;

use LogicException;
use OutOfBoundsException;
use UnexpectedValueException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

// TODO : renommer la classe en PipeHandler
class Dispatcher implements RequestHandlerInterface
{
/**
Expand Down Expand Up @@ -52,7 +53,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$middleware = $this->middlewares[$this->index++];

if (! $middleware instanceof MiddlewareInterface) {
throw new LogicException(sprintf(
throw new UnexpectedValueException(sprintf(
'Middleware "%s" is not an instance of %s',
is_object($middleware) ? get_class($middleware) : gettype($middleware),
MiddlewareInterface::class
Expand Down
6 changes: 3 additions & 3 deletions tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testDispatcherAcceptsASingleArgument()
}

/**
* @expectedException \LogicException
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage is not an instance of Psr\Http\Server\MiddlewareInterface
*/
public function testDispatcherThrowExceptionForInvalidMultipleArguments()
Expand All @@ -73,7 +73,7 @@ public function testDispatcherThrowExceptionForInvalidMultipleArguments()
}

/**
* @expectedException \LogicException
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage is not an instance of Psr\Http\Server\MiddlewareInterface
*/
public function testDispatcherThrowExceptionForInvalidSingleArrayArgument()
Expand All @@ -88,7 +88,7 @@ public function testDispatcherThrowExceptionForInvalidSingleArrayArgument()
}

/**
* @expectedException \LogicException
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage is not an instance of Psr\Http\Server\MiddlewareInterface
*/
public function testDispatcherThrowExceptionForInvalidSingleArgument()
Expand Down

0 comments on commit 0570a94

Please sign in to comment.