assertNull($obj->getWorkingDay()); $this->assertNull($obj->getWorkingTime()); $this->assertFalse($obj->isHomeOffice()); $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', 'isHomeOffice' => true, ], true, ], [ new DateTime('2021-05-03'), new DateInterval("PT7H45M"), [ 'workingDay' => '2021-05-03', 'workingTime' => '07:45:00', 'isHomeOffice' => false, ], false, ], ]; } /** * @param DateTime $date * @param DateInterval $interval * @param array $shouldJson * @param bool $isHomeOffice */ #[DataProvider('workingHoursProvider')] public function testWorkingHoursWithContent(DateTime $date, DateInterval $interval, array $shouldJson, bool $isHomeOffice): void { $obj = new WorkingHours(); $obj->setWorkingDay($date)->setWorkingTime($interval)->setIsHomeOffice($isHomeOffice); $this->assertNotNull($obj->getWorkingDay()); $this->assertInstanceOf(DateTime::class, $obj->getWorkingDay()); $this->assertEquals($date, $obj->getWorkingDay()); $this->assertNotNull($obj->getWorkingTime()); $this->assertInstanceOf(DateInterval::class, $obj->getWorkingTime()); $this->assertEquals($interval, $obj->getWorkingTime()); $this->assertIsBool($obj->isHomeOffice()); $this->assertEquals($isHomeOffice, $obj->isHomeOffice()); $json = $obj->jsonSerialize(); $this->assertEquals($shouldJson, $json); } /** * @param DateTime $date * @param DateInterval $interval * @param array $shouldJson */ #[DataProvider('workingHoursProvider')] public function testWorkingHoursWithContentWithoutHomeOfficeInformation(DateTime $date, DateInterval $interval, array $shouldJson): void { $shouldJson['isHomeOffice'] = false; $obj = new WorkingHours(); $obj->setWorkingDay($date)->setWorkingTime($interval); $this->assertNotNull($obj->getWorkingDay()); $this->assertInstanceOf(DateTime::class, $obj->getWorkingDay()); $this->assertEquals($date, $obj->getWorkingDay()); $this->assertNotNull($obj->getWorkingTime()); $this->assertInstanceOf(DateInterval::class, $obj->getWorkingTime()); $this->assertEquals($interval, $obj->getWorkingTime()); $this->assertIsBool($obj->isHomeOffice()); $this->assertFalse($obj->isHomeOffice()); $json = $obj->jsonSerialize(); $this->assertEquals($shouldJson, $json); } }