1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Testing; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2020 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Psr\Http\Message\ResponseInterface; |
22
|
|
|
|
23
|
|
|
/** @noinspection PhpTooManyParametersInspection |
24
|
|
|
* @package Limoncello\Testing |
25
|
|
|
* |
26
|
|
|
* @@codingStandardsIgnoreLine |
27
|
|
|
* @method ResponseInterface call(string $method, string $uri, array $queryParams = [], array $parsedBody = [], array $headers = [], array $cookies = [], array $files = [], array $server = [], string $messageBody = 'php://input') |
28
|
|
|
*/ |
29
|
|
|
trait HttpCallsTrait |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @param string $uri |
33
|
|
|
* @param array $queryParams |
34
|
|
|
* @param array $headers |
35
|
|
|
* @param array $cookies |
36
|
|
|
* |
37
|
|
|
* @return ResponseInterface |
38
|
|
|
*/ |
39
|
1 |
|
protected function get( |
40
|
|
|
string $uri, |
41
|
|
|
array $queryParams = [], |
42
|
|
|
array $headers = [], |
43
|
|
|
array $cookies = [] |
44
|
|
|
): ResponseInterface { |
45
|
1 |
|
return $this->call('GET', $uri, $queryParams, [], $headers, $cookies); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $uri |
50
|
|
|
* @param array $data |
51
|
|
|
* @param array $headers |
52
|
|
|
* @param array $cookies |
53
|
|
|
* @param array $files |
54
|
|
|
* |
55
|
|
|
* @return ResponseInterface |
56
|
|
|
*/ |
57
|
1 |
View Code Duplication |
protected function post( |
|
|
|
|
58
|
|
|
string $uri, |
59
|
|
|
array $data = [], |
60
|
|
|
array $headers = [], |
61
|
|
|
array $cookies = [], |
62
|
|
|
array $files = [] |
63
|
|
|
): ResponseInterface { |
64
|
1 |
|
$headers['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; |
65
|
|
|
|
66
|
1 |
|
return $this->call('POST', $uri, [], $data, $headers, $cookies, $files); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $uri |
71
|
|
|
* @param array $data |
72
|
|
|
* @param array $headers |
73
|
|
|
* @param array $cookies |
74
|
|
|
* @param array $files |
75
|
|
|
* |
76
|
|
|
* @return ResponseInterface |
77
|
|
|
*/ |
78
|
1 |
View Code Duplication |
protected function put( |
|
|
|
|
79
|
|
|
string $uri, |
80
|
|
|
array $data = [], |
81
|
|
|
array $headers = [], |
82
|
|
|
array $cookies = [], |
83
|
|
|
array $files = [] |
84
|
|
|
): ResponseInterface { |
85
|
1 |
|
$headers['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; |
86
|
|
|
|
87
|
1 |
|
return $this->call('PUT', $uri, [], $data, $headers, $cookies, $files); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $uri |
92
|
|
|
* @param array $data |
93
|
|
|
* @param array $headers |
94
|
|
|
* @param array $cookies |
95
|
|
|
* @param array $files |
96
|
|
|
* |
97
|
|
|
* @return ResponseInterface |
98
|
|
|
*/ |
99
|
1 |
View Code Duplication |
protected function patch( |
|
|
|
|
100
|
|
|
string $uri, |
101
|
|
|
array $data = [], |
102
|
|
|
array $headers = [], |
103
|
|
|
array $cookies = [], |
104
|
|
|
array $files = [] |
105
|
|
|
): ResponseInterface { |
106
|
1 |
|
$headers['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; |
107
|
|
|
|
108
|
1 |
|
return $this->call('PATCH', $uri, [], $data, $headers, $cookies, $files); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string $uri |
113
|
|
|
* @param array $data |
114
|
|
|
* @param array $headers |
115
|
|
|
* @param array $cookies |
116
|
|
|
* |
117
|
|
|
* @return ResponseInterface |
118
|
|
|
*/ |
119
|
1 |
|
protected function delete( |
120
|
|
|
string $uri, |
121
|
|
|
array $data = [], |
122
|
|
|
array $headers = [], |
123
|
|
|
array $cookies = [] |
124
|
|
|
): ResponseInterface { |
125
|
1 |
|
return $this->call('DELETE', $uri, [], $data, $headers, $cookies); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
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.