Kraken\_Unit\Runtime\RuntimeModelTest::testApiCreate_CallsStartAndRejectsPromise_WhenInvokedFromStateOtherThanCreatedOrDestroyedAndStartFailed PHP Method

testApiCreate_CallsStartAndRejectsPromise_WhenInvokedFromStateOtherThanCreatedOrDestroyedAndStartFailed() public method

    public function testApiCreate_CallsStartAndRejectsPromise_WhenInvokedFromStateOtherThanCreatedOrDestroyedAndStartFailed()
    {
        $states = [Runtime::STATE_DESTROYED];
        $loop = $this->getMock(Loop::class, [], [], '', false);
        $loop->expects($this->once())->method('onTick')->will($this->returnCallback(function ($callable) {
            $callable();
        }));
        $events = [];
        $emitter = $this->getMock(EventEmitter::class, [], [], '', false);
        $emitter->expects($this->exactly(3))->method('emit')->will($this->returnCallback(function ($event) use(&$events) {
            $events[] = $event;
        }));
        $runtime = $this->createModel([], ['getLoop', 'start', 'getEventEmitter', 'setLoopState', 'startLoop']);
        $runtime->expects($this->once())->method('getLoop')->will($this->returnValue($loop));
        $runtime->expects($this->once())->method('start')->will($this->returnValue(new PromiseRejected($ex = new Exception())));
        $runtime->expects($this->once())->method('getEventEmitter')->will($this->returnValue($emitter));
        $runtime->expects($this->once())->method('setLoopState');
        $runtime->expects($this->once())->method('startLoop');
        foreach ($states as $state) {
            $runtime->setState($state);
            $callable = $this->createCallableMock();
            $callable->expects($this->once())->method('__invoke')->with($ex);
            $runtime->create()->then($this->expectCallableNever(), $callable);
            $this->assertSame(['beforeCreate', 'create', 'afterCreate'], $events);
        }
    }
RuntimeModelTest