mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Merge branch 'master' into nested-higher-order-expectations
# Conflicts: # src/Expectation.php # tests/.snapshots/success.txt
This commit is contained in:
@ -2,14 +2,68 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKey('c');
|
||||
});
|
||||
$test_array = [
|
||||
'a' => 1,
|
||||
'b',
|
||||
'c' => 'world',
|
||||
'd' => [
|
||||
'e' => 'hello',
|
||||
],
|
||||
'key.with.dots' => false,
|
||||
];
|
||||
|
||||
test('failures', function () {
|
||||
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKey('hello');
|
||||
test('pass')->expect($test_array)->toHaveKey('c');
|
||||
test('pass with nested key')->expect($test_array)->toHaveKey('d.e');
|
||||
test('pass with plain key with dots')->expect($test_array)->toHaveKey('key.with.dots');
|
||||
|
||||
test('pass with value check')->expect($test_array)->toHaveKey('c', 'world');
|
||||
test('pass with value check and nested key')->expect($test_array)->toHaveKey('d.e', 'hello');
|
||||
test('pass with value check and plain key with dots')->expect($test_array)->toHaveKey('key.with.dots', false);
|
||||
|
||||
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 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 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'");
|
||||
|
||||
test('fails with wrong value', function () use ($test_array) {
|
||||
expect($test_array)->toHaveKey('c', 'bar');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKey('hello');
|
||||
test('fails with wrong value and nested key', function () use ($test_array) {
|
||||
expect($test_array)->toHaveKey('d.e', 'foo');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('fails with wrong value and plain key with dots', function () use ($test_array) {
|
||||
expect($test_array)->toHaveKey('key.with.dots', true);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () use ($test_array) {
|
||||
expect($test_array)->not->toHaveKey('c');
|
||||
})->throws(ExpectationFailedException::class, "Expecting Array (...) not to have key 'c'");
|
||||
|
||||
test('not failures with nested key', function () use ($test_array) {
|
||||
expect($test_array)->not->toHaveKey('d.e');
|
||||
})->throws(ExpectationFailedException::class, "Expecting Array (...) not to have key 'd.e'");
|
||||
|
||||
test('not failures with plain key with dots', function () use ($test_array) {
|
||||
expect($test_array)->not->toHaveKey('key.with.dots');
|
||||
})->throws(ExpectationFailedException::class, "Expecting Array (...) not to have key 'key.with.dots'");
|
||||
|
||||
test('not failures with correct value', function () use ($test_array) {
|
||||
expect($test_array)->not->toHaveKey('c', 'world');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with correct value and with nested key', function () use ($test_array) {
|
||||
expect($test_array)->not->toHaveKey('d.e', 'hello');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with correct value and with plain key with dots', function () use ($test_array) {
|
||||
expect($test_array)->not->toHaveKey('key.with.dots', false);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@ -3,13 +3,13 @@
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'c']);
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->toHaveKeys(['a', 'c', 'foo.bar']);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'd']);
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->toHaveKeys(['a', 'd', 'foo.bar', 'hello.world']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKeys(['hello', 'c']);
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->not->toHaveKeys(['foo.bar', 'c', 'z']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
Reference in New Issue
Block a user