feat: adds toHaveKeys expectation

This commit is contained in:
Nuno Maduro
2020-09-13 15:15:37 +02:00
parent aa230a1716
commit 204f343831
4 changed files with 58 additions and 2 deletions

View File

@ -180,6 +180,11 @@
PASS Tests\Expect\toHaveKey
✓ pass
✓ failures
✓ not failures
PASS Tests\Expect\toHaveKeys
✓ pass
✓ failures
✓ not failures
PASS Tests\Expect\toHaveProperty
@ -353,5 +358,5 @@
✓ depends with defined arguments
✓ depends run test only once
Tests: 6 skipped, 208 passed
Tests: 6 skipped, 211 passed

View File

@ -0,0 +1,15 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'c']);
});
test('failures', function () {
expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'd']);
})->throws(ExpectationFailedException::class);
test('not failures', function () {
expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKeys(['hello', 'c']);
})->throws(ExpectationFailedException::class);