1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Phiremock. |
4
|
|
|
* |
5
|
|
|
* Phiremock is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* Phiremock is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with Phiremock. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Mcustiel\Phiremock\Domain; |
20
|
|
|
|
21
|
|
|
use Mcustiel\Phiremock\Domain\Condition\Conditions\BodyCondition; |
22
|
|
|
use Mcustiel\Phiremock\Domain\Condition\Conditions\FormFieldConditionIterator; |
23
|
|
|
use Mcustiel\Phiremock\Domain\Condition\Conditions\HeaderConditionIterator; |
24
|
|
|
use Mcustiel\Phiremock\Domain\Condition\Conditions\JsonPathConditionIterator; |
25
|
|
|
use Mcustiel\Phiremock\Domain\Condition\Conditions\MethodCondition; |
26
|
|
|
use Mcustiel\Phiremock\Domain\Condition\Conditions\UrlCondition; |
27
|
|
|
use Mcustiel\Phiremock\Domain\Options\ScenarioState; |
28
|
|
|
|
29
|
|
|
class Conditions |
30
|
|
|
{ |
31
|
|
|
/** @var MethodCondition|null */ |
32
|
|
|
private $method; |
33
|
|
|
/** @var UrlCondition|null */ |
34
|
|
|
private $url; |
35
|
|
|
/** @var BodyCondition|null */ |
36
|
|
|
private $body; |
37
|
|
|
/** @var HeaderConditionIterator|null */ |
38
|
|
|
private $headers; |
39
|
|
|
/** @var FormFieldConditionIterator|null */ |
40
|
|
|
private $formFields; |
41
|
|
|
/** @var ScenarioState|null */ |
42
|
|
|
private $scenarioState; |
43
|
27 |
|
/** @var JsonPathConditionIterator|null */ |
44
|
|
|
private $jsonPath; |
45
|
|
|
|
46
|
|
|
public function __construct( |
47
|
|
|
?MethodCondition $method = null, |
48
|
|
|
?UrlCondition $url = null, |
49
|
|
|
?BodyCondition $body = null, |
50
|
|
|
?HeaderConditionIterator $headers = null, |
51
|
27 |
|
?FormFieldConditionIterator $formFields = null, |
52
|
27 |
|
?ScenarioState $scenarioState = null, |
53
|
27 |
|
?JsonPathConditionIterator $jsonPath = null |
54
|
27 |
|
) { |
55
|
27 |
|
$this->method = $method; |
56
|
27 |
|
$this->url = $url; |
57
|
27 |
|
$this->body = $body; |
58
|
|
|
$this->headers = $headers; |
59
|
|
|
$this->formFields = $formFields; |
60
|
|
|
$this->scenarioState = $scenarioState; |
61
|
|
|
$this->jsonPath = $jsonPath; |
62
|
|
|
} |
63
|
|
|
|
64
|
27 |
|
public function hasMethod(): bool |
65
|
|
|
{ |
66
|
27 |
|
return null !== $this->method; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getMethod(): ?MethodCondition |
70
|
|
|
{ |
71
|
|
|
return $this->method; |
72
|
|
|
} |
73
|
|
|
|
74
|
27 |
|
public function hasUrl(): bool |
75
|
|
|
{ |
76
|
27 |
|
return null !== $this->url; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getUrl(): ?UrlCondition |
80
|
|
|
{ |
81
|
|
|
return $this->url; |
82
|
|
|
} |
83
|
|
|
|
84
|
27 |
|
public function hasBody(): bool |
85
|
|
|
{ |
86
|
27 |
|
return null !== $this->body; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getBody(): ?BodyCondition |
90
|
|
|
{ |
91
|
|
|
return $this->body; |
92
|
|
|
} |
93
|
|
|
|
94
|
27 |
|
public function hasHeaders(): bool |
95
|
|
|
{ |
96
|
27 |
|
return null !== $this->headers && !$this->headers->isEmpty(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getHeaders(): ?HeaderConditionIterator |
100
|
|
|
{ |
101
|
|
|
return $this->headers; |
102
|
|
|
} |
103
|
|
|
|
104
|
27 |
|
public function hasFormFields(): bool |
105
|
|
|
{ |
106
|
27 |
|
return null !== $this->formFields && !$this->formFields->isEmpty(); |
107
|
|
|
} |
108
|
|
|
|
109
|
24 |
|
public function getFormFields(): ?FormFieldConditionIterator |
110
|
|
|
{ |
111
|
24 |
|
return $this->formFields; |
112
|
|
|
} |
113
|
|
|
|
114
|
9 |
|
public function hasScenarioState(): bool |
115
|
|
|
{ |
116
|
9 |
|
return $this->scenarioState !== null; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getScenarioState(): ?ScenarioState |
120
|
|
|
{ |
121
|
|
|
return $this->scenarioState; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function hasJsonPath(): bool |
125
|
|
|
{ |
126
|
|
|
return null !== $this->jsonPath; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function getJsonPath(): ?JsonPathConditionIterator |
130
|
|
|
{ |
131
|
|
|
return $this->jsonPath; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|