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:
@@ -9,4 +9,4 @@ it('throws exception if no class nor method has been found', function (): void {
|
||||
$testCall = new TestCall(TestSuite::getInstance(), 'filename', 'description', fn () => 'closure');
|
||||
|
||||
$testCall->covers('fakeName');
|
||||
})->throws(InvalidArgumentException::class, 'No class, trait or method named "fakeName" has been found.');
|
||||
})->throws(InvalidArgumentException::class, 'No class, trait or method named [fakeName] has been found.');
|
||||
|
||||
@@ -21,7 +21,7 @@ test('reports missing datasets as errors for a single file run', function () use
|
||||
$result = $run('tests/Fixtures/Suites/IssueOnly.php');
|
||||
|
||||
expect($result['output'])
|
||||
->toContain("A dataset with the name [missing] does not exist. You can create it using `dataset('missing', ['a', 'b']);`.")
|
||||
->toContain("A dataset named [missing] does not exist. You may create one using `dataset('missing', ['a', 'b']);`.")
|
||||
->toContain('FAILED')
|
||||
->toContain('Tests: 1 failed')
|
||||
->and($result['code'])->not->toBe(0);
|
||||
@@ -31,7 +31,7 @@ test('reports missing datasets as errors alongside passing tests', function () u
|
||||
$result = $run('tests/Fixtures/Suites/IssueWithPassing.php');
|
||||
|
||||
expect($result['output'])
|
||||
->toContain("A dataset with the name [missing] does not exist. You can create it using `dataset('missing', ['a', 'b']);`.")
|
||||
->toContain("A dataset named [missing] does not exist. You may create one using `dataset('missing', ['a', 'b']);`.")
|
||||
->toContain('1 passed')
|
||||
->toContain('1 failed')
|
||||
->and($result['code'])->not->toBe(0);
|
||||
|
||||
@@ -10,12 +10,12 @@ beforeEach(function (): void {
|
||||
});
|
||||
|
||||
it('throws exception if dataset does not exist', function (): void {
|
||||
expect(fn () => DatasetsRepository::resolve(['first'], __FILE__))->toThrow(DatasetDoesNotExist::class, "A dataset with the name [first] does not exist. You can create it using `dataset('first', ['a', 'b']);`.");
|
||||
expect(fn () => DatasetsRepository::resolve(['first'], __FILE__))->toThrow(DatasetDoesNotExist::class, "A dataset named [first] does not exist. You may create one using `dataset('first', ['a', 'b']);`.");
|
||||
});
|
||||
|
||||
it('throws exception if dataset already exist', function (): void {
|
||||
DatasetsRepository::set('second', [[]], __DIR__);
|
||||
expect(fn () => DatasetsRepository::set('second', [[]], __DIR__))->toThrow(DatasetAlreadyExists::class, 'A dataset with the name [second] already exists in scope ['.__DIR__.'].');
|
||||
expect(fn () => DatasetsRepository::set('second', [[]], __DIR__))->toThrow(DatasetAlreadyExists::class, 'A dataset named [second] is already registered in ['.__DIR__.'].');
|
||||
});
|
||||
|
||||
it('sets closures', function (): void {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -175,7 +175,7 @@ test('tia still requires git', function (): void {
|
||||
|
||||
$result = $project->pest('--tia');
|
||||
|
||||
expect($result->output)->toContain('The feature [Tia mode] requires [git].')
|
||||
expect($result->output)->toContain('The [Tia mode] feature requires [git].')
|
||||
->and($result->exitCode)->not->toBe(0);
|
||||
})->skipOnWindows();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user