Jyxo\Spl\ArrayUtilTest::testKeymap PHP Method

testKeymap() public method

Tests the keymap() method.
public testKeymap ( )
    public function testKeymap()
    {
        $source = [];
        foreach (range(ord('a'), ord('z')) as $value) {
            $source[] = chr($value);
        }
        $traversable = new \ArrayIterator($source);
        $closure = function ($value) {
            return chr(ord('z') + ord('a') - ord($value));
        };
        $mapped = ArrayUtil::keymap($traversable, $closure);
        $this->assertSame(array_combine(array_reverse($source), $source), $mapped);
        $mapped = ArrayUtil::keymap($traversable, $closure, $closure);
        $this->assertSame(array_reverse(array_combine($source, $source)), $mapped);
    }