Test Failed
Push — master ( 4e95aa...c2cb3f )
by mcfog
01:51
created

MiddlewarePipeTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 90.2 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 46
loc 51
rs 10
c 0
b 0
f 0

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 namespace Nimo\Tests;
2
3
use Nimo\MiddlewarePipe;
4
5
/**
6
 * User: mcfog
7
 * Date: 15/9/12
8
 */
9
class MiddlewarePipeTest extends NimoTestCase
10
{
11
    public function testEmptyStack()
12
    {
13
        $stack = new MiddlewarePipe();
14
        $answerRes = $this->getResponseMock();
15
        $request = $this->getRequestMock();
16
17
        $handler = $this->assertedHandler($request, $answerRes);
18
        $res = $stack->process($request, $handler);
19
        self::assertSame($answerRes, $res);
20
    }
21
22
    public function testAppend()
23
    {
24
        $stack = new MiddlewarePipe();
25
        $request = $this->getRequestMock();
26
        $request2 = $this->getRequestMock();
27
        $request3 = $this->getRequestMock();
28
        $response = $this->getResponseMock();
29
        $middleware1 = $this->assertedNoopMiddleware($request, $request2);
30
        $middleware2 = $this->assertedNoopMiddleware($request2, $request3);
31
        $handler = $this->assertedHandler($request3, $response);
32
33
        $stack
34
            ->append($middleware1)
35
            ->append($middleware2);
36
37
        $res = $stack->process($request, $handler);
38
        self::assertSame($response, $res);
39
    }
40
41
    public function testPrepend()
42
    {
43
        $stack = new MiddlewarePipe();
44
        $request = $this->getRequestMock();
45
        $request2 = $this->getRequestMock();
46
        $request3 = $this->getRequestMock();
47
        $response = $this->getResponseMock();
48
        $middleware1 = $this->assertedNoopMiddleware($request, $request2);
49
        $middleware2 = $this->assertedNoopMiddleware($request2, $request3);
50
        $handler = $this->assertedHandler($request3, $response);
51
52
        $stack
53
            ->prepend($middleware2)
54
            ->prepend($middleware1);
55
56
        $res = $stack->process($request, $handler);
57
        self::assertSame($response, $res);
58
    }
59
}
60