Completed
Push — master ( 27b08f...48acde )
by Alejandro
02:35
created

nonRestPathsAreNotProcessed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 8
loc 8
rs 9.4285
c 1
b 0
f 0
1
<?php
2
namespace ShlinkioTest\Shlink\Rest\Middleware;
3
4
use PHPUnit_Framework_TestCase as TestCase;
5
use Psr\Http\Message\ServerRequestInterface as Request;
6
use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware;
7
use Zend\Diactoros\Response;
8
use Zend\Diactoros\ServerRequestFactory;
9
use Zend\Diactoros\Uri;
10
11
class PathVersionMiddlewareTest extends TestCase
12
{
13
    /**
14
     * @var PathVersionMiddleware
15
     */
16
    protected $middleware;
17
18
    public function setUp()
19
    {
20
        $this->middleware = new PathVersionMiddleware();
21
    }
22
23
    /**
24
     * @test
25
     */
26 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...
27
    {
28
        $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/v2/foo'));
29
        $test = $this;
30
        $this->middleware->__invoke($request, new Response(), function ($req) use ($request, $test) {
31
            $test->assertSame($request, $req);
32
        });
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function versionOneIsPrependedWhenNoVersionIsDefined()
39
    {
40
        $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/rest/bar/baz'));
41
        $test = $this;
42
        $this->middleware->__invoke($request, new Response(), function (Request $req) use ($request, $test) {
43
            $test->assertNotSame($request, $req);
44
            $this->assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath());
45
        });
46
    }
47
48
    /**
49
     * @test
50
     */
51 View Code Duplication
    public function nonRestPathsAreNotProcessed()
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...
52
    {
53
        $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/non-rest'));
54
        $test = $this;
55
        $this->middleware->__invoke($request, new Response(), function ($req) use ($request, $test) {
56
            $test->assertSame($request, $req);
57
        });
58
    }
59
}
60