From 137c6c57b081f40b479768e66837f5d44437ec4b Mon Sep 17 00:00:00 2001 From: mostafaznv Date: Sat, 3 Jun 2023 01:07:52 +0330 Subject: [PATCH] GetValue method added to CacheEnum.php --- src/Utils/CacheEnum.php | 7 ++++++- tests/Unit/CacheStatusTest.php | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/CacheStatusTest.php diff --git a/src/Utils/CacheEnum.php b/src/Utils/CacheEnum.php index 1008a30..9a52244 100644 --- a/src/Utils/CacheEnum.php +++ b/src/Utils/CacheEnum.php @@ -11,8 +11,13 @@ public static function __callStatic(string $name, array $arguments): self return new static($name); } + public function getValue(): int|string + { + return $this->value; + } + public function equals(self $other): bool { - return get_class($this) === get_class($other) and $this->value === $other->value; + return get_class($this) === get_class($other) and $this->getValue() === $other->getValue(); } } diff --git a/tests/Unit/CacheStatusTest.php b/tests/Unit/CacheStatusTest.php new file mode 100644 index 0000000..b4879fc --- /dev/null +++ b/tests/Unit/CacheStatusTest.php @@ -0,0 +1,21 @@ +equals(CacheStatus::CREATED()); + expect($isEqual)->toBeTrue(); + + $isEqual = CacheStatus::CREATED()->equals(CacheStatus::DELETED()); + expect($isEqual)->toBeFalse(); +}); + +it('can get value of cache status', function(CacheStatus $status, string $value) { + expect($status->getValue())->toBe($value); +})->with([ + 'NOT_CREATED' => ['status' => CacheStatus::NOT_CREATED(), 'value' => 'NOT_CREATED'], + 'CREATING' => ['status' => CacheStatus::CREATING(), 'value' => 'CREATING'], + 'CREATED' => ['status' => CacheStatus::CREATED(), 'value' => 'CREATED'], + 'DELETED' => ['status' => CacheStatus::DELETED(), 'value' => 'DELETED'], +]);