Skip to content

Commit fe23a6f

Browse files
author
Mariano Custiel
committed
First running version
1 parent f46ea5c commit fe23a6f

File tree

11 files changed

+478
-23
lines changed

11 files changed

+478
-23
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"name" : "mcustiel/test-phiremock",
1414
"type" : "project",
1515
"require" : {
16-
"php" : ">=5.6",
17-
"mcustiel/phiremock": "dev-master",
18-
"codeception/codeception" : ">=2.1"
16+
"php" : ">=5.5",
17+
"mcustiel/phiremock": "^0.8.2",
18+
"codeception/codeception" : "^2.1"
1919
},
2020
"minimum-stability": "dev"
21-
}
21+
}

src/Extension/PhiremockProcess.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function start($ip, $port, $path, $logsPath)
5252
$this->checkIfProcessIsRunning();
5353

5454
$this->process = proc_open(
55-
$this->getCommandPrefix() . "php {$path}/phiremock -i {$ip} -p {$port}",
55+
$this->getCommandPrefix() . "{$path}/phiremock -i {$ip} -p {$port}",
5656
$this->createProcessDescriptors($logsPath),
5757
$this->pipes,
5858
null,
@@ -118,6 +118,7 @@ public function stop()
118118
fclose($pipe);
119119
}
120120
}
121+
proc_terminate($this->process, SIGKILL);
121122
proc_close($this->process);
122123
unset($this->process);
123124
}

src/Module/Phiremock.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,40 @@ class Phiremock extends CodeceptionModule
1616

1717
public function _beforeSuite($settings = [])
1818
{
19+
$this->config = array_merge($this->config, $settings);
1920
$this->phiremock = new PhiremockClient($this->config['host'], $this->config['port']);
2021
}
2122

22-
public function expectRequest(Expectation $expectation)
23+
public function expectARequestToRemoteServiceWithAResponse(Expectation $expectation)
2324
{
25+
$this->phiremock->createExpectation($expectation);
26+
}
27+
28+
public function haveACleanSetupInRemoteService()
29+
{
30+
$this->phiremock->clearExpectations();
31+
$this->phiremock->resetRequestsCounter();
32+
$this->phiremock->resetScenarios();
33+
}
2434

35+
public function dontExpectRequestsInRemoteService()
36+
{
37+
$this->phiremock->clearExpectations();
38+
$this->phiremock->resetRequestsCounter();
39+
}
40+
41+
public function haveCleanScenariosInRemoteService()
42+
{
43+
$this->phiremock->resetScenarios();
2544
}
2645

27-
public function verifyExecutions(RequestBuilder $builder)
46+
public function seeRemoteServiceReceived($times, RequestBuilder $builder)
2847
{
29-
$expectation = PhiremockClient::on($builder)->then(Respond::withStatusCode(200));
48+
$requests = $this->phiremock->countExecutions($builder);
49+
if ($times != $requests) {
50+
throw new \Exception(
51+
"Request expected to be executed $times times, called $requests times instead"
52+
);
53+
}
3054
}
3155
}

tests/_bootstrap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// This is global bootstrap for autoloading

tests/codeception.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@ settings:
1111
memory_limit: 1024M
1212
extensions:
1313
enabled:
14-
- Codeception\Extension\RunFailed
15-
- Codeception\Extension\Phiremock
14+
- \Codeception\Extension\RunFailed
15+
- \Codeception\Extension\Phiremock
1616
config:
17-
Codeception\Extension\Phiremock:
17+
\Codeception\Extension\Phiremock:
1818
listen: 0.0.0.0:18080
19-
modules:
20-
enabled:
21-
- Phiremock
22-
config:
23-
Phiremock:
24-
host: 127.0.0.1
25-
port: 18080
2619

tests/tests/_output/phiremock.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Server running at http://0.0.0.0:18080
1+
[2016-03-04 15:00:07] stdoutLogger.INFO: Starting Phiremock... [] []
2+
[2016-03-04 15:00:07] stdoutLogger.INFO: Phiremock http server listening on 0.0.0.0:18080 [] []
3+
[2016-03-04 15:00:12] stdoutLogger.INFO: Request received: GET: http://localhost/some/url || [] []

0 commit comments

Comments
 (0)