mirror of
https://github.com/pestphp/pest.git
synced 2026-12-04 23:15: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>
47 lines
1.6 KiB
PHP
47 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Pest\Exceptions\InvalidExpectationValue;
|
|
use PHPUnit\Framework\ExpectationFailedException;
|
|
|
|
test('pass', function (): void {
|
|
expect('Zm9v')->toBeBase64()
|
|
->and('Zm9vYg==')->toBeBase64()
|
|
->and('Zm9vYmE=')->toBeBase64()
|
|
->and('Zm9vYmFy')->toBeBase64()
|
|
->and('')->toBeBase64();
|
|
});
|
|
|
|
test('failures', function (): void {
|
|
expect('not-base64!')->toBeBase64();
|
|
})->throws(ExpectationFailedException::class);
|
|
|
|
test('failures with invalid padding', function (): void {
|
|
expect('AAA')->toBeBase64();
|
|
})->throws(ExpectationFailedException::class);
|
|
|
|
test('failures with padding only', function (): void {
|
|
expect('====')->toBeBase64();
|
|
})->throws(ExpectationFailedException::class);
|
|
|
|
test('failures with malformed input', function (): void {
|
|
expect('!!invalid!!')->toBeBase64();
|
|
})->throws(ExpectationFailedException::class);
|
|
|
|
test('failures with invalid type', function (): void {
|
|
expect([])->toBeBase64();
|
|
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [string].');
|
|
|
|
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);
|