Skip to content

Commit

Permalink
test(unit) remove keys from provided data
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Jul 30, 2024
1 parent 190e197 commit 4c7adda
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions tests/unit/lucatume/WPBrowser/Utils/ArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@ public function searchWithCallbackDataProvider(): array
{
return [
'empty haystack, return true isNeedle' => [
'isNeedle' => static function (): bool {
static function (): bool {
return true;
},
'haystack' => [],
'expected' => false
[],
false
],
'empty haystack, return false isNeedle' => [
'isNeedle' => static function (): bool {
static function (): bool {
return false;
},
'haystack' => [],
'expected' => false
[],
false
],
'return false isNeedle' => [
'isNeedle' => static function (): bool {
static function (): bool {
return false;
},
'haystack' => [1, 2, 3],
'expected' => false
[1, 2, 3],
false
],
'isNeedle is true for first item' => [
'isNeedle' => static function (int $item): bool {
static function (int $item): bool {
return $item === 1;
},
'haystack' => [1, 2, 3],
'expected' => 0
[1, 2, 3],
0
],
'isNeedle true for 3rd and 4th argument' => [
'isNeedle' => static function (int $item, int $key): bool {
static function (int $item, int $key): bool {
return $item === 3 || $key === 3;
},
'haystack' => [1, 2, 3, 4],
'expected' => 2
[1, 2, 3, 4],
2
],
];
}
Expand All @@ -63,29 +63,29 @@ public function firstFromDataProvider(): array
{
return [
'empty' => [
'value' => [],
'default' => null,
'expected' => null
[],
null,
null
],
'empty, default value is 23' => [
'value' => [],
'default' => 23,
'expected' => 23
[],
23,
23
],
'object value' => [
'value' => new stdClass(),
'default' => null,
'expected' => null
new stdClass(),
null,
null
],
'array of numbers' => [
'value' => [1, 2, 3],
'default' => null,
'expected' => 1
[1, 2, 3],
null,
1
],
'array of numbers, default value is 23' => [
'value' => [1, 2, 3],
'default' => 23,
'expected' => 1
[1, 2, 3],
23,
1
]
];
}
Expand All @@ -103,63 +103,63 @@ public function hasShapeDataProvider(): array
{
return [
'empty array, empty shapes' => [
'array' => [],
'expected' => true,
[],
true,
[]
],
'empty array, 3 numbers shapes' => [
'array' => [],
'expected' => false,
[],
false,
['int', 'int', 'int']
],
'array has wrong shape' => [
'array' => [1, 2, 3],
'expected' => false,
[1, 2, 3],
false,
['int', 'int', 'string']
],
'array has 3 objects shape' => [
'array' => [new stdClass, new stdClass, new stdClass],
'expected' => true,
[new stdClass, new stdClass, new stdClass],
true,
['stdClass', 'stdClass', 'stdClass']
],
'array has 3 objects shape, misses 1' => [
'array' => [new stdClass, new stdClass],
'expected' => false,
[new stdClass, new stdClass],
false,
['stdClass', 'stdClass', 'stdClass']
],
'array has mixed shape' => [
'array' => [new stdClass, 2, '3'],
'expected' => true,
[new stdClass, 2, '3'],
true,
['stdClass', 'int', 'string']
],
'array has mixed shape, misses one' => [
'array' => [new stdClass, 2],
'expected' => false,
[new stdClass, 2],
false,
['stdClass', 'int', 'string']
],
'array has mixed shape, 3rd type is Closure' => [
'array' => [new stdClass, 2, '3'],
'expected' => true,
[new stdClass, 2, '3'],
true,
['stdClass', 'int', fn(string $value): bool => $value === '3']
],
'array has mixed shape, 3rd type is Closure, misses one' => [
'array' => [new stdClass, 2],
'expected' => false,
[new stdClass, 2],
false,
['stdClass', 'int', fn(string $value): bool => $value === '3']
],
'array has mixed shape with associative type' => [
'array' => ['a' => new stdClass, 'b' => 2, 'c' => '3'],
'expected' => true,
['a' => new stdClass, 'b' => 2, 'c' => '3'],
true,
['a' => 'stdClass', 'b' => 'int', 'c' => fn(string $value): bool => $value === '3']
],
'array shape does not match mixed types' => [
'array' => ['a' => new stdClass, 'b' => 2, 'c' => '3'],
'expected' => false,
['a' => new stdClass, 'b' => 2, 'c' => '3'],
false,
['a' => 'stdClass', 'b' => 'int', 'c' => fn(string $value): bool => $value === '4']
],
'array shape matches in different order' => [
'array' => ['a' => new stdClass, 'b' => 2, 'c' => '3'],
'expected' => true,
['a' => new stdClass, 'b' => 2, 'c' => '3'],
true,
['b' => 'int', 'c' => fn(string $value): bool => $value === '3', 'a' => 'stdClass']
],
];
Expand Down

0 comments on commit 4c7adda

Please sign in to comment.