ExpectationBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 1
f 0
dl 0
loc 34
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A then() 0 3 1
A thenRespond() 0 7 1
A createExpectation() 0 10 1
A __construct() 0 3 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\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