Completed
Push — master ( ea6e0d...f60c21 )
by Alejandro
05:39 queued 02:45
created

PathVersionMiddlewareTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Rest\Middleware;
5
6
use Interop\Http\ServerMiddleware\DelegateInterface;
7
use PHPUnit\Framework\Assert;
8
use PHPUnit\Framework\TestCase;
9
use Prophecy\Argument;
10
use Psr\Http\Message\ServerRequestInterface as Request;
11
use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware;
12
use Zend\Diactoros\Response;
13
use Zend\Diactoros\ServerRequestFactory;
14
use Zend\Diactoros\Uri;
15
16
class PathVersionMiddlewareTest extends TestCase
17
{
18
    /**
19
     * @var PathVersionMiddleware
20
     */
21
    protected $middleware;
22
23
    public function setUp()
24
    {
25
        $this->middleware = new PathVersionMiddleware();
26
    }
27
28
    /**
29
     * @test
30
     */
31 View Code Duplication
    public function whenVersionIsProvidedRequestRemainsUnchanged()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/v2/foo'));
34
35
        $delegate = $this->prophesize(DelegateInterface::class);
36
        $process = $delegate->process($request)->willReturn(new Response());
37
38
        $this->middleware->process($request, $delegate->reveal());
39
40
        $process->shouldHaveBeenCalled();
41
    }
42
43
    /**
44
     * @test
45
     */
46 View Code Duplication
    public function whenPathDoesNotStartWithRestRemainsUnchanged()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/foo'));
49
50
        $delegate = $this->prophesize(DelegateInterface::class);
51
        $process = $delegate->process($request)->willReturn(new Response());
52
53
        $this->middleware->process($request, $delegate->reveal());
54
55
        $process->shouldHaveBeenCalled();
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function versionOneIsPrependedWhenNoVersionIsDefined()
62
    {
63
        $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/bar/baz'));
64
65
        $delegate = $this->prophesize(DelegateInterface::class);
66
        $delegate->process(Argument::type(Request::class))->will(function (array $args) use ($request) {
67
            $req = \array_shift($args);
68
69
            Assert::assertNotSame($request, $req);
70
            Assert::assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath());
71
            return new Response();
72
        });
73
74
75
        $this->middleware->process($request, $delegate->reveal());
76
    }
77
}
78