From 161f04b719cc104eacfd2fa699ac60bb5f3e4dae Mon Sep 17 00:00:00 2001 From: Thai Nguyen Hung Date: Thu, 8 Jun 2023 09:30:57 +0700 Subject: [PATCH] test: comparable enum --- tests/Pest.php | 6 ++--- tests/Pest/ComparableTest.php | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 tests/Pest/ComparableTest.php diff --git a/tests/Pest.php b/tests/Pest.php index 47f9676..e29ceac 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,6 +1,6 @@ is(Status::PENDING)) + ->toBeTrue() + ->and(Status::PENDING->is(Status::DONE)) + ->toBeFalse() + ->and(Role::ADMIN->is(Role::ADMIN)) + ->toBeTrue() + ->and(Role::ADMIN->is(Role::GUEST)) + ->toBeFalse() + ->and(Role::ADMIN->is('admin')) + ->toBeFalse(); +}); + +it('compare not equal enum', function () { + expect(Status::PENDING->isNot(Status::DONE)) + ->toBeTrue() + ->and(Status::PENDING->isNot(Status::PENDING)) + ->toBeFalse() + ->and(Status::PENDING->isNot(Role::ADMIN)) + ->toBeTrue() + ->and(Role::ADMIN->isNot(Role::GUEST)) + ->toBeTrue() + ->and(Role::ADMIN->isNot(Role::ADMIN)) + ->toBeFalse() + ->and(Role::ADMIN->isNot('admin')) + ->toBeTrue(); +}); + +it('compare in enums', function () { + expect(Status::PENDING->in([Status::PENDING, Status::DONE])) + ->toBeTrue() + ->and(Status::PENDING->in([Status::DONE])) + ->toBeFalse() + ->and(Status::PENDING->in([Role::ADMIN, Role::GUEST])) + ->toBeFalse() + ->and(Role::ADMIN->in([Role::ADMIN])) + ->toBeTrue(); +}); + +it('compare not in enums', function () { + expect(Status::PENDING->notIn([Status::DONE])) + ->toBeTrue() + ->and(Status::PENDING->notIn([Status::PENDING, Status::DONE])) + ->toBeFalse() + ->and(Role::ADMIN->notIn([Role::GUEST])) + ->toBeTrue() + ->and(Role::ADMIN->notIn([Role::ADMIN, Role::GUEST])) + ->toBeFalse(); +});