when(function () { }); $promise->when(function () { }); $promise->when(function () use (&$invoked) { $invoked = true; $this->assertLessThan(30, count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); }); $last = $promise; $f = function () use (&$f, &$count, &$last) { $p = new Promise; $p->when(function () { }); $p->when(function () { }); $last->resolve($p); $last = $p; if (--$count > 0) { $f(); } }; $f(); $last->resolve(); $this->assertTrue($invoked); } }