initital commit
This commit is contained in:
95
tests/Functional/Controller/ForecastControllerTest.php
Normal file
95
tests/Functional/Controller/ForecastControllerTest.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Functional\Controller;
|
||||
|
||||
use App\Controller\ForecastController;
|
||||
use App\DTO\Edge\Response\Mapper\WeatherAtTimePointResponseMapper;
|
||||
use App\DTO\GEOPoint;
|
||||
use App\DTO\WeatherAtTimePoint;
|
||||
use App\Services\GeoPointResolverService;
|
||||
use App\Services\WeatherStorageReceiverInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class ForecastControllerTest extends KernelTestCase
|
||||
{
|
||||
public function testGetForecast(): void
|
||||
{
|
||||
list($weatherPoint, $controller) = $this->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<mixed>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
62
tests/Functional/Services/Storage/RedisStorageStoreTest.php
Normal file
62
tests/Functional/Services/Storage/RedisStorageStoreTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Functional\Services\Storage;
|
||||
|
||||
use App\DTO\GEOPoint;
|
||||
use App\DTO\WeatherAtTimePoint;
|
||||
use App\Services\Storage\RedisStorageStore;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class RedisStorageStoreTest extends KernelTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->bootKernel();
|
||||
}
|
||||
|
||||
public function testStoreAndReceiveData(): void
|
||||
{
|
||||
$dateTime = new \DateTime();
|
||||
$dateTime->setTime(0, 0);
|
||||
$tomorrowDateTime = \DateTime::createFromInterface($dateTime);
|
||||
$tomorrowDateTime->add(new \DateInterval('P1D'));
|
||||
$weatherAtTimePoints = [
|
||||
new WeatherAtTimePoint(
|
||||
$dateTime,
|
||||
10,
|
||||
-10,
|
||||
1
|
||||
),
|
||||
new WeatherAtTimePoint(
|
||||
$tomorrowDateTime,
|
||||
10,
|
||||
-10,
|
||||
1
|
||||
)
|
||||
];
|
||||
|
||||
/**
|
||||
* @var RedisStorageStore $redisStorage
|
||||
*/
|
||||
$redisStorage = $this->getContainer()->get(RedisStorageStore::class);
|
||||
$redisStorage->storeWeatherForPointByDay(
|
||||
new GEOPoint(
|
||||
24,
|
||||
24
|
||||
),
|
||||
$weatherAtTimePoints
|
||||
);
|
||||
$data = $redisStorage->receiveWeatherForPointByDay(
|
||||
new GEOPoint(
|
||||
24,
|
||||
24
|
||||
),
|
||||
$weatherAtTimePoints[0]->date,
|
||||
$weatherAtTimePoints[1]->date,
|
||||
);
|
||||
|
||||
$this->assertEquals($weatherAtTimePoints, $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user