diff --git a/.travis.yml b/.travis.yml index 93657e5..adc6274 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,3 +40,6 @@ install: script: - make test + +after_script: + - make prune diff --git a/docs/openapi.yml b/docs/openapi.yml index 59476c7..7ddec7c 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -62,12 +62,14 @@ components: allOf: # Inherit PutRunningSession - $ref: '#/components/schemas/PutRunningSession' - required: [ temperatureCelcius ] + required: [ temperatureCelcius, is_freezing ] properties: temperatureCelcius: type: number format: float example: 37.2 + is_freezing: + type: boolean RunningSessionId: type: integer diff --git a/src/Application/Command/RegisterRunningSessionHandler.php b/src/Application/Command/RegisterRunningSessionHandler.php index b959e03..0863c78 100644 --- a/src/Application/Command/RegisterRunningSessionHandler.php +++ b/src/Application/Command/RegisterRunningSessionHandler.php @@ -6,6 +6,7 @@ use App\Domain\RunningSession; use App\Domain\RunningSessionRepository; +use App\Domain\Temperature; use App\Domain\WeatherProvider; class RegisterRunningSessionHandler @@ -27,7 +28,7 @@ public function handle(RegisterRunningSession $command): RunningSession $command->getId(), $command->getDistance(), $command->getShoes(), - $currentTemperature + new Temperature($currentTemperature) ); $this->repository->add($session); diff --git a/src/Domain/RunningSession.php b/src/Domain/RunningSession.php index d8b11ac..3d42db4 100644 --- a/src/Domain/RunningSession.php +++ b/src/Domain/RunningSession.php @@ -9,14 +9,14 @@ class RunningSession private int $id; private float $distance; private string $shoes; - private float $metricTemperature; + private Temperature $temperature; - public function __construct(int $id, float $distance, string $shoes, float $metricTemperature) + public function __construct(int $id, float $distance, string $shoes, Temperature $temperature) { $this->id = $id; $this->distance = $distance; $this->shoes = $shoes; - $this->metricTemperature = $metricTemperature; + $this->temperature = $temperature; } public function getId(): int @@ -36,6 +36,11 @@ public function getShoes(): string public function getMetricTemperature(): float { - return $this->metricTemperature; + return $this->temperature->getMetricTemperature(); + } + + public function isFreezing(): bool + { + return $this->temperature->isFreezing(); } } diff --git a/src/Domain/Temperature.php b/src/Domain/Temperature.php new file mode 100644 index 0000000..648aa4a --- /dev/null +++ b/src/Domain/Temperature.php @@ -0,0 +1,35 @@ +metricTemperature = $metricTemperature; + } + + public function getMetricTemperature(): float + { + return $this->metricTemperature; + } + + public function isFreezing(): bool + { + return $this->metricTemperature < 0; + } +} diff --git a/src/Infrastructure/Symfony/Serializer/RunningSessionSerializer.php b/src/Infrastructure/Symfony/Serializer/RunningSessionSerializer.php index b571349..dc484b8 100644 --- a/src/Infrastructure/Symfony/Serializer/RunningSessionSerializer.php +++ b/src/Infrastructure/Symfony/Serializer/RunningSessionSerializer.php @@ -18,6 +18,7 @@ public function serialize(RunningSession $session): string 'distance' => $session->getDistance(), 'shoes' => $session->getShoes(), 'temperatureCelcius' => $session->getMetricTemperature(), + 'is_freezing' => $session->isFreezing(), ]; return json_encode($data, JSON_THROW_ON_ERROR); diff --git a/tests/Domain/RunningSessionFactory.php b/tests/Domain/RunningSessionFactory.php index 753f284..c26c12d 100644 --- a/tests/Domain/RunningSessionFactory.php +++ b/tests/Domain/RunningSessionFactory.php @@ -12,6 +12,6 @@ public static function create( string $shoes = 'shoes_value_not_used', float $metricTemperature = 98.76 ): RunningSession { - return new RunningSession($id, $distance, $shoes, $metricTemperature); + return new RunningSession($id, $distance, $shoes, new Temperature($metricTemperature)); } } diff --git a/tests/Domain/TemperatureTest.php b/tests/Domain/TemperatureTest.php new file mode 100644 index 0000000..4e61421 --- /dev/null +++ b/tests/Domain/TemperatureTest.php @@ -0,0 +1,34 @@ +isFreezing(); + + //Then + self::assertFalse($result, 'temperature should not be freezing'); + } + + public function testIsFreezingBelowZero() + { + //Given + $temperature = new Temperature(-12); + + //When + $result = $temperature->isFreezing(); + + //Then + self::assertTrue($result, 'temperature should be freezing'); + } +} diff --git a/tests/Infrastructure/Symfony/Serializer/RunningSessionSerializerTest.php b/tests/Infrastructure/Symfony/Serializer/RunningSessionSerializerTest.php index d910229..367b22d 100644 --- a/tests/Infrastructure/Symfony/Serializer/RunningSessionSerializerTest.php +++ b/tests/Infrastructure/Symfony/Serializer/RunningSessionSerializerTest.php @@ -29,7 +29,8 @@ public function testRunningSessionIsConvertedToJson() "id": 42, "distance": 5.5, "shoes": "Adadis Turbo2", - "temperatureCelcius": 37.2 + "temperatureCelcius": 37.2, + "is_freezing": false } EOD; self::assertJsonStringEqualsJsonString($expectedJson, $result);