1 | <?php |
||
27 | class Phiremock extends CodeceptionModule |
||
28 | { |
||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $config = [ |
||
33 | 'host' => 'localhost', |
||
34 | 'port' => '8086', |
||
35 | 'resetBeforeEachTest' => false, |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * @var \Mcustiel\Phiremock\Client\Phiremock |
||
40 | */ |
||
41 | private $phiremock; |
||
42 | |||
43 | public function _beforeSuite($settings = []) |
||
44 | { |
||
45 | $this->config = array_merge($this->config, $settings); |
||
46 | $this->phiremock = new PhiremockClient($this->config['host'], $this->config['port']); |
||
47 | } |
||
48 | |||
49 | public function _before(TestInterface $test) |
||
50 | { |
||
51 | if ($this->config['resetBeforeEachTest']) { |
||
52 | $this->haveACleanSetupInRemoteService(); |
||
53 | } |
||
54 | parent::_before($test); |
||
55 | } |
||
56 | |||
57 | public function expectARequestToRemoteServiceWithAResponse(Expectation $expectation) |
||
58 | { |
||
59 | $this->phiremock->createExpectation($expectation); |
||
60 | } |
||
61 | |||
62 | public function haveACleanSetupInRemoteService() |
||
63 | { |
||
64 | $this->phiremock->reset(); |
||
65 | } |
||
66 | |||
67 | public function dontExpectRequestsInRemoteService() |
||
68 | { |
||
69 | $this->phiremock->clearExpectations(); |
||
70 | $this->phiremock->resetRequestsCounter(); |
||
71 | } |
||
72 | |||
73 | public function haveCleanScenariosInRemoteService() |
||
74 | { |
||
75 | $this->phiremock->resetScenarios(); |
||
76 | } |
||
77 | |||
78 | public function didNotReceiveRequestsInRemoteService() |
||
79 | { |
||
80 | $this->phiremock->resetRequestsCounter(); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param int $times |
||
85 | * @param RequestBuilder $builder |
||
86 | * |
||
87 | * @throws \Exception |
||
88 | */ |
||
89 | public function seeRemoteServiceReceived($times, RequestBuilder $builder) |
||
98 | } |
||
99 |