Skip to content

Commit c726528

Browse files
committed
add wiremock as a service in test environment
1 parent 19e7670 commit c726528

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ APP_SECRET='$ecretf0rt3st'
44
SYMFONY_DEPRECATIONS_HELPER=999999
55

66
ACCUWEATHER_API_KEY='accuweatherTestKey'
7+
# See docker-compose.yml
78
ACCUWEATHER_BASE_URI='http://wiremock:8080/'
89

910
###> doctrine/doctrine-bundle ###

behat.yml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ default:
55
- FeatureContext:
66
kernel: '@kernel'
77
dbal: '@doctrine.dbal.default_connection'
8-
accuweatherApiKey: '%%accuweather.apikey%%'
8+
wireMock: '@WireMock\Client\WireMock'
99

1010
extensions:
1111
Behat\Symfony2Extension:

config/packages/test/services.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
# default configuration for services in *this* file
3+
_defaults:
4+
public: true
5+
6+
WireMock\Client\WireMock:
7+
factory: ['WireMock\Client\WireMock', 'create']
8+
# See docker-compose.yml
9+
arguments: ['wiremock', '8080']

config/services.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# Put parameters here that don't need to change on each machine where the app is deployed
55
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
66
parameters:
7-
# defined as parameter to pass it to behat.yml.dist
8-
accuweather.apikey: '%env(ACCUWEATHER_API_KEY)%'
97

108
services:
119
# default configuration for services in *this* file
@@ -37,4 +35,4 @@ services:
3735
App\Infrastructure\Http\RestWeatherProvider:
3836
arguments:
3937
$client: '@guzzle.accuweather'
40-
$apiKey: '%accuweather.apikey%'
38+
$apiKey: '%env(ACCUWEATHER_API_KEY)%'

features/bootstrap/FeatureContext.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,19 @@
1111

1212
class FeatureContext implements Context
1313
{
14-
// See docker-compose.yml
15-
private const WIREMOCK_HOST = 'wiremock';
16-
private const WIREMOCK_PORT = '8080';
14+
// See .env.test
15+
private const ACCUWEATHER_API_KEY = 'accuweatherTestKey';
1716

1817
private KernelInterface $kernel;
1918
private Connection $dbal;
20-
private string $accuweatherApiKey;
2119
private WireMock $wireMock;
2220
private ?Response $response;
2321

24-
public function __construct(KernelInterface $kernel, Connection $dbal, string $accuweatherApiKey)
22+
public function __construct(KernelInterface $kernel, Connection $dbal, WireMock $wireMock)
2523
{
2624
$this->kernel = $kernel;
27-
$this->wireMock = WireMock::create(self::WIREMOCK_HOST, self::WIREMOCK_PORT);
25+
$this->wireMock = $wireMock;
2826
Assert::assertTrue($this->wireMock->isAlive(), 'Wiremock should be alive');
29-
$this->accuweatherApiKey = $accuweatherApiKey;
3027
$this->dbal = $dbal;
3128
}
3229

@@ -44,7 +41,7 @@ public function resetState()
4441
*/
4542
public function currentTemperatureIs($temperature)
4643
{
47-
$uri = '/currentconditions/v1/623?apikey='.$this->accuweatherApiKey;
44+
$uri = '/currentconditions/v1/623?apikey='.self::ACCUWEATHER_API_KEY;
4845
$body = <<<EOD
4946
[{
5047
"LocalObservationDateTime": "2020-10-17T17:50:00+02:00",

0 commit comments

Comments
 (0)