Test Failed
Push — master ( 813bd4...d0de6a )
by Mariano
10:52
created

Phiremock::_before()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
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
        'cleanup' => false,
35
    ];
36
37
    /**
38
     * @var \Mcustiel\Phiremock\Client\Phiremock
39
     */
40
    private $phiremock;
41
42
    public function _beforeSuite($settings = [])
43
    {
44
        $this->config = array_merge($this->config, $settings);
45
        $this->phiremock = new PhiremockClient($this->config['host'], $this->config['port']);
46
    }
47
48
    public function _before(TestInterface $test)
49
    {
50
        if ($this->config['cleanup']) {
51
            $this->haveInitialSetupRestored();
52
        }
53
        parent::_before($test);
54
    }
55
56
    public function expectARequestToRemoteServiceWithAResponse(Expectation $expectation)
57
    {
58
        $this->phiremock->createExpectation($expectation);
59
    }
60
61
    public function haveACleanSetupInRemoteService()
62
    {
63
        $this->phiremock->clearExpectations();
64
        $this->phiremock->resetRequestsCounter();
65
        $this->phiremock->resetScenarios();
66
    }
67
68
    public function haveInitialSetupRestored()
69
    {
70
        $this->phiremock->restoreExpectations();
0 ignored issues
show
Bug introduced by
The method restoreExpectations() does not seem to exist on object<Mcustiel\Phiremock\Client\Phiremock>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
    }
72
73
    public function dontExpectRequestsInRemoteService()
74
    {
75
        $this->phiremock->clearExpectations();
76
        $this->phiremock->resetRequestsCounter();
77
    }
78
79
    public function haveCleanScenariosInRemoteService()
80
    {
81
        $this->phiremock->resetScenarios();
82
    }
83
84
    public function didNotReceiveRequestsInRemoteService()
85
    {
86
        $this->phiremock->resetRequestsCounter();
87
    }
88
89
    public function seeRemoteServiceReceived($times, RequestBuilder $builder)
90
    {
91
        $requests = $this->phiremock->countExecutions($builder);
92
        if ($times !== $requests) {
93
            throw new \Exception(
94
                "Request expected to be executed $times times, called $requests times instead"
95
            );
96
        }
97
    }
98
}
99