-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asssert: add hasKey and hasNotKey assertions (#427)
- Loading branch information
1 parent
4b408f5
commit 3219575
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$array = [ | ||
1 => 1, | ||
'one' => 'one', | ||
]; | ||
|
||
$string= 'Lorem ipsum'; | ||
|
||
Assert::hasKey(1, $array); | ||
Assert::hasKey('one', $array); | ||
|
||
Assert::hasNotKey(2, $array); | ||
Assert::hasNotKey('two', $array); | ||
|
||
Assert::exception(function () use ($array) { | ||
Assert::hasKey(2, $array); | ||
}, Tester\AssertException::class, '%a% should contain key %a%'); | ||
|
||
Assert::exception(function () use ($array) { | ||
Assert::hasKey('two', $array); | ||
}, Tester\AssertException::class, '%a% should contain key %a%'); | ||
|
||
Assert::exception(function () use ($string) { | ||
Assert::hasKey('two', $string); | ||
}, Tester\AssertException::class, '%a% should be array'); | ||
|
||
|
||
Assert::exception(function () use ($array) { | ||
Assert::hasNotKey(1, $array); | ||
}, Tester\AssertException::class, '%a% should not contain key %a%'); | ||
|
||
Assert::exception(function () use ($array) { | ||
Assert::hasNotKey('one', $array); | ||
}, Tester\AssertException::class, '%a% should not contain key %a%'); | ||
|
||
|
||
Assert::exception(function () use ($string) { | ||
Assert::hasNotKey('two', $string); | ||
}, Tester\AssertException::class, '%a% should be array'); | ||
|
||
Assert::exception(function () use ($array) { | ||
Assert::hasKey('two', $array, 'Custom description'); | ||
}, Tester\AssertException::class, "Custom description: [1 => 1, 'one' => 'one'] should contain key 'two'"); | ||
|
||
Assert::exception(function () use ($array) { | ||
Assert::hasNotKey('one', $array, 'Custom description'); | ||
}, Tester\AssertException::class, "Custom description: [1 => 1, 'one' => 'one'] should not contain key 'one'"); |