unregisterAll(); $plugin = $this->getPlugin(); $classes = self::EXPECTED_ORDER; shuffle($classes); foreach($classes as $class){ $plugin->getServer()->getPluginManager()->registerAsyncEvent( $class, function(AsyncEvent $event) use ($class) : ?Promise{ $this->callOrder[] = $class; return null; }, EventPriority::NORMAL, $plugin ); } $event = new GrandchildAsyncEvent(); $promise = $event->call(); $promise->onCompletion(onSuccess: $this->collectResults(...), onFailure: $this->collectResults(...)); } private function collectResults() : void{ if($this->callOrder === self::EXPECTED_ORDER){ $this->setResult(Test::RESULT_OK); }else{ $this->getPlugin()->getLogger()->error("Expected order: " . implode(", ", self::EXPECTED_ORDER) . ", got: " . implode(", ", $this->callOrder)); $this->setResult(Test::RESULT_FAILED); } } }