public function testAfter() { // from js $testAfter = function ($afterAmount, $timesCalled) { $afterCalled = 0; $after = __::after($afterAmount, function () use(&$afterCalled) { $afterCalled++; }); while ($timesCalled--) { $after(); } return $afterCalled; }; $this->assertEquals(1, $testAfter(5, 5), 'after(N) should fire after being called N times'); $this->assertEquals(0, $testAfter(5, 4), 'after(N) should not fire unless called N times'); $this->assertEquals(1, $testAfter(0, 0), 'after(0) should fire immediately'); // docs $str = ''; $func = __::after(3, function () use(&$str) { $str = 'x'; }); $func(); $func(); $func(); $this->assertEquals('x', $str); }