public function testWrap() { // from js $greet = function ($name) { return 'hi: ' . $name; }; $backwards = __::wrap($greet, function ($func, $name) { return $func($name) . ' ' . strrev($name); }); $this->assertEquals('hi: moe eom', $backwards('moe'), 'wrapped the salutation function'); $inner = function () { return 'Hello '; }; $arr = array('name' => 'Moe'); $arr['hi'] = __::wrap($inner, function ($fn) use($arr) { return $fn() . $arr['name']; }); $this->assertEquals('Hello Moe', $arr['hi']()); $noop = function () { }; $wrapped = __::wrap($noop, function ($fn) { return func_get_args(); }); $ret = $wrapped(array('whats', 'your'), 'vector', 'victor'); $this->assertEquals(array($noop, array('whats', 'your'), 'vector', 'victor'), $ret); // docs $hello = function ($name) { return 'hello: ' . $name; }; $hi = __::wrap($hello, function ($func) { return 'before, ' . $func('moe') . ', after'; }); $this->assertEquals('before, hello: moe, after', $hi()); }