Skip to content

Commit

Permalink
tests: increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Rafael Azevedo committed Mar 23, 2022
1 parent f7a20ff commit 2050d89
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/Unit/Attributes/GeneralTraitsVOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Attributes/PersonalTraitsVOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
Expand Down
105 changes: 104 additions & 1 deletion tests/Unit/Datetime/DatetimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/ValueObjects/AbstractValueObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @package HraDigital\Datatypes
* @copyright HraDigital\Datatypes
* @license MIT
* @group hugo
*/
class AbstractValueObjectTest extends AbstractBaseTestCase
{
Expand Down

0 comments on commit 2050d89

Please sign in to comment.