assertArrayHasKeys + assertArrayHasNotKeys
This commit is contained in:
parent
e9f993b396
commit
ed013d9321
@ -7,11 +7,6 @@ namespace Tests;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
|
||||||
* Useful phpunit asserts
|
|
||||||
*
|
|
||||||
* @see https://gist.github.com/anthonyaxenov/3c0d56b8884856a58c75a6f787006546/edit
|
|
||||||
*/
|
|
||||||
class BasicTestCase extends TestCase
|
class BasicTestCase extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -106,4 +101,34 @@ class BasicTestCase extends TestCase
|
|||||||
|| $this->checkExtendsClasses([Collection::class], $value)
|
|| $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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user