88use InterNations \Component \HttpMock \MockBuilder ;
99use InterNations \Component \HttpMock \Matcher \MatcherFactory ;
1010use Mcustiel \DependencyInjection \DependencyInjectionService ;
11+ use Codeception \Events ;
1112
1213class 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