Kraken\_Module\Runtime\RuntimeModelTest::testApiCreate_BehavesAsIntended PHP Method

testApiCreate_BehavesAsIntended() public method

    public function testApiCreate_BehavesAsIntended()
    {
        $core = $this->createCore();
        $emitter = $this->createEmitter();
        $loop = $this->createLoop();
        $model = $this->createModel($core, $emitter);
        $events = [];
        $addEvent = function ($name) use(&$events) {
            $events[] = $name;
        };
        $awaitEvent = function ($name) use($emitter, $addEvent) {
            $emitter->on($name, function () use($name, $addEvent) {
                $addEvent($name);
            });
        };
        $awaitEvent('beforeCreate');
        $awaitEvent('create');
        $awaitEvent('afterCreate');
        $awaitEvent('beforeStart');
        $awaitEvent('start');
        $awaitEvent('afterStart');
        $emitter->once('create', function () use($loop) {
            $loop->stop();
        });
        $model->setState(Runtime::STATE_DESTROYED);
        $model->setLoop($loop);
        $model->create()->then($this->expectCallableOnce());
        $this->assertSame(Runtime::STATE_STARTED, $model->getState());
        $this->assertSame(['beforeCreate', 'create', 'afterCreate', 'beforeStart', 'start', 'afterStart'], $events);
        unset($loop);
        unset($model);
        unset($emitter);
        unset($core);
    }