Passed
Push — master ( 48ca83...283ed8 )
by Mariano
01:54
created

haveCleanRequestsCounterInRemoteService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of phiremock-codeception-extension.
4
 *
5
 * phiremock-codeception-extension 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-codeception-extension 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-codeception-extension.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Codeception\Module;
20
21
use Codeception\Module as CodeceptionModule;
22
use Mcustiel\Phiremock\Client\Phiremock as PhiremockClient;
23
use Mcustiel\Phiremock\Client\Utils\RequestBuilder;
24
use Mcustiel\Phiremock\Domain\Expectation;
25
26
class Phiremock extends CodeceptionModule
27
{
28
    /**
29
     * @var array
30
     */
31
    protected $config = [
32
        'host' => 'localhost',
33
        'port' => '8086',
34
    ];
35
36
    /**
37
     * @var \Mcustiel\Phiremock\Client\Phiremock
38
     */
39
    private $phiremock;
40
41
    public function _beforeSuite($settings = [])
42
    {
43
        $this->config = array_merge($this->config, $settings);
44
        $this->phiremock = new PhiremockClient($this->config['host'], $this->config['port']);
45
    }
46
47
    public function expectARequestToRemoteServiceWithAResponse(Expectation $expectation)
48
    {
49
        $this->phiremock->createExpectation($expectation);
50
    }
51
52
    public function haveACleanSetupInRemoteService()
53
    {
54
        $this->phiremock->clearExpectations();
55
        $this->phiremock->resetRequestsCounter();
56
        $this->phiremock->resetScenarios();
57
    }
58
59
    public function dontExpectRequestsInRemoteService()
60
    {
61
        $this->phiremock->clearExpectations();
62
        $this->phiremock->resetRequestsCounter();
63
    }
64
65
    public function haveCleanScenariosInRemoteService()
66
    {
67
        $this->phiremock->resetScenarios();
68
    }
69
70
    public function haveCleanRequestsCounterInRemoteService()
71
    {
72
        $this->phiremock->resetRequestsCounter();
73
    }
74
75
    public function seeRemoteServiceReceived($times, RequestBuilder $builder)
76
    {
77
        $requests = $this->phiremock->countExecutions($builder);
78
        if ($times !== $requests) {
79
            throw new \Exception(
80
                "Request expected to be executed $times times, called $requests times instead"
81
            );
82
        }
83
    }
84
}
85