public function testMap() { // from js $this->assertEquals(array(2, 4, 6), __u::map(array(1, 2, 3), function ($num) { return $num * 2; }), 'doubled numbers'); $ifnull = __u::map(null, function () { }); $this->assertTrue(is_array($ifnull) && count($ifnull) === 0, 'handles a null property'); $multiplier = 3; $func = function ($num) use($multiplier) { return $num * $multiplier; }; $tripled = __u::map(array(1, 2, 3), $func); $this->assertEquals(array(3, 6, 9), $tripled); $doubled = __u(array(1, 2, 3))->map(function ($num) { return $num * 2; }); $this->assertEquals(array(2, 4, 6), $doubled, 'OO-style doubled numbers'); $this->assertEquals(array(2, 4, 6), __u::map(array(1, 2, 3), function ($n) { return $n * 2; })); $this->assertEquals(array(2, 4, 6), __u(array(1, 2, 3))->map(function ($n) { return $n * 2; })); $doubled = __u::collect(array(1, 2, 3), function ($num) { return $num * 2; }); $this->assertEquals(array(2, 4, 6), $doubled, 'aliased as "collect"'); // docs $this->assertEquals(array(3, 6, 9), __u::map(array(1, 2, 3), function ($num) { return $num * 3; })); $this->assertEquals(array(3, 6, 9), __u::map(array('one' => 1, 'two' => 2, 'three' => 3), function ($num, $key) { return $num * 3; })); }