1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\Yproximite\WannaSpeakBundle\Api; |
6
|
|
|
|
7
|
|
|
use PhpSpec\ObjectBehavior; |
8
|
|
|
use Symfony\Contracts\HttpClient\ResponseInterface; |
9
|
|
|
use Yproximite\WannaSpeakBundle\Api\CallTrackings; |
10
|
|
|
use Yproximite\WannaSpeakBundle\Api\CallTrackingsInterface; |
11
|
|
|
use Yproximite\WannaSpeakBundle\HttpClientInterface; |
12
|
|
|
|
13
|
|
|
class CallTrackingsSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
public function it_is_initializable() |
16
|
|
|
{ |
17
|
|
|
$this->shouldHaveType(CallTrackings::class); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
View Code Duplication |
public function let(HttpClientInterface $client, ResponseInterface $response): void |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$this->beConstructedWith($client); |
23
|
|
|
|
24
|
|
|
// Since we are in spec, the response content will always be the, see PHPUnit tests for real response asserting. |
25
|
|
|
$response |
26
|
|
|
->toArray() |
27
|
|
|
->willReturn(['error' => null, 'data' => [/* ... */]]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
public function it_should_list_all_numbers_by_default(HttpClientInterface $client, ResponseInterface $response): void |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$client |
33
|
|
|
->request(CallTrackingsInterface::API, 'list', []) |
34
|
|
|
->shouldBeCalled() |
35
|
|
|
->willReturn($response); |
36
|
|
|
|
37
|
|
|
$this->getNumbers()->shouldBe(['error' => null, 'data' => [/* ... */]]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function it_should_list_all_numbers(HttpClientInterface $client, ResponseInterface $response): void |
41
|
|
|
{ |
42
|
|
|
$client |
43
|
|
|
->request(CallTrackingsInterface::API, 'list', ['tag1' => 'value']) |
44
|
|
|
->shouldBeCalled() |
45
|
|
|
->willReturn($response); |
46
|
|
|
|
47
|
|
|
$this |
48
|
|
|
->getNumbers(CallTrackingsInterface::NUMBERS_LIST, ['tag1' => 'value']) |
49
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function it_should_list_available_numbers(HttpClientInterface $client, ResponseInterface $response): void |
53
|
|
|
{ |
54
|
|
|
$client |
55
|
|
|
->request(CallTrackingsInterface::API, 'available', ['did_pattern' => '331%']) |
56
|
|
|
->shouldBeCalled() |
57
|
|
|
->willReturn($response); |
58
|
|
|
|
59
|
|
|
$this |
60
|
|
|
->getNumbers(CallTrackingsInterface::NUMBERS_AVAILABLE, ['did_pattern' => '331%']) |
61
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function it_should_list_deleted_numbers(HttpClientInterface $client, ResponseInterface $response): void |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$client |
67
|
|
|
->request(CallTrackingsInterface::API, 'deleted', []) |
68
|
|
|
->shouldBeCalled() |
69
|
|
|
->willReturn($response); |
70
|
|
|
|
71
|
|
|
$this |
72
|
|
|
->getNumbers(CallTrackingsInterface::NUMBERS_DELETED) |
73
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function it_should_add(HttpClientInterface $client, ResponseInterface $response): void |
77
|
|
|
{ |
78
|
|
|
$client |
79
|
|
|
->request(CallTrackingsInterface::API, 'add', [ |
80
|
|
|
'did' => '33176280XXX', |
81
|
|
|
'destination' => '33700XXYYZZ', |
82
|
|
|
'name' => 'The name', |
83
|
|
|
'tag1' => 'Tag 1', |
84
|
|
|
'tag2' => 'Tag 2', |
85
|
|
|
]) |
86
|
|
|
->shouldBeCalled() |
87
|
|
|
->willReturn($response); |
88
|
|
|
|
89
|
|
|
$this |
90
|
|
|
->add('33176280XXX', '33700XXYYZZ', 'The name', [ |
91
|
|
|
'tag1' => 'Tag 1', |
92
|
|
|
'tag2' => 'Tag 2', |
93
|
|
|
]) |
94
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
View Code Duplication |
public function it_should_modify(HttpClientInterface $client, ResponseInterface $response): void |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$client |
100
|
|
|
->request(CallTrackingsInterface::API, 'modify', [ |
101
|
|
|
'did' => '33176280XXX', |
102
|
|
|
'name' => 'My CallTracking', |
103
|
|
|
]) |
104
|
|
|
->shouldBeCalled() |
105
|
|
|
->willReturn($response); |
106
|
|
|
|
107
|
|
|
$this |
108
|
|
|
->modify('33176280XXX', ['name' => 'My CallTracking']) |
109
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function it_should_delete(HttpClientInterface $client, ResponseInterface $response): void |
113
|
|
|
{ |
114
|
|
|
$client |
115
|
|
|
->request(CallTrackingsInterface::API, 'delete', [ |
116
|
|
|
'did' => '33176280XXX', |
117
|
|
|
]) |
118
|
|
|
->shouldBeCalled() |
119
|
|
|
->willReturn($response); |
120
|
|
|
|
121
|
|
|
$this |
122
|
|
|
->delete('33176280XXX') |
123
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
View Code Duplication |
public function it_should_expires(HttpClientInterface $client, ResponseInterface $response): void |
|
|
|
|
127
|
|
|
{ |
128
|
|
|
$client |
129
|
|
|
->request(CallTrackingsInterface::API, 'modify', [ |
130
|
|
|
'did' => '33176280XXX', |
131
|
|
|
'stopdate' => '2020-11-19', |
132
|
|
|
]) |
133
|
|
|
->shouldBeCalled() |
134
|
|
|
->willReturn($response); |
135
|
|
|
|
136
|
|
|
$this |
137
|
|
|
->expires('33176280XXX', new \DateTime('2020-11-19')) |
138
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
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.