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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

135 lines
3.0 KiB

<?php
declare(strict_types=1);
namespace App\Tests\unit\Entity;
use App\Entity\History;
use App\Tests\UnitTester;
use Codeception\Test\Unit;
use DateTimeInterface;
use Faker\Factory;
use ReflectionException;
/**
* @internal
*/
class HistoryTest extends Unit
{
protected UnitTester $tester;
/**
* @dataProvider dataGetId
*
* @throws ReflectionException
* @test
*/
public function getId(?int $id): void
{
$entity = new History();
$property = $this->tester->getClassProperty($entity, 'id');
$property->setValue($entity, $id);
$result = $entity->getId();
self::assertEquals($id, $result);
}
public static function dataGetId(): array
{
$faker = Factory::create('en_EN');
return [
['id' => null],
['id' => $faker->randomNumber()],
];
}
/**
* @dataProvider dataGetTemp
*
* @throws ReflectionException
* @test
*/
public function getTemp(?float $temp): void
{
$entity = new History();
$property = $this->tester->getClassProperty($entity, 'temp');
$property->setValue($entity, $temp);
$result = $entity->getTemp();
self::assertEquals($temp, $result);
}
public static function dataGetTemp(): array
{
$faker = Factory::create('en_EN');
return [
['temp' => null],
['temp' => $faker->randomFloat()],
];
}
/**
* @throws ReflectionException
* @test
*/
public function setTemp(): void
{
$entity = new History();
$property = $this->tester->getClassProperty($entity, 'temp');
$temp = (Factory::create('en_EN'))->randomFloat();
$resultSet = $entity->setTemp($temp);
$result = $property->getValue($entity);
self::assertEquals($temp, $result);
self::assertEquals($entity, $resultSet);
}
/**
* @dataProvider dataGetDateAt
*
* @throws ReflectionException
* @test
*/
public function getDateAt(?DateTimeInterface $date_at): void
{
$entity = new History();
$property = $this->tester->getClassProperty($entity, 'date_at');
$property->setValue($entity, $date_at);
$result = $entity->getDateAt();
self::assertEquals($date_at, $result);
}
public static function dataGetDateAt(): array
{
$faker = Factory::create('en_EN');
return [
['date_at' => null],
['date_at' => $faker->dateTime()],
];
}
/**
* @throws ReflectionException
* @test
*/
public function setDateAt(): void
{
$entity = new History();
$property = $this->tester->getClassProperty($entity, 'date_at');
$date_at = (Factory::create('en_EN'))->dateTime();
$resultSet = $entity->setDateAt($date_at);
$result = $property->getValue($entity);
self::assertEquals($date_at, $result);
self::assertEquals($entity, $resultSet);
}
}