Completed
Pull Request — master (#46)
by
unknown
05:21
created

HeadersMatchingPolicySpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 43.84 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 32
loc 73
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 5 1
A it_is_matching_policy() 0 4 1
A it_match_when_request_config_does_not_have_headers() 0 12 1
A it_not_match_when_header_is_missing_in_request() 0 12 1
A it_not_match_when_header_value_in_request_is_different_than_expected() 13 13 1
A it_match_when_headers_from_config_are_equal_headers_from_request() 19 19 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
3
namespace spec\Coduo\TuTu\Request;
4
5
use Coduo\PHPMatcher\Factory\SimpleFactory;
6
use Coduo\TuTu\Config\Element;
7
use PhpSpec\ObjectBehavior;
8
use Prophecy\Argument;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class HeadersMatchingPolicySpec extends ObjectBehavior
12
{
13
    function let()
14
    {
15
        $phpMatcher = (new SimpleFactory())->createMatcher();
16
        $this->beConstructedWith($phpMatcher);
17
    }
18
19
    function it_is_matching_policy()
20
    {
21
        $this->shouldBeAnInstanceOf('Coduo\TuTu\Request\MatchingPolicy');
22
    }
23
24
    function it_match_when_request_config_does_not_have_headers()
25
    {
26
        $responseConfig = Element::fromArray([
27
            'request' => [
28
                'path' => '/foo',
29
                'headers' => []
30
            ],
31
        ]);
32
        $request = Request::create('/foo');
33
34
        $this->match($request, $responseConfig)->shouldReturn(true);
35
    }
36
37
    function it_not_match_when_header_is_missing_in_request()
38
    {
39
        $responseConfig = Element::fromArray([
40
            'request' => [
41
                'path' => '/foo',
42
                'headers' => ['Header' => 'Value']
43
            ],
44
        ]);
45
        $request = Request::create('/foo');
46
47
        $this->match($request, $responseConfig)->shouldReturn(false);
48
    }
49
50 View Code Duplication
    function it_not_match_when_header_value_in_request_is_different_than_expected()
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...
51
    {
52
        $responseConfig = Element::fromArray([
53
            'request' => [
54
                'path' => '/foo',
55
                'headers' => ['Header' => 'Value']
56
            ],
57
        ]);
58
        $request = Request::create('/foo');
59
        $request->headers->add(['Header' => 'Different Value']);
60
61
        $this->match($request, $responseConfig)->shouldReturn(false);
62
    }
63
64 View Code Duplication
    function it_match_when_headers_from_config_are_equal_headers_from_request()
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...
65
    {
66
        $responseConfig = Element::fromArray([
67
            'request' => [
68
                'path' => '/foo',
69
                'headers' => [
70
                    'Header' => 'Value',
71
                    'Header1' => 'Value1'
72
                ]
73
            ],
74
        ]);
75
        $request = Request::create('/foo');
76
        $request->headers->add([
77
            'Header' => 'Value',
78
            'Header1' => 'Value1'
79
        ]);
80
81
        $this->match($request, $responseConfig)->shouldReturn(true);
82
    }
83
}
84