From 6208c9f8b208a9cb31bcaa0d4ce574a548af94e7 Mon Sep 17 00:00:00 2001 From: valb-mig Date: Thu, 19 Mar 2026 15:46:07 -0300 Subject: [PATCH 1/2] chore: Add readonly to Dice constructor --- src/Domain/ValueObjects/Dice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domain/ValueObjects/Dice.php b/src/Domain/ValueObjects/Dice.php index 4bc9c7d..7f9a928 100644 --- a/src/Domain/ValueObjects/Dice.php +++ b/src/Domain/ValueObjects/Dice.php @@ -13,7 +13,7 @@ final class Dice * @throws \InvalidArgumentException */ public function __construct( - public int $sides, + public readonly int $sides, ) { if ($sides < self::MINIMUM_VALUE) { throw new \InvalidArgumentException('Invalid number of sides for a dice'); From 50c7b1345e57c5614a580f8e14cd4b890606ef1e Mon Sep 17 00:00:00 2001 From: valb-mig Date: Mon, 23 Mar 2026 16:32:48 -0300 Subject: [PATCH 2/2] feat: add check entity --- src/Domain/Entities/Check.php | 50 ++++++++++++++++++++++++ tests/Domain/Entities/CheckTest.php | 59 +++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/Domain/Entities/Check.php create mode 100644 tests/Domain/Entities/CheckTest.php diff --git a/src/Domain/Entities/Check.php b/src/Domain/Entities/Check.php new file mode 100644 index 0000000..f200f9a --- /dev/null +++ b/src/Domain/Entities/Check.php @@ -0,0 +1,50 @@ += $this->threshold; + } + + /** + * @param int $roll + * @return bool + */ + public function isFailure(int $roll): bool + { + return $roll < $this->threshold; + } +} diff --git a/tests/Domain/Entities/CheckTest.php b/tests/Domain/Entities/CheckTest.php new file mode 100644 index 0000000..192f9f4 --- /dev/null +++ b/tests/Domain/Entities/CheckTest.php @@ -0,0 +1,59 @@ +assertSame('My Check', $check->title); + $this->assertSame(10, $check->threshold); + } + + public function test_check_is_successful_when_roll_is_greater_than_or_equal_to_threshold(): void + { + $check = Check::create('My Check', 10); + + $this->assertTrue($check->isSuccess(10)); + $this->assertFalse($check->isSuccess(9)); + } + + public function test_check_is_failure_when_roll_is_less_than_threshold(): void + { + $check = Check::create('My Check', 10); + + $this->assertFalse($check->isFailure(10)); + $this->assertTrue($check->isFailure(9)); + } + + // ------------------------------------------------------------------------- + // Exceptions + // ------------------------------------------------------------------------- + + public function test_check_throws_exception_when_threshold_is_negative(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Threshold must be greater than or equal to 0.'); + + Check::create('My Check', -1); + } + + public function test_check_throws_exception_when_title_is_empty(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Title cannot be empty.'); + + Check::create('', 10); + } +}