public function testAfter() { // from js $testAfter = function ($afterAmount, $timesCalled) { $afterCalled = 0; $after = __u::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'); // extra $testAfterAgain = function ($afterAmount, $timesCalled) { $afterCalled = 0; $after = __u($afterAmount)->after(function () use(&$afterCalled) { $afterCalled++; }); while ($timesCalled--) { $after(); } return $afterCalled; }; $this->assertEquals(1, $testAfterAgain(5, 5), 'after(N) should fire after being called N times in OO-style call'); $this->assertEquals(0, $testAfterAgain(5, 4), 'after(N) should not fire unless called N times in OO-style call'); // docs $str = ''; $func = __u::after(3, function () use(&$str) { $str = 'x'; }); $func(); $func(); $func(); $this->assertEquals('x', $str); }