Skip to content

Commit

Permalink
Add Psalm
Browse files Browse the repository at this point in the history
At a level of strictness the project can currently meet
  • Loading branch information
kevinsmith committed Mar 4, 2020
1 parent 0f138d1 commit ec5015d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ before_script:
script:
- php vendor/bin/phpunit --coverage-clover=coverage.clover
- php vendor/bin/phpstan analyse --no-interaction
- php vendor/bin/psalm
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"laminas/laminas-diactoros": "~1.0",
"phpstan/phpstan": "^0.12.14",
"phpunit/phpunit": "~7.0",
"roave/security-advisories": "dev-master"
"roave/security-advisories": "dev-master",
"vimeo/psalm": "^3.9"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 17 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
errorLevel="5"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<directory name="tests"/>
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
8 changes: 5 additions & 3 deletions src/RelayBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
namespace Relay;

use ArrayObject;
use Traversable;

/**
*
Expand All @@ -24,7 +26,7 @@ class RelayBuilder
*
* A callable to convert queue entries to callables in the Runner.
*
* @var callable|ResolverInterface
* @var callable
*
*/
protected $resolver;
Expand All @@ -33,7 +35,7 @@ class RelayBuilder
*
* Constructor.
*
* @param callable|ResolverInterface $resolver A callable to convert a queue entry to
* @param callable $resolver A callable to convert a queue entry to
* a callable|MiddlewareInterface in the Runner.
*
*/
Expand All @@ -46,7 +48,7 @@ public function __construct(callable $resolver = null)
*
* Creates a new Relay with the specified queue for its Runner objects.
*
* @param array|ArrayObject|GetArrayCopyInterface|Traversable $queue The
* @param array|ArrayObject|Traversable $queue The
* queue specification.
*
* @return Relay
Expand Down
2 changes: 1 addition & 1 deletion tests/RelayBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testInvalidArgument()

public function testEmptyQueue()
{
$this->expectException(InvalidArgumentException::CLASS);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$queue cannot be empty');

$this->relayBuilder->newInstance([]);
Expand Down
17 changes: 10 additions & 7 deletions tests/RelayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp()
};
}

protected function assertRelay($relay)
protected function assertRelay(Relay $relay)
{
FakeMiddleware::$count = 0;

Expand Down Expand Up @@ -60,23 +60,26 @@ public function testTraversableQueue()
$this->assertRelay(new Relay($queue));
}

/**
* @psalm-suppress InvalidArgument
*/
public function testBadQueue()
{
$this->expectException(TypeError::CLASS);
$this->expectException(TypeError::class);
new Relay('bad');
}

public function testEmptyQueue()
{
$this->expectException(InvalidArgumentException::CLASS);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$queue cannot be empty');

new Relay([]);
}

public function testQueueWithInvalidEntry()
{
$this->expectException(RuntimeException::CLASS);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage(
"Invalid middleware queue entry: bad. Middleware must either be callable or implement Psr\Http\Server\MiddlewareInterface."
);
Expand All @@ -88,9 +91,9 @@ public function testQueueWithInvalidEntry()
public function testResolverEntries()
{
$queue = [
FakeMiddleware::CLASS,
FakeMiddleware::CLASS,
FakeMiddleware::CLASS,
FakeMiddleware::class,
FakeMiddleware::class,
FakeMiddleware::class,
$this->responder,
];

Expand Down

0 comments on commit ec5015d

Please sign in to comment.