Skip to content

Commit

Permalink
qa: fix failing CS checks and prophecy warnings
Browse files Browse the repository at this point in the history
- Adds the phpspec/prophecy-phpunit package, and updates all tests that use prophecys to use the `ProphecyTrait` from that package.
- Corrects all phpcs issues.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
  • Loading branch information
weierophinney committed Jan 6, 2021
1 parent 24d175f commit f65c4bf
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 40 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -39,6 +39,7 @@
"laminas/laminas-coding-standard": "~2.1.0",
"malukenho/docheader": "^0.1.6",
"phpspec/prophecy": "^1.9",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.4.1",
"psalm/plugin-phpunit": "^0.15.0",
"vimeo/psalm": "^4.3"
Expand Down
8 changes: 0 additions & 8 deletions src/Test/AbstractImplicitMethodsIntegrationTest.php
Expand Up @@ -119,8 +119,6 @@ public function method(): Generator

/**
* @dataProvider method
*
* @return void
*/
public function testExplicitRequest(string $method, array $routes): void
{
Expand Down Expand Up @@ -202,8 +200,6 @@ public function withoutImplicitMiddleware()
* returned response should be 405: Method Not Allowed - handled by MethodNotAllowedMiddleware.
*
* @dataProvider withoutImplicitMiddleware
*
* @return void
*/
public function testWithoutImplicitMiddleware(string $requestMethod, array $allowedMethods): void
{
Expand Down Expand Up @@ -252,8 +248,6 @@ abstract public function implicitRoutesAndRequests(): Generator;

/**
* @dataProvider implicitRoutesAndRequests
*
* @return void
*/
public function testImplicitHeadRequest(
string $routePath,
Expand Down Expand Up @@ -334,8 +328,6 @@ public function testImplicitHeadRequest(

/**
* @dataProvider implicitRoutesAndRequests
*
* @return void
*/
public function testImplicitOptionsRequest(
string $routePath,
Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/DispatchMiddlewareFactoryTest.php
Expand Up @@ -13,10 +13,13 @@
use Mezzio\Router\Middleware\DispatchMiddleware;
use Mezzio\Router\Middleware\DispatchMiddlewareFactory;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Container\ContainerInterface;

class DispatchMiddlewareFactoryTest extends TestCase
{
use ProphecyTrait;

public function testFactoryProducesDispatchMiddleware(): void
{
$container = $this->prophesize(ContainerInterface::class)->reveal();
Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/DispatchMiddlewareTest.php
Expand Up @@ -14,13 +14,16 @@
use Mezzio\Router\RouteResult;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class DispatchMiddlewareTest extends TestCase
{
use ProphecyTrait;

/** @var RequestHandlerInterface|ObjectProphecy */
private $handler;

Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/ImplicitHeadMiddlewareFactoryTest.php
Expand Up @@ -15,13 +15,16 @@
use Mezzio\Router\Middleware\ImplicitHeadMiddlewareFactory;
use Mezzio\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\StreamInterface;
use Zend\Expressive\Router\RouterInterface as ZendExpressiveRouterInterface;

class ImplicitHeadMiddlewareFactoryTest extends TestCase
{
use ProphecyTrait;

/** @var ContainerInterface|ObjectProphecy */
private $container;

Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/ImplicitHeadMiddlewareTest.php
Expand Up @@ -17,6 +17,7 @@
use Mezzio\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -26,6 +27,8 @@

class ImplicitHeadMiddlewareTest extends TestCase
{
use ProphecyTrait;

/** @var ImplicitHeadMiddleware */
private $middleware;

Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/ImplicitOptionsMiddlewareFactoryTest.php
Expand Up @@ -14,12 +14,15 @@
use Mezzio\Router\Middleware\ImplicitOptionsMiddleware;
use Mezzio\Router\Middleware\ImplicitOptionsMiddlewareFactory;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;

class ImplicitOptionsMiddlewareFactoryTest extends TestCase
{
use ProphecyTrait;

/** @var ContainerInterface|ObjectProphecy */
private $container;

Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/ImplicitOptionsMiddlewareTest.php
Expand Up @@ -15,6 +15,7 @@
use Mezzio\Router\Route;
use Mezzio\Router\RouteResult;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -24,6 +25,8 @@

class ImplicitOptionsMiddlewareTest extends TestCase
{
use ProphecyTrait;

/** @var ImplicitOptionsMiddleware */
private $middleware;

Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/MethodNotAllowedMiddlewareFactoryTest.php
Expand Up @@ -14,12 +14,15 @@
use Mezzio\Router\Middleware\MethodNotAllowedMiddleware;
use Mezzio\Router\Middleware\MethodNotAllowedMiddlewareFactory;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;

class MethodNotAllowedMiddlewareFactoryTest extends TestCase
{
use ProphecyTrait;

/** @var ContainerInterface|ObjectProphecy */
private $container;

Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/MethodNotAllowedMiddlewareTest.php
Expand Up @@ -16,13 +16,16 @@
use Mezzio\Router\RouteResult;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class MethodNotAllowedMiddlewareTest extends TestCase
{
use ProphecyTrait;

/** @var RequestHandlerInterface|ObjectProphecy */
private $handler;

Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/RouteMiddlewareFactoryTest.php
Expand Up @@ -16,12 +16,15 @@
use Mezzio\Router\Middleware\RouteMiddlewareFactory;
use Mezzio\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use Zend\Expressive\Router\RouterInterface as ZendExpressiveRouterInterface;

class RouteMiddlewareFactoryTest extends TestCase
{
use ProphecyTrait;

/** @var ContainerInterface|ObjectProphecy */
private $container;

Expand Down
3 changes: 3 additions & 0 deletions test/Middleware/RouteMiddlewareTest.php
Expand Up @@ -15,6 +15,7 @@
use Mezzio\Router\RouteResult;
use Mezzio\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -24,6 +25,8 @@

class RouteMiddlewareTest extends TestCase
{
use ProphecyTrait;

/** @var RouterInterface|ObjectProphecy */
private $router;

Expand Down
3 changes: 3 additions & 0 deletions test/RouteCollectorFactoryTest.php
Expand Up @@ -15,13 +15,16 @@
use Mezzio\Router\RouteCollectorFactory;
use Mezzio\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use ReflectionProperty;
use Zend\Expressive\Router\RouterInterface as ZendExpressiveRouterInterface;

class RouteCollectorFactoryTest extends TestCase
{
use ProphecyTrait;

/** @var ContainerInterface|ObjectProphecy */
private $container;

Expand Down
15 changes: 4 additions & 11 deletions test/RouteCollectorTest.php
Expand Up @@ -17,6 +17,7 @@
use Mezzio\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -31,6 +32,8 @@

class RouteCollectorTest extends TestCase
{
use ProphecyTrait;

/** @var RouterInterface|ObjectProphecy */
private $router;

Expand Down Expand Up @@ -73,8 +76,7 @@ public function process(

/**
* @return string[][]
*
* @psalm-return array{GET: array{0: string}, POST: array{0: string}, PUT: array{0: string}, PATCH: array{0: string}, DELETE: array{0: string}}
* @psalm-return array<array-key, array{0:string}>
*/
public function commonHttpMethods(): array
{
Expand Down Expand Up @@ -108,10 +110,7 @@ public function testAnyRouteMethod(): void

/**
* @dataProvider commonHttpMethods
*
* @param string $method
*
* @return void
*/
public function testCanCallRouteWithHttpMethods($method): void
{
Expand Down Expand Up @@ -164,10 +163,7 @@ public function invalidPathTypes(): array

/**
* @dataProvider invalidPathTypes
*
* @param mixed $path
*
* @return void
*/
public function testCallingRouteWithAnInvalidPathTypeRaisesAnException($path): void
{
Expand All @@ -177,10 +173,7 @@ public function testCallingRouteWithAnInvalidPathTypeRaisesAnException($path): v

/**
* @dataProvider commonHttpMethods
*
* @param mixed $method
*
* @return void
*/
public function testCommonHttpMethodsAreExposedAsClassMethodsAndReturnRoutes($method): void
{
Expand Down
13 changes: 6 additions & 7 deletions test/RouteResultTest.php
Expand Up @@ -13,6 +13,8 @@
use Mezzio\Router\Route;
use Mezzio\Router\RouteResult;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
Expand All @@ -22,6 +24,8 @@
*/
class RouteResultTest extends TestCase
{
use ProphecyTrait;

public function testRouteNameIsNotRetrievable(): void
{
$result = RouteResult::fromRouteFailure([]);
Expand Down Expand Up @@ -65,9 +69,8 @@ public function testRouteSuccessMethodFailure(): void
}

/**
* @return (RouteResult|\Prophecy\Prophecy\ObjectProphecy)[]
*
* @psalm-return array{route: \Prophecy\Prophecy\ObjectProphecy<Route>, result: RouteResult}
* @return (RouteResult|ObjectProphecy)[]
* @psalm-return array{route: ObjectProphecy<Route>, result: RouteResult}
*/
public function testFromRouteShouldComposeRouteInResult(): array
{
Expand All @@ -83,8 +86,6 @@ public function testFromRouteShouldComposeRouteInResult(): array

/**
* @depends testFromRouteShouldComposeRouteInResult
*
* @return void
*/
public function testAllAccessorsShouldReturnExpectedDataWhenResultCreatedViaFromRoute(array $data): void
{
Expand Down Expand Up @@ -114,8 +115,6 @@ public function testFailureResultDoesNotIndicateAMethodFailureIfAllMethodsAreAll

/**
* @depends testFailureResultDoesNotIndicateAMethodFailureIfAllMethodsAreAllowed
*
* @return void
*/
public function testAllowedMethodsIncludesASingleWildcardEntryWhenAllMethodsAllowedForFailureResult(
RouteResult $result
Expand Down

0 comments on commit f65c4bf

Please sign in to comment.