1
1
<?php
2
2
3
- use App \Infrastructure \ Database \ PostgresRunningSessionRepository ;
4
- use App \Infrastructure \ Database \ PostgresRunningSessionRepositoryTest ;
5
- use App \Infrastructure \ Http \ CurrentConditionDeserializerTest ;
3
+ use App \Domain \ RunningSessionFactory ;
4
+ use App \Domain \ RunningSessionRepository ;
5
+ use App \Domain \ WeatherProvider ;
6
6
use App \Infrastructure \Symfony \Serializer \RegisterRunningSessionDeserializerTest ;
7
7
use Behat \Behat \Context \Context ;
8
- use Doctrine \DBAL \Connection ;
9
8
use PHPUnit \Framework \Assert ;
9
+ use Prophecy \Prophecy \ObjectProphecy ;
10
10
use Symfony \Component \HttpFoundation \Request ;
11
11
use Symfony \Component \HttpFoundation \Response ;
12
12
use Symfony \Component \HttpKernel \KernelInterface ;
13
- use WireMock \Client \WireMock ;
14
13
15
14
class FeatureContext implements Context
16
15
{
16
+ use BehatProphecyTrait;
17
+
17
18
private KernelInterface $ kernel ;
18
- private Connection $ dbal ;
19
- private WireMock $ wireMock ;
20
19
private ?Response $ response ;
21
- private string $ accuweatherApiKey ;
20
+ /** @var ObjectProphecy|WeatherProvider */
21
+ private $ weatherProvider ;
22
+ /** @var ObjectProphecy|RunningSessionRepository */
23
+ private $ runningSessionRepository ;
22
24
23
- public function __construct (KernelInterface $ kernel, Connection $ dbal , WireMock $ wireMock , string $ accuweatherApiKey )
25
+ public function __construct (KernelInterface $ kernel )
24
26
{
25
27
$ this ->kernel = $ kernel ;
26
- $ this ->wireMock = $ wireMock ;
27
- Assert::assertTrue ($ this ->wireMock ->isAlive (), 'Wiremock should be alive ' );
28
- $ this ->dbal = $ dbal ;
29
- $ this ->accuweatherApiKey = $ accuweatherApiKey ;
30
- }
31
28
32
- /**
33
- * @BeforeScenario
34
- */
35
- public function resetState ()
36
- {
37
- $ this ->wireMock ->reset ();
38
- $ this ->dbal ->executeStatement ('TRUNCATE TABLE ' .PostgresRunningSessionRepository::TABLE_NAME );
29
+ $ this ->weatherProvider = $ this ->prophesize (WeatherProvider::class);
30
+ $ kernel ->getContainer ()->set (WeatherProvider::class, $ this ->weatherProvider ->reveal ());
31
+
32
+ $ this ->runningSessionRepository = $ this ->prophesize (RunningSessionRepository::class);
33
+ $ kernel ->getContainer ()->set (RunningSessionRepository::class, $ this ->runningSessionRepository ->reveal ());
39
34
}
40
35
41
36
/**
42
37
* @Given current temperature is :temperature celcius degrees
43
38
*/
44
39
public function currentTemperatureIs ($ temperature )
45
40
{
46
- $ uri = '/currentconditions/v1/623?apikey= ' .$ this ->accuweatherApiKey ;
47
- $ body = CurrentConditionDeserializerTest::createBody ($ temperature );
48
-
49
- $ this ->wireMock ->stubFor (WireMock::get (WireMock::urlEqualTo ($ uri ))
50
- ->willReturn (WireMock::aResponse ()
51
- ->withHeader ('Content-Type ' , 'application/json ' )
52
- ->withBody ($ body )));
41
+ $ this ->weatherProvider
42
+ ->getCurrentCelciusTemperature ()
43
+ ->willReturn ($ temperature );
53
44
}
54
45
55
46
/**
@@ -69,10 +60,14 @@ public function iRegisterARunningSessionWith($id, $distance, $shoes)
69
60
public function aRunningSessionShouldBeAddedWith ($ id , $ distance , $ shoes , $ temperature )
70
61
{
71
62
Assert::assertEquals (201 , $ this ->response ->getStatusCode ());
72
- PostgresRunningSessionRepositoryTest::thenRunningSessionTableShouldContain ($ this ->dbal , $ id , [
73
- 'distance ' => $ distance ,
74
- 'shoes ' => $ shoes ,
75
- 'temperature_celcius ' => $ temperature ,
76
- ]);
63
+
64
+ $ this ->runningSessionRepository
65
+ ->add (RunningSessionFactory::create (
66
+ $ id ,
67
+ $ distance ,
68
+ $ shoes ,
69
+ $ temperature
70
+ ))
71
+ ->shouldHaveBeenCalled ();
77
72
}
78
73
}
0 commit comments