From 2dc3e326893ce6839a8a3e464d86860ae7bdbdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SIGUI=20Kess=C3=A9=20Emmanuel?= Date: Mon, 13 Nov 2023 11:53:36 +0100 Subject: [PATCH] :sparkles: Add bool value --- src/BoolValue.php | 23 +++++++++++++++++++++++ src/Concerns/AsBool.php | 37 +++++++++++++++++++++++++++++++++++++ src/Contracts/BoolType.php | 10 ++++++++++ tests/Unit/BoolTest.php | 27 +++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/BoolValue.php create mode 100644 src/Concerns/AsBool.php create mode 100644 src/Contracts/BoolType.php create mode 100644 tests/Unit/BoolTest.php diff --git a/src/BoolValue.php b/src/BoolValue.php new file mode 100644 index 0000000..19d5f91 --- /dev/null +++ b/src/BoolValue.php @@ -0,0 +1,23 @@ +value = $value; + } + + public function get(): bool + { + return $this->value; + } +} diff --git a/src/Concerns/AsBool.php b/src/Concerns/AsBool.php new file mode 100644 index 0000000..d6b7fc6 --- /dev/null +++ b/src/Concerns/AsBool.php @@ -0,0 +1,37 @@ +get(); + } + + if (is_bool($value)) { + return new self($value); + } + + throw new \InvalidArgumentException(sprintf( + 'Value "%s" is not a boolean.', + get_debug_type($value), + )); + } +} diff --git a/src/Contracts/BoolType.php b/src/Contracts/BoolType.php new file mode 100644 index 0000000..ce15cfb --- /dev/null +++ b/src/Contracts/BoolType.php @@ -0,0 +1,10 @@ +bool = BoolValue::from(true); +}); + +it('should be instantiable', function () { + expect($this->bool)->toBeInstanceOf(BoolValue::class); +}); + +it('should be an instance of BoolType', function () { + expect($this->bool)->toBeInstanceOf(BoolType::class); +}); + +it('should be an instance of ScalarType', function () { + expect($this->bool)->toBeInstanceOf(ScalarType::class); +}); + +it('should return the value', function () { + expect($this->bool->get())->toBe(true); +});