createController('Prague', false, true); /** * @var WeatherAtTimePointResponseMapper $timePointResponseMapper */ $timePointResponseMapper = $this->getContainer()->get(WeatherAtTimePointResponseMapper::class); $expectedResponse = new \stdClass(); $expectedResponse->city = 'Prague'; $expectedResponse->temperature = $timePointResponseMapper->fromWeatherAtTimePointsDateAsYYYYmmdd($weatherPoint); $result = $controller->getForecast('Prague'); $this->assertEquals($result->getStatusCode(), 200); $this->assertEquals( json_encode($expectedResponse), $result->getContent() ); } public function testGetInvalidCity(): void { list($_, $controller) = $this->createController('Atlantis', true, true); $result = $controller->getForecast('Atlantis'); $this->assertEquals($result->getStatusCode(), 404); } public function testDataNotFound(): void { list($_, $controller) = $this->createController('Prague', false, false); $result = $controller->getForecast('Prague'); $this->assertEquals($result->getStatusCode(), 404); } /** * @return array */ public function createController(string $cityName, bool $invalidCity, bool $createWeatherPoints): array { $weatherPoint = match ($createWeatherPoints) { true => [ new WeatherAtTimePoint( new \DateTime(), 10, 10, 10 ), new WeatherAtTimePoint( new \DateTime(), 9, 9, 9 ), ], false => [] }; $point = new GEOPoint( 22, 22 ); $weatherStorageReceiverMock = \Mockery::mock(WeatherStorageReceiverInterface::class); // @phpstan-ignore-next-line method.notFound $weatherStorageReceiverMock->shouldReceive('receiveWeatherForPointByDay')->with($point, \Mockery::any(), \Mockery::any()) ->andReturn( $weatherPoint ); $geoPointResolverMock = \Mockery::mock(GeoPointResolverService::class); // @phpstan-ignore-next-line method.notFound $geoPointResolverMock->shouldReceive('getGeoPointFromCityName')->with($cityName)->andReturn( $invalidCity === true ? null : $point ); $this->getContainer()->set(WeatherStorageReceiverInterface::class, $weatherStorageReceiverMock); $this->getContainer()->set(GeoPointResolverService::class, $geoPointResolverMock); $controller = $this->getContainer()->get(ForecastController::class); return array($weatherPoint, $controller); } }