From 18c74d7108039ce1cda82a2415c278f3394582b7 Mon Sep 17 00:00:00 2001 From: "cristian.almohalla" Date: Wed, 26 Oct 2022 08:16:42 +0200 Subject: [PATCH] feat: add unique id value object --- src/Domain/Model/ValueObject/UniqueId.php | 14 +++++ .../Domain/Model/ValueObject/UniqueIdTest.php | 56 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/Domain/Model/ValueObject/UniqueId.php create mode 100644 tests/Domain/Model/ValueObject/UniqueIdTest.php diff --git a/src/Domain/Model/ValueObject/UniqueId.php b/src/Domain/Model/ValueObject/UniqueId.php new file mode 100644 index 0000000..7a05fbd --- /dev/null +++ b/src/Domain/Model/ValueObject/UniqueId.php @@ -0,0 +1,14 @@ +assertEquals($value, $str->value()); + $this->assertEquals($value, $str->jsonSerialize()); + } + + /** + * @test + */ + public function given_uid_class_when_ask_to_generate_an_uid_then_return_uid_instance() + { + $uid = UniqueId::create(); + $this->assertInstanceOf(UniqueId::class, $uid); + $this->assertMatchesRegularExpression('/^[0-9A-Z]{10}$/i', $uid->value()); + } + + /** + * @test + */ + public function given_two_identical_uids_when_ask_to_check_equality_then_return_true() + { + $value = 'H7HVQ2U72X'; + $str = UniqueId::from($value); + $other = UniqueId::from($value); + + $this->assertTrue($str->equalTo($other)); + } + + /** + * @test + */ + public function given_two_different_uids_when_ask_to_check_equality_then_return_false() + { + $str = UniqueId::from('H7HVQ2U72X'); + $other = UniqueId::from('H7INVWHVPR'); + + $this->assertFalse($str->equalTo($other)); + } +}