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:
Vincent Borgers
2026-11-03 17:42:45 +01:00
committed by GitHub
parent b3baf7e210
commit e107ac707c
16 changed files with 119 additions and 2 deletions
+52
View File
@@ -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;