Skip to content

Commit

Permalink
Make phpunit providers static
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksei Khudiakov <[email protected]>
  • Loading branch information
Xerkus committed Nov 20, 2023
1 parent 7b3326c commit 696505c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions test/MiddlewareListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MiddlewareListenerTest extends TestCase
* @psalm-param array<string, mixed> $matchedParams
* @psalm-param array<string, object|array> $services
*/
public function createMvcEvent(array $matchedParams, array $services = []): MvcEvent
public static function createMvcEvent(array $matchedParams, array $services = []): MvcEvent
{
$response = new Response();
$routeMatch = new RouteMatch($matchedParams);
Expand All @@ -53,7 +53,7 @@ public function createMvcEvent(array $matchedParams, array $services = []): MvcE
'services' => $services,
]);

$application = $this->createMock(Application::class);
$application = self::createStub(Application::class);
$application->method('getEventManager')->willReturn($eventManager);
$application->method('getServiceManager')->willReturn($serviceManager);
$application->method('getResponse')->willReturn($response);
Expand All @@ -70,7 +70,7 @@ public function createMvcEvent(array $matchedParams, array $services = []): MvcE
/**
* @return iterable<string, array{0: array<string, mixed>, 1: array<string, object|array>, 2: string}>
*/
public function validMiddlewareProvider(): iterable
public static function validMiddlewareProvider(): iterable
{
// Remember that mutable body writes are bad!
$middleware = new class implements MiddlewareInterface {
Expand Down Expand Up @@ -224,12 +224,12 @@ public function handle(
* @psalm-param array<string, mixed> $matchedParams
* @psalm-param array<string, object|array> $services
*/
public function testSuccessfullyDispatchesMiddlewareAndReturnsResponse(
public static function testSuccessfullyDispatchesMiddlewareAndReturnsResponse(
array $matchedParams,
array $services,
string $expectedBody
): void {
$event = $this->createMvcEvent($matchedParams, $services);
$event = self::createMvcEvent($matchedParams, $services);

$listener = new MiddlewareListener(new HandlerFromPipeSpecFactory());
$return = $listener->onDispatch($event);
Expand All @@ -254,7 +254,7 @@ public function testIgnoresMiddlewareParamIfControllerMarkerIsNotPipeSpec(
array $services
): void {
$matchedParams['controller'] = 'some_controller';
$event = $this->createMvcEvent($matchedParams, $services);
$event = self::createMvcEvent($matchedParams, $services);

$listener = new MiddlewareListener(new HandlerFromPipeSpecFactory());
$return = $listener->onDispatch($event);
Expand All @@ -280,7 +280,7 @@ public function process(
},
],
];
$event = $this->createMvcEvent($matchedParams, []);
$event = self::createMvcEvent($matchedParams, []);
$application = $event->getApplication();

$application->getEventManager()->attach(
Expand Down Expand Up @@ -317,7 +317,7 @@ static function (ServerRequestInterface $request) use (&$routeMatch) {
),
];

$event = $this->createMvcEvent($matchedParams, []);
$event = self::createMvcEvent($matchedParams, []);

$listener = new MiddlewareListener(new HandlerFromPipeSpecFactory());
$return = $listener->onDispatch($event);
Expand All @@ -341,7 +341,7 @@ static function (ServerRequestInterface $request) use (&$passedRequest) {
'test_param' => 'test_param_value',
];

$event = $this->createMvcEvent($matchedParams, []);
$event = self::createMvcEvent($matchedParams, []);
$listener = new MiddlewareListener(new HandlerFromPipeSpecFactory());
$return = $listener->onDispatch($event);

Expand All @@ -362,7 +362,7 @@ public function testTriggersDispatchErrorForExceptionRaisedInMiddleware(): void
throw $exception;
}),
];
$event = $this->createMvcEvent($matchedParams, []);
$event = self::createMvcEvent($matchedParams, []);

$application = $event->getApplication();
$application->getEventManager()
Expand All @@ -386,7 +386,7 @@ public function testExhaustedMiddlewarePipeTriggersDispatchError(): void
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(),
];
$event = $this->createMvcEvent($matchedParams, []);
$event = self::createMvcEvent($matchedParams, []);

$application = $event->getApplication();
$application->getEventManager()
Expand All @@ -410,7 +410,7 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures(
array $matchedParams,
array $services
): void {
$event = $this->createMvcEvent($matchedParams, $services);
$event = self::createMvcEvent($matchedParams, $services);
$event->setError(Application::ERROR_CONTROLLER_CANNOT_DISPATCH);

$listener = new MiddlewareListener(new HandlerFromPipeSpecFactory());
Expand All @@ -434,7 +434,7 @@ public function testWillNotDispatchWhenAnMvcEventResultIsAlreadySet($alreadySetR
'controller' => PipeSpec::class,
'middleware' => $middleware,
];
$event = $this->createMvcEvent($matchedParams, []);
$event = self::createMvcEvent($matchedParams, []);
$event->setResult($alreadySetResult);

$listener = new MiddlewareListener(new HandlerFromPipeSpecFactory());
Expand All @@ -447,17 +447,17 @@ public function testWillNotDispatchWhenAnMvcEventResultIsAlreadySet($alreadySetR
/**
* @return mixed[][]
*/
public function alreadySetMvcEventResultProvider(): array
public static function alreadySetMvcEventResultProvider(): array
{
return [
[123],
[true],
[false],
[[]],
[new stdClass()],
[$this],
[$this->createMock(ModelInterface::class)],
[$this->createMock(Response::class)],
[new stdClass()],
[self::createStub(ModelInterface::class)],
[self::createStub(Response::class)],
[['view model data' => 'as an array']],
[['foo' => new stdClass()]],
['a response string'],
Expand Down

0 comments on commit 696505c

Please sign in to comment.