Einführung des Modells.

This commit is contained in:
2021-03-29 15:07:07 +02:00
parent 9e2e94c116
commit e4cd00caf1
6 changed files with 153 additions and 3 deletions
@@ -0,0 +1,70 @@
<?php
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Models;
use Codeception\Test\Unit;
use DateInterval;
use DateTime;
use Error;
use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
class WorkingHoursTest extends Unit
{
public function testWorkingHoursWithoutContent(): void
{
$obj = new WorkingHours();
$this->assertNull($obj->getWorkingDay());
$this->assertNull($obj->getWorkingTime());
$this->expectException(Error::class);
$obj->jsonSerialize();
}
/**
* @return array[]
*/
public function workingHoursProvider(): array
{
return [
[
new DateTime('2020-11-30'),
new DateInterval("PT8H"),
[
'workingDay' => '2020-11-30',
'workingTime' => '08:00:00',
],
],
[
new DateTime('2021-05-03'),
new DateInterval("PT7H45M"),
[
'workingDay' => '2021-05-03',
'workingTime' => '07:45:00',
],
],
];
}
/**
* @param DateTime $date
* @param DateInterval $interval
* @param array<string, string> $should_json
*
* @dataProvider workingHoursProvider
*/
public function testWorkingHoursWithContent(DateTime $date, DateInterval $interval, array $should_json): void
{
$obj = new WorkingHours();
$obj
->setWorkingDay($date)
->setWorkingTime($interval);
$this->assertNotNull($obj->getWorkingDay());
$this->assertNotNull($obj->getWorkingTime());
$json = $obj->jsonSerialize();
$this->assertIsArray($json);
$this->assertEquals($should_json, $json);
}
}