mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Merge pull request #911 from devajmeireles/feature/add-to-be-digits-expectation
[2.x] Introducing `toBeDigits` Expectation
This commit is contained in:
@ -502,6 +502,18 @@ final class Expectation
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value contains only digits.
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toBeDigits(string $message = ''): self
|
||||
{
|
||||
Assert::assertTrue(ctype_digit((string) $this->value), $message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is of type object.
|
||||
*
|
||||
|
||||
20
tests/Features/Expect/toBeDigits.php
Normal file
20
tests/Features/Expect/toBeDigits.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('123')->toBeDigits();
|
||||
expect('123.14')->not->toBeDigits();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('123.14')->toBeDigits();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect('123.14')->toBeDigits('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect('445')->not->toBeDigits();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
Reference in New Issue
Block a user