diff --git a/tests/Unit/Attributes/GeneralTraitsVOTest.php b/tests/Unit/Attributes/GeneralTraitsVOTest.php index e7a2cc1..55dd44d 100644 --- a/tests/Unit/Attributes/GeneralTraitsVOTest.php +++ b/tests/Unit/Attributes/GeneralTraitsVOTest.php @@ -145,6 +145,16 @@ public function testBreaksIfAliasIsEmpty(): void new GeneralTraitsVO($data); } + public function testBreaksIfSurnameIsEmpty(): void + { + $this->expectException(NonEmptyStringException::class); + + $data = self::DATA; + $data['surname'] = ''; + + new GeneralTraitsVO($data); + } + public function testBreaksIfHitsIsNegative(): void { $this->expectException(NonNegativeNumberException::class); diff --git a/tests/Unit/Attributes/PersonalTraitsVOTest.php b/tests/Unit/Attributes/PersonalTraitsVOTest.php index d3409db..e7d1522 100644 --- a/tests/Unit/Attributes/PersonalTraitsVOTest.php +++ b/tests/Unit/Attributes/PersonalTraitsVOTest.php @@ -5,6 +5,7 @@ namespace HraDigital\Tests\Datatypes\Unit\Attributes; use HraDigital\Datatypes\Exceptions\Datatypes\NonEmptyStringException; +use HraDigital\Datatypes\Exceptions\Entities\UnexpectedEntityValueException; use HraDigital\Tests\Datatypes\AbstractBaseTestCase; /** @@ -36,6 +37,24 @@ public function testLoadsSuccessfully(): void $this->assertTrue($object->hasPhoto()); } + public function testLoadsSuccessfullyWithDifferentGender(): void + { + $data = self::DATA; + $data['gender'] = 'Female'; + $object = new PersonalTraitsVO($data); + + $this->assertEquals($data['gender'], (string) $object->getGender()); + } + + public function testBreaksIfGenderIsNotSupported(): void + { + $this->expectException(UnexpectedEntityValueException::class); + + $data = self::DATA; + $data['gender'] = 'Unsupported'; + new PersonalTraitsVO($data); + } + public function testBreaksWithEmptyCoutryOfBirth(): void { $data = self::DATA; diff --git a/tests/Unit/Datetime/DatetimeTest.php b/tests/Unit/Datetime/DatetimeTest.php index 1589fb2..ab33ce8 100644 --- a/tests/Unit/Datetime/DatetimeTest.php +++ b/tests/Unit/Datetime/DatetimeTest.php @@ -19,7 +19,7 @@ class DatetimeTest extends AbstractBaseTestCase { const DATETIME = '2021-05-06 10:11:12'; - public function testCanInstanciateSuccessfully(): void + public function testCanInstanciateSuccessfullyFromString(): void { $dt = Datetime::fromString(self::DATETIME); @@ -34,6 +34,109 @@ public function testCanInstanciateSuccessfully(): void $this->assertEquals($dt->jsonSerialize(), self::DATETIME); } + public function testCanInstantiateSuccessfullyFromNow(): void + { + $datetime = Datetime::now(); + $native = new \DateTime('now'); + + $this->assertEquals( + $datetime->toDateString(), + $native->format('Y-m-d') + ); + } + + public function testCanInstantiateSuccessfullyFromToday(): void + { + $datetime = Datetime::today(); + $native = new \DateTime('now'); + + $this->assertEquals( + $datetime->toDateString(), + $native->format('Y-m-d') + ); + $this->assertEquals(0, $datetime->getHour()); + $this->assertEquals(0, $datetime->getMinute()); + $this->assertEquals(0, $datetime->getSecond()); + } + + public function testCanInstantiateSuccessfullyFromTomorrow(): void + { + $datetime = Datetime::tomorrow(); + $native = new \DateTime('now'); + + $this->assertEquals( + $datetime->addDays(-1)->toDateString(), + $native->format('Y-m-d') + ); + $this->assertEquals(0, $datetime->getHour()); + $this->assertEquals(0, $datetime->getMinute()); + $this->assertEquals(0, $datetime->getSecond()); + } + + public function testCanInstantiateSuccessfullyFromYesterday(): void + { + $datetime = Datetime::yesterday(); + $native = new \DateTime('now'); + + $this->assertEquals( + $datetime->addDays(1)->toDateString(), + $native->format('Y-m-d') + ); + $this->assertEquals(0, $datetime->getHour()); + $this->assertEquals(0, $datetime->getMinute()); + $this->assertEquals(0, $datetime->getSecond()); + } + + public function testCanInstantiateSuccessfullyFromTimestamp(): void + { + $original = Datetime::now(); + $timestamp = $original->getTimestamp(); + + $fromTimestamp = Datetime::fromTimestamp($timestamp); + + $this->assertFalse($original === $fromTimestamp); + $this->assertEquals( + $original->toDatetimeString(), + $fromTimestamp->toDatetimeString() + ); + } + + public function testCanInstantiateSuccessfullyFromUnits(): void + { + $years = 2020; + $months = 11; + $days = 10; + $hours = 9; + $minutes = 30; + $seconds = 0; + $dt = Datetime::fromUnits($years, $months, $days, $hours, $minutes, $seconds); + + $this->assertEquals( + $years, + $dt->getYear() + ); + $this->assertEquals( + $months, + $dt->getMonth() + ); + $this->assertEquals( + $days, + $dt->getDay() + ); + $this->assertEquals( + $hours, + $dt->getHour() + ); + $this->assertEquals( + $minutes, + $dt->getMinute() + ); + $this->assertEquals( + $seconds, + $dt->getSecond() + ); + } + public function testCanAddInterval(): void { $dt = Datetime::fromString(self::DATETIME); diff --git a/tests/Unit/ValueObjects/AbstractValueObjectTest.php b/tests/Unit/ValueObjects/AbstractValueObjectTest.php index 0d13e44..b8fd680 100644 --- a/tests/Unit/ValueObjects/AbstractValueObjectTest.php +++ b/tests/Unit/ValueObjects/AbstractValueObjectTest.php @@ -15,7 +15,6 @@ * @package HraDigital\Datatypes * @copyright HraDigital\Datatypes * @license MIT - * @group hugo */ class AbstractValueObjectTest extends AbstractBaseTestCase {