diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 5bb208cc..5f68109e 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -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; diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 2348e978..39bd3f9e 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -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) \ No newline at end of file diff --git a/tests/Features/Expect/toBeAlpha.php b/tests/Features/Expect/toBeAlpha.php index 9e76d554..46085482 100644 --- a/tests/Features/Expect/toBeAlpha.php +++ b/tests/Features/Expect/toBeAlpha.php @@ -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); diff --git a/tests/Features/Expect/toBeAlphaNumeric.php b/tests/Features/Expect/toBeAlphaNumeric.php index 90f5cb03..08cc34ea 100644 --- a/tests/Features/Expect/toBeAlphaNumeric.php +++ b/tests/Features/Expect/toBeAlphaNumeric.php @@ -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); diff --git a/tests/Features/Expect/toBeBase64.php b/tests/Features/Expect/toBeBase64.php index 91bcdadf..f4a01390 100644 --- a/tests/Features/Expect/toBeBase64.php +++ b/tests/Features/Expect/toBeBase64.php @@ -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); diff --git a/tests/Features/Expect/toBeDigits.php b/tests/Features/Expect/toBeDigits.php index 13acea0c..d08f4a47 100644 --- a/tests/Features/Expect/toBeDigits.php +++ b/tests/Features/Expect/toBeDigits.php @@ -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); diff --git a/tests/Features/Expect/toBeDomain.php b/tests/Features/Expect/toBeDomain.php index 54a9c59b..8a47ca69 100644 --- a/tests/Features/Expect/toBeDomain.php +++ b/tests/Features/Expect/toBeDomain.php @@ -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); diff --git a/tests/Features/Expect/toBeHexadecimal.php b/tests/Features/Expect/toBeHexadecimal.php index 7e10e8dc..9f4a1658 100644 --- a/tests/Features/Expect/toBeHexadecimal.php +++ b/tests/Features/Expect/toBeHexadecimal.php @@ -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); diff --git a/tests/Features/Expect/toBeHostname.php b/tests/Features/Expect/toBeHostname.php index f2791368..15c49c80 100644 --- a/tests/Features/Expect/toBeHostname.php +++ b/tests/Features/Expect/toBeHostname.php @@ -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); diff --git a/tests/Features/Expect/toBeIpAddress.php b/tests/Features/Expect/toBeIpAddress.php index 90a3faa9..c8ec4747 100644 --- a/tests/Features/Expect/toBeIpAddress.php +++ b/tests/Features/Expect/toBeIpAddress.php @@ -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); diff --git a/tests/Features/Expect/toBeLowercase.php b/tests/Features/Expect/toBeLowercase.php index 08c9c25d..ed68051d 100644 --- a/tests/Features/Expect/toBeLowercase.php +++ b/tests/Features/Expect/toBeLowercase.php @@ -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); diff --git a/tests/Features/Expect/toBeMacAddress.php b/tests/Features/Expect/toBeMacAddress.php index d6bfca6a..aac86463 100644 --- a/tests/Features/Expect/toBeMacAddress.php +++ b/tests/Features/Expect/toBeMacAddress.php @@ -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); diff --git a/tests/Features/Expect/toBeUlid.php b/tests/Features/Expect/toBeUlid.php index ab0d510a..5776d31f 100644 --- a/tests/Features/Expect/toBeUlid.php +++ b/tests/Features/Expect/toBeUlid.php @@ -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(); }); diff --git a/tests/Features/Expect/toBeUppercase.php b/tests/Features/Expect/toBeUppercase.php index 3ee6aedb..77880b78 100644 --- a/tests/Features/Expect/toBeUppercase.php +++ b/tests/Features/Expect/toBeUppercase.php @@ -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); diff --git a/tests/Features/Expect/toBeUuid.php b/tests/Features/Expect/toBeUuid.php index 8baba5e4..d03d8b36 100644 --- a/tests/Features/Expect/toBeUuid.php +++ b/tests/Features/Expect/toBeUuid.php @@ -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(); }); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 9bbf5a8c..84f7336c 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -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}")