Skip to content

Commit 3e30798

Browse files
committed
Fixed problem with process that keeps running
1 parent 6e7ae7d commit 3e30798

File tree

3 files changed

+92
-8
lines changed

3 files changed

+92
-8
lines changed

README.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,78 @@
11
# phiremock-codeception-extension
2-
Codeception extension and module to make working with phiremock even easier.
2+
Codeception extension and module to make working with Phiremock even easier. It allows to start a Phiremock server specifically for the acceptance tests to run or to connect to an already running Phiremock server.
3+
4+
## Extension
5+
The extension provides an easy way to start a Phiremock server with configured host, port, debug mode and logs path.
6+
7+
### Configuration
8+
In codeception.yml you will need to enable Phiremock extension and configure it in a proper way:
9+
10+
```yaml
11+
extensions:
12+
enabled:
13+
- \Codeception\Extension\Phiremock
14+
config:
15+
\Codeception\Extension\Phiremock:
16+
listen: 127.0.0.1:18080 # defaults to 0.0.0.0:8086
17+
bin_path: ../vendor/bin # defaults to codeception_dir/../vendor/bin
18+
logs_path: /var/log/my_app/tests/logs # defaults to codeception's tests output dir
19+
debug: true # defaults to false
20+
```
21+
22+
## Module
23+
The module allows you to connect to a Phiremock server and to interact with it in a semantic way through the codeception actor in your tests.
24+
25+
### Configuration
26+
You need to enable Phiremock module in your suite's configuration file:
27+
28+
```yaml
29+
modules:
30+
enabled:
31+
- Phiremock:
32+
host: 127.0.0.1
33+
port: 18080
34+
```
35+
36+
### Use
37+
The module provides the following handy methods to communicate with Phiremock server:
38+
39+
#### expectARequestToRemoteServiceWithAResponse
40+
Allows you to setup an expectation in Phiremock, specifying the expected request and the response the server should give for it:
41+
42+
```php
43+
$I->expectARequestToRemoteServiceWithAResponse(
44+
Phiremock::on(
45+
A::getRequest()->andUrl(Is::equalTo('/some/url'))
46+
)->then(
47+
Respond::withStatusCode(203)->andBody('I am a response')
48+
)
49+
);
50+
```
51+
52+
### haveACleanSetupInRemoteService
53+
Cleans the server of all configured expectations, scenarios and requests history.
54+
55+
```php
56+
$I->haveACleanSetupInRemoteService();
57+
```
58+
59+
### dontExpectRequestsInRemoteService
60+
Cleans all previously configured expectations and requests history.
61+
62+
```php
63+
$I->dontExpectRequestsInRemoteService();
64+
```
65+
66+
### haveCleanScenariosInRemoteService
67+
Cleans the state of all scenarios (sets all of them to inital state).
68+
69+
```php
70+
$I->haveCleanScenariosInRemoteService();
71+
```
72+
73+
### seeRemoteServiceReceived
74+
Allows you to verify that the server received a request a given amount of times. This request could or not be previously set up as an expectation.
75+
76+
```php
77+
$I->seeRemoteServiceReceived(1, A::getRequest()->andUrl(Is::equalTo('/some/url')));
78+
```

src/Extension/Phiremock.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class Phiremock extends CodeceptionExtension
2727
public static $events = [];
2828

2929
protected $config = [
30-
'listen' => '0.0.0.0:8086'
30+
'listen' => '0.0.0.0:8086',
31+
'debug' => false
3132
];
3233

3334
/**
@@ -50,13 +51,20 @@ public function __construct(
5051
) {
5152
$this->config['bin_path'] = Config::projectDir() . '../vendor/bin';
5253
$this->config['logs_path'] = Config::logDir();
54+
5355
parent::__construct($config, $options);
5456

5557
$this->initProcess($process);
5658

5759
list($ip, $port) = explode(':', $this->config['listen']);
58-
$executablePath = $this->config['bin_path'];
59-
$this->process->start($ip, $port, $executablePath, $this->config['logs_path']);
60+
61+
$this->process->start(
62+
$ip,
63+
$port,
64+
$this->config['bin_path'],
65+
$this->config['logs_path'],
66+
$this->config['debug']
67+
);
6068
}
6169

6270
private function initProcess($process)

src/Extension/PhiremockProcess.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class PhiremockProcess
4747
*
4848
* @throws \Exception
4949
*/
50-
public function start($ip, $port, $path, $logsPath)
50+
public function start($ip, $port, $path, $logsPath, $debug)
5151
{
5252
$this->checkIfProcessIsRunning();
5353

5454
$this->process = proc_open(
55-
$this->getCommandPrefix() . "{$path}/phiremock -i {$ip} -p {$port}",
55+
$this->getCommandPrefix() . "{$path}/phiremock -i {$ip} -p {$port}" . ($debug? ' -d' : ''),
5656
$this->createProcessDescriptors($logsPath),
5757
$this->pipes,
5858
null,
@@ -130,8 +130,8 @@ public function stop()
130130
private function getCommandPrefix()
131131
{
132132
if (PHP_OS == 'WIN32' || PHP_OS == 'WINNT' || PHP_OS == 'Windows') {
133-
return 'exec ';
133+
return '';
134134
}
135-
return '';
135+
return 'exec ';
136136
}
137137
}

0 commit comments

Comments
 (0)