Files
pest/tests/Features/Expect/toBeHexadecimal.php
T
Vincent Borgers e107ac707c 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>
2026-11-03 22:12:45 +05:30

47 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function (): void {
expect('abcdef')->toBeHexadecimal()
->and('ABCDEF')->toBeHexadecimal()
->and('aBcDeF')->toBeHexadecimal()
->and('1234567890')->toBeHexadecimal()
->and('deadbeef')->toBeHexadecimal();
});
test('failures', function (): void {
expect('xyz')->toBeHexadecimal();
})->throws(ExpectationFailedException::class);
test('failures with invalid characters', function (): void {
expect('ghijkl')->toBeHexadecimal();
})->throws(ExpectationFailedException::class);
test('failures with zero-x prefix', function (): void {
expect('0x1a')->toBeHexadecimal();
})->throws(ExpectationFailedException::class);
test('failures with empty string', function (): void {
expect('')->toBeHexadecimal();
})->throws(ExpectationFailedException::class);
test('failures with invalid type', function (): void {
expect([])->toBeHexadecimal();
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [string].');
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);