mirror of
https://github.com/pestphp/pest.git
synced 2026-09-05 14:23:34 +02:00
chore: refactors exceptions
This commit is contained in:
@@ -31,7 +31,7 @@ test('failures with malformed input', function (): void {
|
||||
|
||||
test('failures with invalid type', function (): void {
|
||||
expect([])->toBeBase64();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
})->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!');
|
||||
|
||||
@@ -22,7 +22,7 @@ test('failures with leading dot', function (): void {
|
||||
|
||||
test('failures with invalid type', function (): void {
|
||||
expect([])->toBeDomain();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [string].');
|
||||
|
||||
test('failures with custom message', function (): void {
|
||||
expect('example')->toBeDomain('oh no!');
|
||||
|
||||
@@ -31,7 +31,7 @@ test('failures with empty string', function (): void {
|
||||
|
||||
test('failures with invalid type', function (): void {
|
||||
expect([])->toBeHexadecimal();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
})->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!');
|
||||
|
||||
@@ -22,7 +22,7 @@ test('failures with trailing hyphen', function (): void {
|
||||
|
||||
test('failures with invalid type', function (): void {
|
||||
expect([])->toBeHostname();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [string].');
|
||||
|
||||
test('failures with custom message', function (): void {
|
||||
expect('-example')->toBeHostname('oh no!');
|
||||
|
||||
@@ -17,7 +17,7 @@ test('failures', function (): void {
|
||||
|
||||
test('failures with invalid type', function (): void {
|
||||
expect([])->toBeIpAddress();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [string].');
|
||||
|
||||
test('failures with custom message', function (): void {
|
||||
expect('not-an-ip')->toBeIpAddress('oh no!');
|
||||
|
||||
@@ -17,7 +17,7 @@ test('failures', function (): void {
|
||||
|
||||
test('failures with invalid type', function (): void {
|
||||
expect([])->toBeMacAddress();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
})->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!');
|
||||
|
||||
@@ -7,7 +7,7 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('failures with wrong type', function (): void {
|
||||
expect([])->toBeUlid();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [string].');
|
||||
|
||||
test('pass', function (): void {
|
||||
expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid()
|
||||
|
||||
@@ -7,7 +7,7 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('failures with wrong type', function (): void {
|
||||
expect([])->toBeUuid();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [string].');
|
||||
|
||||
test('pass', function (): void {
|
||||
expect('3cafb226-4326-11ee-a516-846993788c86')->toBeUuid()
|
||||
|
||||
@@ -11,7 +11,7 @@ test('pass', function (): void {
|
||||
|
||||
test('failures with invalid type', function (): void {
|
||||
expect('foo')->toHaveCount(3);
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable]');
|
||||
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [countable|iterable]');
|
||||
|
||||
test('failures', function (): void {
|
||||
expect([1, 2, 3])->toHaveCount(4);
|
||||
|
||||
@@ -24,7 +24,7 @@ test('pass with value check and plain key with dots')->expect($test_array)->toHa
|
||||
|
||||
test('failures', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('foo');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'foo'");
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that an array has the key [foo]');
|
||||
|
||||
test('failures with custom message', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('foo', message: 'oh no!');
|
||||
@@ -36,7 +36,7 @@ test('failures with custom message and Any matcher', function () use ($test_arra
|
||||
|
||||
test('failures with nested key', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('d.bar');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'd.bar'");
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that an array has the key [d.bar]');
|
||||
|
||||
test('failures with nested key and custom message', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('d.bar', message: 'oh no!');
|
||||
@@ -48,7 +48,7 @@ test('failures with nested key and custom message with Any matcher', function ()
|
||||
|
||||
test('failures with plain key with dots', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('missing.key.with.dots');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'missing.key.with.dots'");
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that an array has the key [missing.key.with.dots]');
|
||||
|
||||
test('fails with wrong value', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('c', 'bar');
|
||||
|
||||
@@ -7,7 +7,7 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('failures with wrong type', function (): void {
|
||||
expect('foo')->toHaveSameSize([1]);
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable].');
|
||||
})->throws(InvalidExpectationValue::class, 'This expectation may only be used on a value of type [countable|iterable].');
|
||||
|
||||
test('pass', function (): void {
|
||||
expect([1, 2, 3])->toHaveSameSize([4, 5, 6]);
|
||||
|
||||
@@ -33,11 +33,11 @@ test('passes', function (): void {
|
||||
|
||||
test('failures 1', function (): void {
|
||||
expect(function (): void {})->toThrow(RuntimeException::class);
|
||||
})->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.');
|
||||
})->throws(ExpectationFailedException::class, 'Exception ['.RuntimeException::class.'] not thrown.');
|
||||
|
||||
test('failures 2', function (): void {
|
||||
expect(function (): void {})->toThrow(function (RuntimeException $e): void {});
|
||||
})->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.');
|
||||
})->throws(ExpectationFailedException::class, 'Exception ['.RuntimeException::class.'] not thrown.');
|
||||
|
||||
test('failures 3', function (): void {
|
||||
expect(function (): void {
|
||||
@@ -64,7 +64,7 @@ test('failures 5', function (): void {
|
||||
|
||||
test('failures 6', function (): void {
|
||||
expect(function (): void {})->toThrow('actual message');
|
||||
})->throws(ExpectationFailedException::class, 'Exception with message "actual message" not thrown');
|
||||
})->throws(ExpectationFailedException::class, 'Exception with message [actual message] not thrown');
|
||||
|
||||
test('failures 7', function (): void {
|
||||
expect(function (): void {
|
||||
|
||||
Reference in New Issue
Block a user