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

PathVersionMiddlewareTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 32.65 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 16
loc 49
rs 10
c 1
b 0
f 0
wmc 4
lcom 1
cbo 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A versionOneIsPrependedWhenNoVersionIsDefined() 0 9 1
A whenVersionIsProvidedRequestRemainsUnchanged() 8 8 1
A nonRestPathsAreNotProcessed() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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