From 035c78095ac6536981e5cb88dedcdd7ae9a0be7f Mon Sep 17 00:00:00 2001 From: arnold Date: Thu, 29 Aug 2024 23:53:50 +0200 Subject: [PATCH] Type defs for PHP 8.1+ --- composer.json | 3 +- phpstan.neon | 2 +- src/Endpoint.php | 37 +------- src/Generator.php | 20 ++--- src/Generator/GenerateFunction.php | 25 +----- src/Generator/GenerateInvokeMiddleware.php | 17 +--- src/Generator/GenerateRouteMiddleware.php | 14 ++-- src/Invoker.php | 21 +---- src/NoInvoker.php | 6 +- src/NotFoundMiddleware.php | 12 +-- tests/Utils/CallbackMockTrait.php | 84 ------------------- tests/Utils/Consecutive.php | 69 --------------- tests/unit/Generator/GenerateFunctionTest.php | 5 +- .../GenerateInvokeMiddlewareTest.php | 10 ++- tests/unit/GeneratorTest.php | 2 +- tests/unit/InvokerTest.php | 14 ++-- tests/unit/NoInvokerTest.php | 5 +- tests/unit/NotFoundMiddlewareTest.php | 6 +- 18 files changed, 54 insertions(+), 298 deletions(-) delete mode 100644 tests/Utils/CallbackMockTrait.php delete mode 100644 tests/Utils/Consecutive.php diff --git a/composer.json b/composer.json index 87f0964..61efce1 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "ext-json": "*", "mikey179/vfsstream": "^1.6.11", "phpstan/phpstan": "~1.12.0", - "phpunit/phpunit": ">= 10.5, < 12.0", + "phpunit/phpunit": "^11.3", + "jasny/phpunit-extension": "^v0.5.0", "nyholm/psr7": "^1.1", "relay/relay": "^2.1", "squizlabs/php_codesniffer": "^3.10" diff --git a/phpstan.neon b/phpstan.neon index 4392422..3703eb2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 3 + level: 5 paths: - src diff --git a/src/Endpoint.php b/src/Endpoint.php index 6f2fdf7..0783fa2 100644 --- a/src/Endpoint.php +++ b/src/Endpoint.php @@ -12,26 +12,13 @@ */ final class Endpoint { - /** - * @var string - */ - protected $path; - - /** - * @var array[] - */ - protected $routes = []; - - /** - * @var array[] - */ - protected $vars = []; + protected string $path; + protected array $routes = []; + protected array $vars = []; /** * Endpoint constructor. - * - * @param string $path */ public function __construct(string $path) { @@ -40,13 +27,8 @@ public function __construct(string $path) /** * Add a route for this endpoint. - * - * @param string $method - * @param mixed $route - * @param array $vars - * @return static */ - public function withRoute(string $method, $route, array $vars): self + public function withRoute(string $method, mixed $route, array $vars): self { $method = strtoupper($method); @@ -63,8 +45,6 @@ public function withRoute(string $method, $route, array $vars): self /** * Get the path of this endpoint. - * - * @return string */ public function getPath(): string { @@ -73,8 +53,6 @@ public function getPath(): string /** * Get the allowed methods for this endpoint. - * - * @return array */ public function getAllowedMethods(): array { @@ -83,8 +61,6 @@ public function getAllowedMethods(): array /** * Get all routes for this endpoint. - * - * @return array[] */ public function getRoutes(): array { @@ -93,9 +69,6 @@ public function getRoutes(): array /** * Get vars for a route. - * - * @param string $method - * @return array[] */ public function getVars(string $method): array { @@ -111,8 +84,6 @@ public function getVars(string $method): array /** * Get unique routes with methods and vars. - * - * @return \Generator */ public function getUniqueRoutes(): \Generator { diff --git a/src/Generator.php b/src/Generator.php index 0d6f9fd..21b9c2c 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -5,6 +5,7 @@ namespace Jasny\SwitchRoute; use Jasny\SwitchRoute\Generator\GenerateFunction; +use RuntimeException; use Spatie\Regex\Regex; /** @@ -23,7 +24,7 @@ class Generator /** * Generator constructor. * - * @param callable $generate Callback to generate code from structure. + * @param callable|null $generate Callback to generate code from structure. */ public function __construct(callable $generate = null) { @@ -37,7 +38,7 @@ public function __construct(callable $generate = null) * @param string $file Filename to store the script. * @param callable $getRoutes Callback to get an array with the routes. * @param bool $overwrite Overwrite existing file. - * @throws \RuntimeException if file could not be created. + * @throws RuntimeException if file could not be created. */ public function generate(string $name, string $file, callable $getRoutes, bool $overwrite): void { @@ -58,7 +59,7 @@ public function generate(string $name, string $file, callable $getRoutes, bool $ if (!file_exists($dir)) { $this->tryFs(fn () => mkdir($dir, self::DIR_MODE, true)); } elseif (!is_dir($dir)) { - throw new \RuntimeException("'$dir' exists and is not a directory"); + throw new RuntimeException("'$dir' exists and is not a directory"); } $this->tryFs(fn () => file_put_contents($file, $code)); @@ -66,11 +67,8 @@ public function generate(string $name, string $file, callable $getRoutes, bool $ /** * Try a file system function and throw a \RuntimeException on failure. - * - * @param callable $fn - * @return mixed */ - protected function tryFs(callable $fn) + protected function tryFs(callable $fn): mixed { $level = error_reporting(); error_reporting($level ^ ~(E_WARNING | E_USER_WARNING | E_NOTICE | E_USER_NOTICE)); @@ -88,7 +86,7 @@ protected function tryFs(callable $fn) } if ($ret === false) { - throw new \RuntimeException(error_get_last()['message'] ?? "Unknown error"); + throw new RuntimeException(error_get_last()['message'] ?? "Unknown error"); } return $ret; @@ -99,13 +97,9 @@ protected function tryFs(callable $fn) * Uses `opcache_is_script_cached` to prevent an unnecessary filesystem read. * * {@internal opcache isn't easily testable and mocking `opcache_is_script_cached` doesn't seem that useful.}} - * - * @param string $file - * @return bool */ protected function scriptExists(string $file): bool { - /** @noinspection PhpComposerExtensionStubsInspection */ return (function_exists('opcache_is_script_cached') && opcache_is_script_cached($file)) || file_exists($file); } @@ -113,8 +107,6 @@ protected function scriptExists(string $file): bool /** * Create a structure with a leaf for each endpoint. * - * @param iterable $routes - * @return array * @throws InvalidRouteException */ protected function structureEndpoints(iterable $routes): array diff --git a/src/Generator/GenerateFunction.php b/src/Generator/GenerateFunction.php index cda196f..42e7866 100644 --- a/src/Generator/GenerateFunction.php +++ b/src/Generator/GenerateFunction.php @@ -15,15 +15,10 @@ */ class GenerateFunction extends AbstractGenerate { - /** - * @var InvokerInterface - */ - protected $invoker; + protected InvokerInterface $invoker; /** * GenerateScript constructor. - * - * @param InvokerInterface $invoker */ public function __construct(InvokerInterface $invoker = null) { @@ -71,9 +66,6 @@ function {$function}(string \$method, string \$path, ?callable \$instantiate = n /** * Generate code for an endpoint - * - * @param Endpoint $endpoint - * @return string */ protected function generateEndpoint(Endpoint $endpoint): string { @@ -90,11 +82,6 @@ protected function generateEndpoint(Endpoint $endpoint): string /** * Generate routing code for an endpoint. * - * @param string $key - * @param array $route - * @param array $vars - * @param callable|null $genArg - * @return string * @throws InvalidRouteException */ protected function generateRoute(string $key, array $route, array $vars, ?callable $genArg = null): string @@ -125,8 +112,6 @@ protected function generateRoute(string $key, array $route, array $vars, ?callab /** * Generate code for when no route matches. * - * @param Endpoint|null $endpoint - * @return string * @throws InvalidRouteException */ protected function generateDefault(?Endpoint $endpoint): string @@ -144,14 +129,8 @@ protected function generateDefault(?Endpoint $endpoint): string /** * Generate code for argument using path vars. - * - * @param array $vars - * @param string|null $name - * @param string|null $type - * @param mixed $default - * @return string */ - protected function genArg(array $vars, ?string $name, ?string $type = null, $default = null): string + protected function genArg(array $vars, ?string $name, ?string $type = null, mixed $default = null): string { if ($name === null) { $fnMap = function ($name, $pos) { diff --git a/src/Generator/GenerateInvokeMiddleware.php b/src/Generator/GenerateInvokeMiddleware.php index 89942a9..f27bed2 100644 --- a/src/Generator/GenerateInvokeMiddleware.php +++ b/src/Generator/GenerateInvokeMiddleware.php @@ -15,15 +15,10 @@ */ class GenerateInvokeMiddleware extends AbstractGenerate { - /** - * @var InvokerInterface - */ - protected $invoker; + protected InvokerInterface $invoker; /** * GenerateScript constructor. - * - * @param InvokerInterface $invoker */ public function __construct(InvokerInterface $invoker = null) { @@ -101,9 +96,6 @@ public function process(ServerRequestInterface \$request, RequestHandlerInterfac /** * Generate the PHP script with a switch for routing. - * - * @param array $routes - * @return string */ protected function generateSwitchFromRoutes(array $routes): string { @@ -139,9 +131,6 @@ protected function generateSwitchFromRoutes(array $routes): string /** * Group routes by controller name. - * - * @param array[] $routes - * @return array */ protected function groupRoutes(array $routes): array { @@ -172,10 +161,6 @@ protected function groupRoutes(array $routes): array /** * Generate routing code for an endpoint. * - * @param string $key - * @param array $route - * @param array $vars - * @return string * @throws InvalidRouteException */ protected function generateRoute(string $key, array $route, array $vars): string diff --git a/src/Generator/GenerateRouteMiddleware.php b/src/Generator/GenerateRouteMiddleware.php index 3bcf022..7fd4530 100644 --- a/src/Generator/GenerateRouteMiddleware.php +++ b/src/Generator/GenerateRouteMiddleware.php @@ -91,22 +91,18 @@ protected function generateEndpoint(Endpoint $endpoint): string /** * Generate routing code for an endpoint. * - * @param string $_ - * @param array $route - * @param array $vars - * @return string * @throws InvalidRouteException */ - protected function generateRoute(string $_, array $route, array $vars): string + protected function generateRoute(string $key, array $route, array $vars): string { $code = ['return $request']; - foreach ($route as $key => $value) { - $code[] = " ->withAttribute('route:" . addslashes($key) . "', " . var_export($value, true) . ")"; + foreach ($route as $k => $v) { + $code[] = " ->withAttribute('route:" . addslashes($k) . "', " . var_export($v, true) . ")"; } - foreach ($vars as $key => $index) { - $code[] = " ->withAttribute('route:{" . addslashes($key) . "}', \$segments[{$index}])"; + foreach ($vars as $k => $index) { + $code[] = " ->withAttribute('route:{" . addslashes($k) . "}', \$segments[{$index}])"; } $code[array_key_last($code)] .= ';'; diff --git a/src/Invoker.php b/src/Invoker.php index 0f415e0..b766311 100644 --- a/src/Invoker.php +++ b/src/Invoker.php @@ -24,10 +24,7 @@ class Invoker implements InvokerInterface */ protected $createInvokable; - /** - * @var ReflectionFactoryInterface - */ - protected $reflection; + protected ReflectionFactoryInterface|ReflectionFactory $reflection; /** * Invoker constructor. @@ -77,7 +74,7 @@ public function generateInvocation(array $route, callable $genArg, string $new = * @return string */ protected function generateInvocationMethod( - $invokable, + array|string $invokable, ReflectionMethod $reflection, string $new = '(new \\%s)' ): string { @@ -113,10 +110,8 @@ protected function generateInvocationArgs(ReflectionFunctionAbstract $reflection /** * Assert that invokable is a function name or array with class and method. - * - * @param mixed $invokable */ - protected function assertInvokable($invokable): void + protected function assertInvokable(mixed $invokable): void { $valid = is_callable($invokable, true) && ( ( @@ -147,11 +142,9 @@ protected function assertInvokable($invokable): void /** * Get reflection of invokable. * - * @param array|string $invokable - * @return ReflectionFunction|ReflectionMethod * @throws ReflectionException if function or method doesn't exist */ - protected function getReflection($invokable): ReflectionFunctionAbstract + protected function getReflection(array|string $invokable): ReflectionFunction|ReflectionMethod { if (is_string($invokable) && strpos($invokable, '::') !== false) { $invokable = explode('::', $invokable); @@ -164,8 +157,6 @@ protected function getReflection($invokable): ReflectionFunctionAbstract /** * Generate standard code for when no route matches. - * - * @return string */ public function generateDefault(): string { @@ -183,10 +174,6 @@ public function generateDefault(): string /** * Default method to create invokable from controller and action FQCN. - * - * @param string|null $controller - * @param string|null $action - * @return array */ final public static function createInvokable(?string $controller, ?string $action): array { diff --git a/src/NoInvoker.php b/src/NoInvoker.php index b288ed0..8d2c3de 100644 --- a/src/NoInvoker.php +++ b/src/NoInvoker.php @@ -17,18 +17,16 @@ class NoInvoker implements InvokerInterface * * @param array $route * @param callable $genArg Callback to generate code for arguments. - * @param string $new PHP code to instantiate class. + * @param string $new Unused * @return string */ - public function generateInvocation(array $route, callable $genArg, string $new = '(new %s)'): string + public function generateInvocation(array $route, callable $genArg, string $new = ''): string { return '[200, ' . var_export($route, true) . ', ' . $genArg(null) . ']'; } /** * Generate standard code for when no route matches. - * - * @return string */ public function generateDefault(): string { diff --git a/src/NotFoundMiddleware.php b/src/NotFoundMiddleware.php index e332f1e..d6d28e9 100644 --- a/src/NotFoundMiddleware.php +++ b/src/NotFoundMiddleware.php @@ -15,10 +15,7 @@ */ class NotFoundMiddleware implements MiddlewareInterface { - /** - * @var ResponseFactoryInterface - */ - protected $responseFactory; + protected ResponseFactoryInterface $responseFactory; /** * Class constructor. @@ -32,9 +29,6 @@ public function __construct(ResponseFactoryInterface $responseFactory) /** * The default action for when no route matches. - * - * @param ServerRequestInterface $request - * @return ResponseInterface */ protected function notFound(ServerRequestInterface $request): ResponseInterface { @@ -56,10 +50,6 @@ protected function notFound(ServerRequestInterface $request): ResponseInterface /** * Process an incoming server request. - * - * @param ServerRequestInterface $request - * @param RequestHandlerInterface $handler - * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { diff --git a/tests/Utils/CallbackMockTrait.php b/tests/Utils/CallbackMockTrait.php deleted file mode 100644 index ec63fb1..0000000 --- a/tests/Utils/CallbackMockTrait.php +++ /dev/null @@ -1,84 +0,0 @@ - - * $callback = $this->createCallbackMock($this->once(), ['abc'], 10); - * - * - * OR - * - * - * $callback = $this->createCallbackMock( - * $this->once(), - * function(InvocationMocker $invoke) { - * $invoke->with('abc')->willReturn(10); - * } - * ); - * - * - * @param InvocationOrder $matcher - * @param \Closure|array|null $assert - * @param mixed $return - * @return MockObject|callable - */ - protected function createCallbackMock($matcher, $assert = null, $return = null): MockObject - { - if (isset($assert) && !is_array($assert) && !$assert instanceof \Closure) { - $type = (is_object($assert) ? get_class($assert) . ' ' : '') . gettype($assert); - throw new \InvalidArgumentException("Expected an array or Closure, got a $type"); - } - - $callback = $this->getMockBuilder(DummyCallback::class) - ->setMockClassName('CallbackMock_' . \substr(\md5((string) \mt_rand()), 0, 8)) - ->getMock(); - $invoke = $callback->expects($matcher)->method('__invoke'); - - if ($assert instanceof \Closure) { - $assert($invoke); - } elseif (is_array($assert)) { - $invoke->with(...$assert)->willReturn($return); - } - - return $callback; - } -} - -/** - * @internal - * @codeCoverageIgnore - */ -class DummyCallback -{ - /** - * Invoke object. - * - * @return mixed - */ - public function __invoke() - { - return null; - } -} diff --git a/tests/Utils/Consecutive.php b/tests/Utils/Consecutive.php deleted file mode 100644 index 5b9b1bb..0000000 --- a/tests/Utils/Consecutive.php +++ /dev/null @@ -1,69 +0,0 @@ -with(...Consecutive::create(...$withCodes)) - */ - -declare(strict_types=1); - -namespace Jasny\SwitchRoute\Tests\Utils; - -use PHPUnit\Framework\Assert; -use PHPUnit\Framework\Constraint\Constraint; -use PHPUnit\Framework\Constraint\IsEqual; -use RuntimeException; - -class Consecutive -{ - public static function create(...$parameterGroups): array - { - $result = []; - $parametersCount = null; - $groups = []; - $values = []; - - foreach ($parameterGroups as $index => $parameters) { - // initial - $parametersCount ??= count($parameters); - - // compare - if ($parametersCount !== count($parameters)) { - throw new RuntimeException('Parameters count max much in all groups'); - } - - // prepare parameters - foreach ($parameters as $parameter) { - if (!$parameter instanceof Constraint) { - $parameter = new IsEqual($parameter); - } - - $groups[$index][] = $parameter; - } - } - - // collect values - foreach ($groups as $parameters) { - foreach ($parameters as $index => $parameter) { - $values[$index][] = $parameter; - } - } - - // build callback - for ($index = 0; $index < $parametersCount; ++$index) { - $result[$index] = Assert::callback(static function ($value) use ($values, $index) { - static $map = null; - $map ??= $values[$index]; - - $expectedArg = array_shift($map); - if ($expectedArg === null) { - throw new RuntimeException('No more expected calls'); - } - $expectedArg->evaluate($value); - - return true; - }); - } - - return $result; - } -} diff --git a/tests/unit/Generator/GenerateFunctionTest.php b/tests/unit/Generator/GenerateFunctionTest.php index 83819bd..3a81445 100644 --- a/tests/unit/Generator/GenerateFunctionTest.php +++ b/tests/unit/Generator/GenerateFunctionTest.php @@ -5,9 +5,9 @@ namespace Jasny\SwitchRoute\Tests\Generator; use Closure; +use Jasny\PHPUnit\ConsecutiveTrait; use Jasny\SwitchRoute\Endpoint; use Jasny\SwitchRoute\Generator\AbstractGenerate; -use Jasny\SwitchRoute\Tests\Utils\Consecutive; use Jasny\SwitchRoute\Generator\GenerateFunction; use Jasny\SwitchRoute\InvalidRouteException; use Jasny\SwitchRoute\Invoker; @@ -20,6 +20,7 @@ #[CoversClass(AbstractGenerate::class)] class GenerateFunctionTest extends TestCase { + use ConsecutiveTrait; use RoutesTrait; protected function getRouteArgs() @@ -53,7 +54,7 @@ public function testGenerate() $invoker = $this->createMock(Invoker::class); $invoker->expects($this->exactly(count($routeArgs)))->method('generateInvocation') - ->with(...Consecutive::create(...$routeArgs)) + ->with(...$this->consecutive(...$routeArgs)) ->willReturnCallback(function ($route, callable $genArg) { ['controller' => $controller, 'action' => $action] = $route + ['controller' => null, 'action' => null]; $arg = $action !== 'NotFoundAction' ? $genArg('id', '', null) : $genArg('allowedMethods', '', []); diff --git a/tests/unit/Generator/GenerateInvokeMiddlewareTest.php b/tests/unit/Generator/GenerateInvokeMiddlewareTest.php index 941dd59..8b1db6b 100644 --- a/tests/unit/Generator/GenerateInvokeMiddlewareTest.php +++ b/tests/unit/Generator/GenerateInvokeMiddlewareTest.php @@ -5,12 +5,13 @@ namespace Jasny\SwitchRoute\Tests\Generator; use Closure; +use Jasny\PHPUnit\ConsecutiveTrait; use Jasny\SwitchRoute\Endpoint; +use Jasny\SwitchRoute\Generator\AbstractGenerate; use Jasny\SwitchRoute\Generator\GenerateInvokeMiddleware; use Jasny\SwitchRoute\InvalidRouteException; use Jasny\SwitchRoute\Invoker; use Jasny\SwitchRoute\Tests\RoutesTrait; -use Jasny\SwitchRoute\Tests\Utils\Consecutive; use Nyholm\Psr7\ServerRequest; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -18,10 +19,11 @@ use Psr\Http\Message\ServerRequestInterface; use ReflectionException; -#[CoversClass(\Jasny\SwitchRoute\Generator\GenerateInvokeMiddleware::class)] -#[CoversClass(\Jasny\SwitchRoute\Generator\AbstractGenerate::class)] +#[CoversClass(GenerateInvokeMiddleware::class)] +#[CoversClass(AbstractGenerate::class)] class GenerateInvokeMiddlewareTest extends TestCase { + use ConsecutiveTrait; use RoutesTrait; protected function getRouteArgs() @@ -59,7 +61,7 @@ public function testGenerate(string $serverRequestClass) $invoker = $this->createMock(Invoker::class); $invoker->expects($this->exactly(count($routeArgs)))->method('generateInvocation') - ->with(...Consecutive::create(...$routeArgs)) + ->with(...$this->consecutive(...$routeArgs)) ->willReturnCallback(function ($route, callable $genArg) use ($serverRequestClass) { ['controller' => $controller, 'action' => $action] = $route; $request = $genArg('request', $serverRequestClass, null); diff --git a/tests/unit/GeneratorTest.php b/tests/unit/GeneratorTest.php index f095ccb..5179d4a 100644 --- a/tests/unit/GeneratorTest.php +++ b/tests/unit/GeneratorTest.php @@ -4,9 +4,9 @@ namespace Jasny\SwitchRoute\Tests; +use Jasny\PHPUnit\CallbackMockTrait; use Jasny\SwitchRoute\Generator; use Jasny\SwitchRoute\InvalidRouteException; -use Jasny\SwitchRoute\Tests\Utils\CallbackMockTrait; use LogicException; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; diff --git a/tests/unit/InvokerTest.php b/tests/unit/InvokerTest.php index cccca7a..0ab37b0 100644 --- a/tests/unit/InvokerTest.php +++ b/tests/unit/InvokerTest.php @@ -5,10 +5,10 @@ namespace Jasny\SwitchRoute\Tests; use BadMethodCallException; +use Jasny\PHPUnit\CallbackMockTrait; +use Jasny\PHPUnit\ConsecutiveTrait; use Jasny\ReflectionFactory\ReflectionFactory; use Jasny\SwitchRoute\Invoker; -use Jasny\SwitchRoute\Tests\Utils\CallbackMockTrait; -use Jasny\SwitchRoute\Tests\Utils\Consecutive; use LogicException; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -25,6 +25,7 @@ class InvokerTest extends TestCase { use CallbackMockTrait; + use ConsecutiveTrait; /** * Create reflection factory that will return a ReflectionMethod. @@ -34,8 +35,11 @@ class InvokerTest extends TestCase * @param ReflectionParameter[] $parameters * @return ReflectionFactory&MockObject */ - protected function createReflectionFactoryMock($invokable, $isStatic, $parameters): ReflectionFactory - { + protected function createReflectionFactoryMock( + array $invokable, + bool $isStatic, + array $parameters, + ): ReflectionFactory & MockObject { $reflection = $this->createMock(ReflectionMethod::class); $reflection->expects($this->any())->method('isStatic')->willReturn($isStatic); $reflection->expects($this->any())->method('getParameters')->willReturn($parameters); @@ -122,7 +126,7 @@ public function testGenerateWithArguments($controller, $action, $invokable, $exp $genArg = $this->createCallbackMock($this->exactly(3), function (InvocationMocker $invoke) { $invoke - ->with(...Consecutive::create(['id', null, null], ['some', null, null], ['good', 'string', 'ok'])) + ->with(...$this->consecutive(['id', null, null], ['some', null, null], ['good', 'string', 'ok'])) ->willReturnOnConsecutiveCalls("\$var['id'] ?? NULL", "\$var['some'] ?? NULL", "\$var['good'] ?? 'ok'"); }); diff --git a/tests/unit/NoInvokerTest.php b/tests/unit/NoInvokerTest.php index 6300986..ea54a12 100644 --- a/tests/unit/NoInvokerTest.php +++ b/tests/unit/NoInvokerTest.php @@ -4,12 +4,13 @@ namespace Jasny\SwitchRoute\Tests; +use Jasny\PHPUnit\CallbackMockTrait; use Jasny\SwitchRoute\NoInvoker; -use Jasny\SwitchRoute\Tests\Utils\CallbackMockTrait; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[CoversClass(NoInvoker::class)] class NoInvokerTest extends TestCase +#[CoversClass(NoInvoker::class)] +class NoInvokerTest extends TestCase { use CallbackMockTrait; diff --git a/tests/unit/NotFoundMiddlewareTest.php b/tests/unit/NotFoundMiddlewareTest.php index 57094ce..4e6486b 100644 --- a/tests/unit/NotFoundMiddlewareTest.php +++ b/tests/unit/NotFoundMiddlewareTest.php @@ -4,9 +4,9 @@ namespace Jasny\SwitchRoute\Tests; +use Jasny\PHPUnit\ConsecutiveTrait; use Jasny\SwitchRoute\NotFoundException; use Jasny\SwitchRoute\NotFoundMiddleware; -use Jasny\SwitchRoute\Tests\Utils\Consecutive; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseFactoryInterface; @@ -18,6 +18,8 @@ #[CoversClass(NotFoundMiddleware::class)] class NotFoundMiddlewareTest extends TestCase { + use ConsecutiveTrait; + public function testFound() { $request = $this->createMock(ServerRequestInterface::class); @@ -80,7 +82,7 @@ public function testMethodNotAllowed() $responseBody = $this->createMock(StreamInterface::class); $response = $this->createMock(ResponseInterface::class); $response->expects($this->exactly(2))->method('withHeader') - ->with(...Consecutive::create(['Content-Type', 'text/plain'], ['Allow', 'GET, POST'])) + ->with(...$this->consecutive(['Content-Type', 'text/plain'], ['Allow', 'GET, POST'])) ->willReturnSelf(); $response->expects($this->once())->method('getBody')->willReturn($responseBody); $responseBody->expects($this->once())->method('write')->with('Method Not Allowed');