summaryrefslogtreecommitdiff
path: root/tests/Utils/TestMiddleware.php
blob: eb3ea04fa41d7299a41777fd090c1e5b3c800996 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

declare(strict_types=1);

namespace Lightscale\Router\Test\Utils;

use Lightscale\Router\Contracts\Middleware;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class TestMiddleware implements Middleware
{
    private static int $staticCalls = 0;

    private int $call;
    private int $calls = 0;

    public static function resetCalls(): void
    {
        self::$staticCalls = 0;
    }

    public function handle(ServerRequestInterface $request, callable $next): ResponseInterface
    {
        ++$this->calls;
        $this->call = ++self::$staticCalls;

        return $next($request);
    }

    public function assertCalled(): void
    {
        Assert::assertGreaterThan(0, $this->calls);
    }

    public function assertCallNumber(int $num): void
    {
        Assert::assertSame($num, $this->call);
    }
}