Passed
Push — master ( 431a99...5fb423 )
by Mariano
04:28
created

onDeleteRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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\Client;
20
21
use Mcustiel\Phiremock\Client\Utils\A;
22
use Mcustiel\Phiremock\Client\Utils\ConditionsBuilder;
23
use Mcustiel\Phiremock\Client\Utils\ExpectationBuilder;
24
use Mcustiel\Phiremock\Client\Utils\HttpResponseBuilder;
25
use Mcustiel\Phiremock\Client\Utils\Is;
26
use Mcustiel\Phiremock\Client\Utils\Proxy;
27
use Mcustiel\Phiremock\Client\Utils\ProxyResponseBuilder;
28
use Mcustiel\Phiremock\Client\Utils\Respond;
29
use Mcustiel\Phiremock\Domain\Condition\Matchers\CaseInsensitiveEquals;
30
use Mcustiel\Phiremock\Domain\Condition\Matchers\Contains;
31
use Mcustiel\Phiremock\Domain\Condition\Matchers\Equals;
32
use Mcustiel\Phiremock\Domain\Condition\Matchers\JsonEquals;
33
use Mcustiel\Phiremock\Domain\Condition\Matchers\RegExp;
34
35
// ConditionBuilder creators
36
37
function request(): ConditionsBuilder
38
{
39
    return new ConditionsBuilder();
40
}
41
42
function getRequest(string $url = null): ConditionsBuilder
43
{
44
    $builder = A::getRequest();
45
    if ($url) {
46
        $builder->andUrl(isEqualTo($url));
47
    }
48
    return $builder;
49
}
50
51
function postRequest(): ConditionsBuilder
52
{
53
    return A::postRequest();
54
}
55
56
function putRequest(): ConditionsBuilder
57
{
58
    return A::putRequest();
59
}
60
61
function deleteRequest(string $url = null): ConditionsBuilder
62
{
63
    $builder = A::deleteRequest();
64
    if ($url) {
65
        $builder->andUrl(isEqualTo($url));
66
    }
67
    return $builder;
68
}
69
70
function patchRequest(): ConditionsBuilder
71
{
72
    return A::patchRequest();
73
}
74
75
function headRequest(): ConditionsBuilder
76
{
77
    return A::headRequest();
78
}
79
80
function optionsRequest(): ConditionsBuilder
81
{
82
    return A::optionsRequest();
83
}
84
85
function fetchRequest(): ConditionsBuilder
86
{
87
    return A::fetchRequest();
88
}
89
90
function linkRequest(): ConditionsBuilder
91
{
92
    return A::linkRequest();
93
}
94
95
// Matcher creators
96
97
function isEqualTo($value): Equals
98
{
99
    return Is::equalTo($value);
100
}
101
102
function isSameStringAs(string $value): CaseInsensitiveEquals
103
{
104
    return Is::sameStringAs($value);
105
}
106
107
function matchesRegex(string $value): RegExp
108
{
109
    return Is::matching($value);
110
}
111
112
function isSameJsonAs($value): JsonEquals
113
{
114
    return Is::sameJsonObjectAs($value);
115
}
116
117
function contains(string $value): Contains
118
{
119
    return Is::containing($value);
120
}
121
122
// ResponseBuilder creators
123
124
function respond(int $statusCode): HttpResponseBuilder
125
{
126
    return Respond::withStatusCode($statusCode);
127
}
128
129
function proxyTo(string $url): ProxyResponseBuilder
130
{
131
    return Proxy::to($url);
132
}
133
134
// ExpectationBuilder creator
135
136
function on(ConditionsBuilder $builder): ExpectationBuilder
137
{
138
    return Phiremock::on($builder);
139
}
140
141
function onGetRequest(string $url = null): ExpectationBuilder
142
{
143
    return Phiremock::on(getRequest($url));
144
}
145
146
function onDeleteRequest(string $url = null): ExpectationBuilder
147
{
148
    return Phiremock::on(deleteRequest($url));
149
}
150