|
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 BodyMatchingPolicySpec 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_config_body_is_empty() |
|
25
|
|
|
{ |
|
26
|
|
|
$responseConfig = Element::fromArray([ |
|
27
|
|
|
'request' => ['path' => '/foo'], |
|
28
|
|
|
]); |
|
29
|
|
|
$request = Request::create('/foo'); |
|
30
|
|
|
|
|
31
|
|
|
$this->match($request, $responseConfig)->shouldReturn(true); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
function it_match_when_request_body_match_config_body() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$responseConfig = Element::fromArray([ |
|
37
|
|
|
'request' => [ |
|
38
|
|
|
'path' => '/foo', |
|
39
|
|
|
'headers' => [], |
|
40
|
|
|
'body' => 'HELLO WORLD' |
|
41
|
|
|
], |
|
42
|
|
|
]); |
|
43
|
|
|
$request = Request::create('/foo', 'GET', [], [], [], [], 'HELLO WORLD'); |
|
44
|
|
|
|
|
45
|
|
|
$this->match($request, $responseConfig)->shouldReturn(true); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
View Code Duplication |
function it_not_match_when_request_body_not_match_config_body() |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$responseConfig = Element::fromArray([ |
|
51
|
|
|
'request' => [ |
|
52
|
|
|
'path' => '/foo', |
|
53
|
|
|
'headers' => [], |
|
54
|
|
|
'body' => 'HELLO WORLD' |
|
55
|
|
|
], |
|
56
|
|
|
]); |
|
57
|
|
|
$request = Request::create('/foo', 'GET', [], [], [], [], 'WORLD HELLO'); |
|
58
|
|
|
|
|
59
|
|
|
$this->match($request, $responseConfig)->shouldReturn(false); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
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.