mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
e107ac707c
* 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>
33 lines
1.1 KiB
PHP
33 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Pest\Exceptions\InvalidExpectationValue;
|
|
use PHPUnit\Framework\ExpectationFailedException;
|
|
|
|
test('pass', function (): void {
|
|
expect('00:1a:2b:3c:4d:5e')->toBeMacAddress()
|
|
->and('00-1a-2b-3c-4d-5e')->toBeMacAddress()
|
|
->and('ff:ff:ff:ff:ff:ff')->toBeMacAddress();
|
|
});
|
|
|
|
test('failures', function (): void {
|
|
expect('not-a-mac')->toBeMacAddress();
|
|
})->throws(ExpectationFailedException::class);
|
|
|
|
test('failures with invalid type', function (): void {
|
|
expect([])->toBeMacAddress();
|
|
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [string].');
|
|
|
|
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);
|