add custom message to failed expectations

This commit is contained in:
Fabio Ivona
2022-09-19 09:03:27 +02:00
parent c5cb1fc325
commit 8a3caa5e7f
55 changed files with 424 additions and 143 deletions

View File

@ -24,10 +24,18 @@ test('failures', function () use ($test_array) {
expect($test_array)->toHaveKey('foo');
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'foo'");
test('failures with custom message', function () use ($test_array) {
expect($test_array)->toHaveKey('foo', message: 'oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('failures with nested key', function () use ($test_array) {
expect($test_array)->toHaveKey('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) {
expect($test_array)->toHaveKey('d.bar', message: 'oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('failures with plain key with dots', function () use ($test_array) {
expect($test_array)->toHaveKey('missing.key.with.dots');
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'missing.key.with.dots'");