Skip to content

Commit fbae6a9

Browse files
authored
Merge pull request #5 from JiankangMai/master
fixed bug 'Address is already in use'
2 parents 5a51d13 + 6bcee1b commit fbae6a9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Extension/HttpMock.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use InterNations\Component\HttpMock\MockBuilder;
99
use InterNations\Component\HttpMock\Matcher\MatcherFactory;
1010
use Mcustiel\DependencyInjection\DependencyInjectionService;
11+
use Codeception\Events;
1112

1213
class HttpMock extends CodeceptionExtension
1314
{
@@ -18,6 +19,12 @@ class HttpMock extends CodeceptionExtension
1819
'port' => '28080',
1920
'host' => 'localhost'
2021
];
22+
23+
public static $events = [
24+
Events::SUITE_BEFORE => 'startHttpMock',
25+
Events::SUITE_AFTER => 'stopHttpMock'
26+
];
27+
2128
/**
2229
* @var \InterNations\Component\HttpMock\Server
2330
*/
@@ -31,15 +38,12 @@ public function __construct(array $config, array $options)
3138
{
3239
parent::__construct(array_merge($this->defaults, $config), $options);
3340
$this->diManager = new DependencyInjectionService();
34-
$this->startHttpMock();
35-
}
3641

37-
public function __destruct()
38-
{
39-
$this->stopHttpMock();
4042
}
4143

42-
private function startHttpMock()
44+
45+
46+
public function startHttpMock()
4347
{
4448
echo "Starting http mock server on {$this->config['host']}:{$this->config['port']}" . PHP_EOL;
4549
$this->server = new Server($this->config['port'], $this->config['host']);
@@ -63,7 +67,7 @@ function () {
6367
);
6468
}
6569

66-
private function stopHttpMock()
70+
public function stopHttpMock()
6771
{
6872
echo 'Stoping http mock server' . PHP_EOL;
6973
$this->server->stop();

0 commit comments

Comments
 (0)