diff --git a/php/BasicTestCase.php b/php/BasicTestCase.php index 536ddba..49199b2 100644 --- a/php/BasicTestCase.php +++ b/php/BasicTestCase.php @@ -7,11 +7,6 @@ namespace Tests; use Illuminate\Support\Collection; use PHPUnit\Framework\TestCase; -/** - * Useful phpunit asserts - * - * @see https://gist.github.com/anthonyaxenov/3c0d56b8884856a58c75a6f787006546/edit - */ class BasicTestCase extends TestCase { /** @@ -106,4 +101,34 @@ class BasicTestCase extends TestCase || $this->checkExtendsClasses([Collection::class], $value) ); } -} + + /** + * Asserts that $array has all the $keys + * + * @param array $keys Keys to check + * @param array|ArrayAccess|Arrayable $array Array in which to check keys presence + * @return void + */ + public function assertArrayHasKeys(array $keys, array|ArrayAccess|Arrayable $array): void + { + $array instanceof Arrayable && $array = $array->toArray(); + foreach ($keys as $key) { + $this->assertArrayHasKey($key, $array); + } + } + + /** + * Asserts that $array has not all the $keys + * + * @param array $keys Keys to check + * @param array|ArrayAccess|Arrayable $array Array in which to check keys absence + * @return void + */ + public function assertArrayHasNotKeys(array $keys, array|ArrayAccess|Arrayable $array): void + { + $array instanceof Arrayable && $array = $array->toArray(); + foreach ($keys as $key) { + $this->assertArrayNotHasKey($key, $array); + } + } +} \ No newline at end of file