|
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\Utils; |
|
20
|
|
|
|
|
21
|
|
|
use Mcustiel\Phiremock\Domain\Expectation; |
|
22
|
|
|
use Mcustiel\Phiremock\Domain\Response; |
|
23
|
|
|
use Mcustiel\Phiremock\Domain\Version; |
|
24
|
|
|
|
|
25
|
|
|
class ExpectationBuilder |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var ConditionsBuilder */ |
|
28
|
|
|
private $requestBuilder; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(ConditionsBuilder $requestBuilder) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->requestBuilder = $requestBuilder; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function then(ResponseBuilder $responseBuilder): Expectation |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->createExpectation($responseBuilder->build()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function thenRespond(int $statusCode, string $body): Expectation |
|
41
|
|
|
{ |
|
42
|
|
|
$response = HttpResponseBuilder::create($statusCode) |
|
43
|
|
|
->andBody($body) |
|
44
|
|
|
->build(); |
|
45
|
|
|
|
|
46
|
|
|
return $this->createExpectation($response); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
private function createExpectation(Response $response): Expectation |
|
50
|
|
|
{ |
|
51
|
|
|
$requestOptions = $this->requestBuilder->build(); |
|
52
|
|
|
|
|
53
|
|
|
return new Expectation( |
|
54
|
|
|
$requestOptions->getRequestConditions(), |
|
55
|
|
|
$response, |
|
56
|
|
|
$requestOptions->getScenarioName(), |
|
57
|
|
|
null, |
|
58
|
|
|
new Version('2') |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|