|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace BrenoRoosevelt\Tests; |
| 5 | + |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | +use function BrenoRoosevelt\none; |
| 8 | +use const BrenoRoosevelt\CALLBACK_USE_BOTH; |
| 9 | +use const BrenoRoosevelt\CALLBACK_USE_KEY; |
| 10 | +use const BrenoRoosevelt\CALLBACK_USE_VALUE; |
| 11 | + |
| 12 | +class NoneTest extends TestCase |
| 13 | +{ |
| 14 | + public function noneProvider(): array |
| 15 | + { |
| 16 | + return [ |
| 17 | + 'case_1' => [ |
| 18 | + ['a', 'b', 'c'], // collection |
| 19 | + fn($el) => false, // callback |
| 20 | + CALLBACK_USE_VALUE, // mode |
| 21 | + true, // expected |
| 22 | + ], |
| 23 | + 'case_2' => [ |
| 24 | + ['a', 'b', 'c'], |
| 25 | + fn($el) => true, |
| 26 | + CALLBACK_USE_VALUE, |
| 27 | + false, |
| 28 | + ], |
| 29 | + 'case_3' => [ |
| 30 | + [], |
| 31 | + fn($el) => false, |
| 32 | + CALLBACK_USE_VALUE, |
| 33 | + true, |
| 34 | + ], |
| 35 | + 'case_3_1' => [ |
| 36 | + [], |
| 37 | + fn($el) => true, |
| 38 | + CALLBACK_USE_VALUE, |
| 39 | + true, |
| 40 | + ], |
| 41 | + 'case_4' => [ |
| 42 | + [1, 2, 3, 4], |
| 43 | + fn($el) => $el === 2, |
| 44 | + CALLBACK_USE_VALUE, |
| 45 | + false, |
| 46 | + ], |
| 47 | + 'case_5' => [ |
| 48 | + [1, 2, 3, 4], |
| 49 | + fn($el) => $el === 0, |
| 50 | + CALLBACK_USE_VALUE, |
| 51 | + true, |
| 52 | + ], |
| 53 | + 'case_6' => [ |
| 54 | + [1, 2, 3, 4], |
| 55 | + fn($key) => is_string($key), |
| 56 | + CALLBACK_USE_KEY, |
| 57 | + true, |
| 58 | + ], |
| 59 | + 'case_6_1' => [ |
| 60 | + [1, 2, 3, 4, 'a' => 5], |
| 61 | + fn($key) => is_string($key), |
| 62 | + CALLBACK_USE_KEY, |
| 63 | + false, |
| 64 | + ], |
| 65 | + 'case_7' => [ |
| 66 | + ['a' => 1, 'b' => 2, 'c' => 3, 4], |
| 67 | + fn($v, $key) => is_integer($key) && is_integer($v), |
| 68 | + CALLBACK_USE_BOTH, |
| 69 | + false, |
| 70 | + ] |
| 71 | + ]; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @param iterable $items |
| 76 | + * @param callable $callback |
| 77 | + * @param int $mode |
| 78 | + * @param bool $expected |
| 79 | + * @return void |
| 80 | + * @dataProvider noneProvider |
| 81 | + */ |
| 82 | + public function testNone(iterable $items, callable $callback, int $mode, bool $expected): void |
| 83 | + { |
| 84 | + $actual = none($items, $callback, $mode); |
| 85 | + $this->assertEquals($expected, $actual); |
| 86 | + } |
| 87 | +} |
0 commit comments