generated from dev/symfony-5-cli-template
Implementation a microservice architecture with JSON-RPC 2.0 communication between backend and frontend https://www.jsonrpc.org/specification
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.9 KiB
93 lines
2.9 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\api\Method\Weather;
|
|
|
|
use App\Tests\ApiTester;
|
|
use Codeception\Example;
|
|
use DateTime;
|
|
|
|
class GetByDateMethodCest
|
|
{
|
|
private ApiTester $tester;
|
|
|
|
public function _before(ApiTester $tester): void
|
|
{
|
|
$this->tester = $tester;
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataApply
|
|
*/
|
|
public function testApply(Example $example): void
|
|
{
|
|
$this->tester->sendPost('/json-rpc', $example['body']);
|
|
$this->tester->seeResponseIsJson();
|
|
$this->tester->seeResponseContainsJson($example['seeResponseContainsJson']);
|
|
$this->tester->seeResponseMatchesJsonType($example['seeResponseMatchesJsonType']);
|
|
}
|
|
|
|
protected function dataApply(): array
|
|
{
|
|
return [
|
|
[
|
|
'body' => sprintf(
|
|
'[{"jsonrpc": "2.0", "method": "weather.getByDate", "params": {"date": "%s"}, "id": 1}]',
|
|
(new DateTime())->format('Y-m-d')
|
|
),
|
|
'seeResponseContainsJson' => [
|
|
'jsonrpc' => '2.0',
|
|
'id' => 1,
|
|
],
|
|
'seeResponseMatchesJsonType' => [
|
|
'jsonrpc' => 'string',
|
|
'id' => 'integer',
|
|
],
|
|
],
|
|
[
|
|
'body' => sprintf(
|
|
'[{"jsonrpc": "2.0", "method": "weather.getByDate", "params": {"date": "%s"}, "id": 1}]',
|
|
'9999-01-01'
|
|
),
|
|
'seeResponseContainsJson' => [
|
|
'jsonrpc' => '2.0',
|
|
'id' => 1,
|
|
'result' => [],
|
|
],
|
|
'seeResponseMatchesJsonType' => [
|
|
'jsonrpc' => 'string',
|
|
'id' => 'integer',
|
|
'result' => 'array',
|
|
],
|
|
],
|
|
[
|
|
'body' => sprintf(
|
|
'[{"jsonrpc": "2.0", "method": "weather.getByDate", "params": {"date": "%s"}, "id": 1}]',
|
|
'01-01-9999'
|
|
),
|
|
'seeResponseContainsJson' => [
|
|
'jsonrpc' => '2.0',
|
|
'id' => 1,
|
|
],
|
|
'seeResponseMatchesJsonType' => [
|
|
'jsonrpc' => 'string',
|
|
'id' => 'integer',
|
|
'error' => 'array',
|
|
],
|
|
],
|
|
[
|
|
'body' => '[{"jsonrpc": "2.0", "method": "weather.getByDate", "params": [], "id": 1}]',
|
|
'seeResponseContainsJson' => [
|
|
'jsonrpc' => '2.0',
|
|
'id' => 1,
|
|
],
|
|
'seeResponseMatchesJsonType' => [
|
|
'jsonrpc' => 'string',
|
|
'id' => 'integer',
|
|
'error' => 'array',
|
|
],
|
|
],
|
|
];
|
|
}
|
|
}
|