Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit d68faec

Browse files
committed
Now using php-simple-di to save the connection
1 parent c6c1890 commit d68faec

File tree

5 files changed

+364
-23
lines changed

5 files changed

+364
-23
lines changed

composer.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"mock",
88
"mock external services"
99
],
10-
"authors" : [{
11-
"name" : "Mariano Custiel",
12-
"email" : "jmcustiel@gmail.com",
13-
"homepage" : "https://github.com/mcustiel",
14-
"role" : "Developer"
15-
}
16-
],
10+
"authors" : [{
11+
"name" : "Mariano Custiel",
12+
"email" : "jmcustiel@gmail.com",
13+
"homepage" : "https://github.com/mcustiel",
14+
"role" : "Developer"
15+
}
16+
],
1717
"autoload" : {
1818
"psr-4" : {
1919
"Codeception\\" : "src"
@@ -26,7 +26,8 @@
2626
"require" : {
2727
"php" : ">=5.4",
2828
"codeception/codeception" : "~2.1.0",
29-
"wiremock-php/wiremock-php" : ">=1.43"
29+
"wiremock-php/wiremock-php" : ">=1.43",
30+
"mcustiel/php-simple-di" : ">=1.2.0"
3031
},
3132
"require-dev" : {
3233
"phing/phing" : ">=2.12.0",

src/Extension/WireMock.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use Codeception\Platform\Extension as CodeceptionExtension;
2121
use WireMock\Client\WireMock as WireMockClient;
22+
use Mcustiel\DependencyInjection\DependencyContainer;
2223

2324
/**
2425
* Codeception Extension for WireMock
@@ -78,7 +79,12 @@ public function __construct(
7879
$host = 'localhost';
7980
sleep($this->config['start-delay']);
8081
}
81-
WireMockConnection::setConnection(WireMockClient::create($host, $this->config['port']));
82+
DependencyContainer::getInstance()->add(
83+
'wiremockConnection',
84+
function() use ($host) {
85+
return WireMockClient::create($host, $this->config['port']);
86+
}
87+
);
8288
}
8389

8490
private function initWireMockProcess($process)
@@ -113,8 +119,9 @@ private function initWireMockArgumentsManager($argumentsManager)
113119
*/
114120
public function __destruct()
115121
{
116-
if (WireMockConnection::get()->isAlive()) {
117-
WireMockConnection::get()->shutdownServer();
122+
$connection = DependencyContainer::getInstance()->get('wiremockConnection');
123+
if ($connection->isAlive()) {
124+
$connection->shutdownServer();
118125
}
119126
$this->process->stop();
120127
}

src/Module/WireMock.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Codeception\Extension\WireMockConnection;
2323
use WireMock\Client\MappingBuilder;
2424
use WireMock\Client\RequestPatternBuilder;
25+
use Mcustiel\DependencyInjection\DependencyContainer;
2526

2627
class WireMock extends CodeceptionModule
2728
{
@@ -37,7 +38,7 @@ class WireMock extends CodeceptionModule
3738
public function _before(TestCase $testCase)
3839
{
3940
parent::_before($testCase);
40-
$this->wireMock = WireMockConnection::get();
41+
$this->wireMock = DependencyContainer::getInstance()->get('wiremockConnection');
4142
}
4243

4344
public function cleanAllPreviousRequestsToWireMock()

0 commit comments

Comments
 (0)