mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
Add default failure messages to the remaining string expectations (#1948)
* Add default failure messages to the remaining string expectations * test: update parallel snapshot count for the new default-message cases --------- Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
@@ -447,6 +447,10 @@ final class Expectation
|
||||
*/
|
||||
public function toBeDigits(string $message = ''): self
|
||||
{
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} contains only digits.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(ctype_digit((string) $this->value), $message);
|
||||
|
||||
return $this;
|
||||
@@ -889,6 +893,10 @@ final class Expectation
|
||||
*/
|
||||
public function toBeUppercase(string $message = ''): self
|
||||
{
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is uppercase.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(ctype_upper((string) $this->value), $message);
|
||||
|
||||
return $this;
|
||||
@@ -899,6 +907,10 @@ final class Expectation
|
||||
*/
|
||||
public function toBeLowercase(string $message = ''): self
|
||||
{
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is lowercase.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(ctype_lower((string) $this->value), $message);
|
||||
|
||||
return $this;
|
||||
@@ -909,6 +921,10 @@ final class Expectation
|
||||
*/
|
||||
public function toBeAlphaNumeric(string $message = ''): self
|
||||
{
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is alphanumeric.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(ctype_alnum((string) $this->value), $message);
|
||||
|
||||
return $this;
|
||||
@@ -919,6 +935,10 @@ final class Expectation
|
||||
*/
|
||||
public function toBeAlpha(string $message = ''): self
|
||||
{
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is alphabetic.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(ctype_alpha((string) $this->value), $message);
|
||||
|
||||
return $this;
|
||||
@@ -997,6 +1017,10 @@ final class Expectation
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is a UUID.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(Str::isUuid($this->value), $message);
|
||||
|
||||
return $this;
|
||||
@@ -1011,6 +1035,10 @@ final class Expectation
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is a ULID.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(Str::isUlid($this->value), $message);
|
||||
|
||||
return $this;
|
||||
@@ -1079,6 +1107,10 @@ final class Expectation
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is an IP address.";
|
||||
}
|
||||
|
||||
Assert::assertTrue((bool) filter_var($this->value, FILTER_VALIDATE_IP), $message);
|
||||
|
||||
return $this;
|
||||
@@ -1093,6 +1125,10 @@ final class Expectation
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is a MAC address.";
|
||||
}
|
||||
|
||||
Assert::assertTrue((bool) filter_var($this->value, FILTER_VALIDATE_MAC), $message);
|
||||
|
||||
return $this;
|
||||
@@ -1107,6 +1143,10 @@ final class Expectation
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is a hostname.";
|
||||
}
|
||||
|
||||
Assert::assertTrue((bool) filter_var($this->value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME), $message);
|
||||
|
||||
return $this;
|
||||
@@ -1121,6 +1161,10 @@ final class Expectation
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is a domain.";
|
||||
}
|
||||
|
||||
$isValid = filter_var($this->value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) !== false
|
||||
&& str_contains($this->value, '.');
|
||||
|
||||
@@ -1138,6 +1182,10 @@ final class Expectation
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is a base64 string.";
|
||||
}
|
||||
|
||||
$decoded = base64_decode($this->value, true);
|
||||
Assert::assertTrue($decoded !== false && base64_encode($decoded) === $this->value, $message);
|
||||
|
||||
@@ -1153,6 +1201,10 @@ final class Expectation
|
||||
InvalidExpectationValue::expected('string');
|
||||
}
|
||||
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is a hexadecimal string.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(ctype_xdigit($this->value), $message);
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -472,12 +472,14 @@
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeAlphaNumeric
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeArray
|
||||
@@ -494,6 +496,7 @@
|
||||
✓ failures with malformed input
|
||||
✓ failures with invalid type
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeBetween
|
||||
@@ -534,6 +537,7 @@
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeDirectory
|
||||
@@ -548,6 +552,7 @@
|
||||
✓ failures with leading dot
|
||||
✓ failures with invalid type
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeEmail
|
||||
@@ -620,6 +625,7 @@
|
||||
✓ failures with empty string
|
||||
✓ failures with invalid type
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeHostname
|
||||
@@ -628,6 +634,7 @@
|
||||
✓ failures with trailing hyphen
|
||||
✓ failures with invalid type
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeIn
|
||||
@@ -671,6 +678,7 @@
|
||||
✓ failures
|
||||
✓ failures with invalid type
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeIterable
|
||||
@@ -717,6 +725,7 @@
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeMacAddress
|
||||
@@ -724,6 +733,7 @@
|
||||
✓ failures
|
||||
✓ failures with invalid type
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeNAN
|
||||
@@ -829,12 +839,14 @@
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ failures with message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeUppercase
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ failures with custom message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeUrl
|
||||
@@ -849,6 +861,7 @@
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ failures with message
|
||||
✓ failures with default message
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\Expect\toBeWritableDirectory
|
||||
@@ -2308,4 +2321,4 @@
|
||||
✓ pass with dataset with ('my-datas-set-value')
|
||||
✓ within describe → pass with dataset with ('my-datas-set-value')
|
||||
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1635 passed (3610 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1648 passed (3649 assertions)
|
||||
@@ -17,6 +17,10 @@ test('failures with custom message', function (): void {
|
||||
expect('123')->toBeAlpha('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('123')->toBeAlpha();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that 123 is alphabetic.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('abc')->not->toBeAlpha();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -17,6 +17,10 @@ test('failures with custom message', function (): void {
|
||||
expect('-')->toBeAlphaNumeric('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('-')->toBeAlphaNumeric();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that - is alphanumeric.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('abc123')->not->toBeAlphaNumeric();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -37,6 +37,10 @@ test('failures with custom message', function (): void {
|
||||
expect('!!invalid!!')->toBeBase64('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('!!invalid!!')->toBeBase64();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that !!invalid!! is a base64 string.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('Zm9v')->not->toBeBase64();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -17,6 +17,10 @@ test('failures with custom message', function (): void {
|
||||
expect('123.14')->toBeDigits('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('123.14')->toBeDigits();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that 123.14 contains only digits.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('445')->not->toBeDigits();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -28,6 +28,10 @@ test('failures with custom message', function (): void {
|
||||
expect('example')->toBeDomain('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('example')->toBeDomain();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that example is a domain.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('example.com')->not->toBeDomain();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -37,6 +37,10 @@ test('failures with custom message', function (): void {
|
||||
expect('xyz')->toBeHexadecimal('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('xyz')->toBeHexadecimal();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that xyz is a hexadecimal string.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('abcdef')->not->toBeHexadecimal();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -28,6 +28,10 @@ test('failures with custom message', function (): void {
|
||||
expect('-example')->toBeHostname('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('-example')->toBeHostname();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that -example is a hostname.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('example.com')->not->toBeHostname();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -23,6 +23,10 @@ test('failures with custom message', function (): void {
|
||||
expect('not-an-ip')->toBeIpAddress('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('not-an-ip')->toBeIpAddress();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that not-an-ip is an IP address.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('192.168.1.1')->not->toBeIpAddress();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -17,6 +17,10 @@ test('failures with custom message', function (): void {
|
||||
expect('UPPERCASE')->toBeLowercase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('UPPERCASE')->toBeLowercase();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that UPPERCASE is lowercase.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('lowercase')->not->toBeLowercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -23,6 +23,10 @@ test('failures with custom message', function (): void {
|
||||
expect('not-a-mac')->toBeMacAddress('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('not-a-mac')->toBeMacAddress();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that not-a-mac is a MAC address.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('00:1a:2b:3c:4d:5e')->not->toBeMacAddress();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -23,6 +23,10 @@ test('failures with message', function (): void {
|
||||
expect('bar')->toBeUlid('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('foo')->toBeUlid();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that foo is a ULID.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('foo')->not->toBeUlid();
|
||||
});
|
||||
|
||||
@@ -17,6 +17,10 @@ test('failures with custom message', function (): void {
|
||||
expect('lowercase')->toBeUppercase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('lowercase')->toBeUppercase();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that lowercase is uppercase.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('UPPERCASE')->not->toBeUppercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -28,6 +28,10 @@ test('failures with message', function (): void {
|
||||
expect('bar')->toBeUuid('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function (): void {
|
||||
expect('foo')->toBeUuid();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that foo is a UUID.');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('foo')->not->toBeUuid();
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ test('parallel', function () use ($run): void {
|
||||
$output = $run('--exclude-group=integration');
|
||||
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));
|
||||
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1609 passed (3538 assertions)';
|
||||
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1622 passed (3577 assertions)';
|
||||
|
||||
expect($output)
|
||||
->toContain("Tests: {$expected}")
|
||||
|
||||
Reference in New Issue
Block a user