1
1
<?php
2
2
3
3
use App \Infrastructure \Database \PostgresRunningSessionRepository ;
4
+ use App \Infrastructure \Database \PostgresRunningSessionRepositoryTest ;
5
+ use App \Infrastructure \Http \CurrentConditionDeserializerTest ;
6
+ use App \Infrastructure \Symfony \Serializer \RegisterRunningSessionDeserializerTest ;
4
7
use Behat \Behat \Context \Context ;
5
8
use Doctrine \DBAL \Connection ;
6
9
use PHPUnit \Framework \Assert ;
@@ -41,31 +44,7 @@ public function resetState()
41
44
public function currentTemperatureIs ($ temperature )
42
45
{
43
46
$ uri = '/currentconditions/v1/623?apikey= ' .$ this ->accuweatherApiKey ;
44
- $ body = <<<EOD
45
- [{
46
- "LocalObservationDateTime": "2020-10-17T17:50:00+02:00",
47
- "EpochTime": 1602949800,
48
- "WeatherText": "Mostly cloudy",
49
- "WeatherIcon": 6,
50
- "HasPrecipitation": false,
51
- "PrecipitationType": null,
52
- "IsDayTime": true,
53
- "Temperature": {
54
- "Metric": {
55
- "Value": $ temperature,
56
- "Unit": "C",
57
- "UnitType": 17
58
- },
59
- "Imperial": {
60
- "Value": 55.0,
61
- "Unit": "F",
62
- "UnitType": 18
63
- }
64
- },
65
- "MobileLink": "http://m.accuweather.com/en/fr/paris/623/current-weather/623?lang=en-us",
66
- "Link": "http://www.accuweather.com/en/fr/paris/623/current-weather/623?lang=en-us"
67
- }]
68
- EOD ;
47
+ $ body = CurrentConditionDeserializerTest::createBody ($ temperature );
69
48
70
49
$ this ->wireMock ->stubFor (WireMock::get (WireMock::urlEqualTo ($ uri ))
71
50
->willReturn (WireMock::aResponse ()
@@ -78,16 +57,10 @@ public function currentTemperatureIs($temperature)
78
57
*/
79
58
public function iRegisterARunningSessionWith ($ id , $ distance , $ shoes )
80
59
{
81
- $ request = Request::create ('/runningsessions/ ' .$ id , 'PUT ' , [], [], [], [], <<<EOD
82
- {
83
- "id": $ id,
84
- "distance": $ distance,
85
- "shoes": " $ shoes"
86
- }
87
- EOD
88
- );
60
+ $ body = RegisterRunningSessionDeserializerTest::createBody ($ id , $ distance , $ shoes );
61
+ $ request = Request::create ('/runningsessions/ ' .$ id , 'PUT ' , [], [], [], [], $ body );
89
62
90
- $ this ->response = $ this ->kernel ->handle ($ request ); //, HttpKernelInterface::MASTER_REQUEST, false);
63
+ $ this ->response = $ this ->kernel ->handle ($ request );
91
64
}
92
65
93
66
/**
@@ -96,15 +69,10 @@ public function iRegisterARunningSessionWith($id, $distance, $shoes)
96
69
public function aRunningSessionShouldBeAddedWith ($ id , $ distance , $ shoes , $ temperature )
97
70
{
98
71
Assert::assertEquals (201 , $ this ->response ->getStatusCode ());
99
-
100
- $ row = $ this ->dbal ->fetchAssociative (
101
- 'SELECT distance, shoes, temperature_celcius '
102
- .' FROM ' .PostgresRunningSessionRepository::TABLE_NAME
103
- .' WHERE ID = :id ' , [':id ' => $ id ]);
104
-
105
- Assert::assertIsArray ($ row , 'No session found with this id ' );
106
- Assert::assertEquals ($ distance , $ row ['distance ' ]);
107
- Assert::assertEquals ($ shoes , $ row ['shoes ' ]);
108
- Assert::assertEquals ($ temperature , $ row ['temperature_celcius ' ]);
72
+ PostgresRunningSessionRepositoryTest::thenRunningSessionTableShouldContain ($ this ->dbal , $ id , [
73
+ 'distance ' => $ distance ,
74
+ 'shoes ' => $ shoes ,
75
+ 'temperature_celcius ' => $ temperature ,
76
+ ]);
109
77
}
110
78
}
0 commit comments