|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @package Functional-php |
| 5 | + * @author Lars Strojny <lstrojny@php.net> |
| 6 | + * @copyright 2011-2017 Lars Strojny |
| 7 | + * @license https://opensource.org/licenses/MIT MIT |
| 8 | + * @link https://github.com/lstrojny/functional-php |
| 9 | + */ |
| 10 | + |
| 11 | +namespace Functional\Tests; |
| 12 | + |
| 13 | +use ArrayIterator; |
| 14 | + |
| 15 | +use function Functional\omit_keys; |
| 16 | + |
| 17 | +class OmitKeysTest extends AbstractTestCase |
| 18 | +{ |
| 19 | + public static function getData() |
| 20 | + { |
| 21 | + return [ |
| 22 | + [['foo' => 1], ['foo' => 1], []], |
| 23 | + [['foo' => 1], ['foo' => 1], ['bar']], |
| 24 | + [[], ['foo' => 1], ['foo']], |
| 25 | + [[], ['foo' => 1, 'bar' => 2], ['foo', 'bar']], |
| 26 | + [['bar' => 2], ['foo' => 1, 'bar' => 2], ['foo']], |
| 27 | + [[1 => 'b'], ['a', 'b', 'c'], [0, 2]], |
| 28 | + ]; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @dataProvider getData |
| 33 | + */ |
| 34 | + public function test(array $expected, array $input, array $keys) |
| 35 | + { |
| 36 | + $this->assertSame($expected, omit_keys($input, $keys)); |
| 37 | + $this->assertSame($expected, omit_keys(new ArrayIterator($input), $keys)); |
| 38 | + } |
| 39 | + |
| 40 | + public function testPassNonArrayOrTraversable() |
| 41 | + { |
| 42 | + $this->expectArgumentError("Functional\omit_keys() expects parameter 1 to be array or instance of Traversable"); |
| 43 | + omit_keys(new \stdclass(), []); |
| 44 | + } |
| 45 | +} |
0 commit comments