feat: toBeUUID expectation

This commit is contained in:
Thai Nguyen Hung
2023-09-05 08:25:02 +07:00
parent cc6c5bf199
commit 038fd80428
3 changed files with 56 additions and 0 deletions

View File

@ -16,6 +16,7 @@ use Pest\Matchers\Any;
use Pest\Support\Arr;
use Pest\Support\Exporter;
use Pest\Support\NullClosure;
use Pest\Support\Str;
use Pest\TestSuite;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Constraint\Constraint;
@ -1111,4 +1112,20 @@ final class Expectation
return $this;
}
/**
* Asserts that the value is UUID.
*
* @return self<TValue>
*/
public function toBeUUID(string $message = ''): self
{
if (! is_string($this->value)) {
InvalidExpectationValue::expected('string');
}
Assert::assertTrue(Str::isUuid($this->value), $message);
return $this;
}
}