/**
  * @param PromiseInterface $promise
  */
 protected function chainingTest(PromiseInterface $promise)
 {
     $this->given($deferred = new Deferred(), $onFulfilled = $this->delegateMockWithReturn($deferred->promise()))->when($thenPromise = $promise->then($onFulfilled))->then()->boolean($thenPromise->state()->equals(State::PENDING()))->isTrue();
     $this->given($onFulfilledThen = $this->delegateMock(), $onNotify = $this->delegateMock())->when(function () use($deferred, $thenPromise, $onFulfilledThen, $onNotify) {
         $thenPromise->then($onFulfilledThen, null, $onNotify);
         $deferred->notify('state');
         $deferred->resolve('bar');
     })->then()->delegateCall($onNotify)->withArguments('state')->once()->delegateCall($onFulfilledThen)->withArguments('bar')->once();
     $this->given($onFulfilled = $this->delegateMockWithReturn(new RejectedPromise($this->defaultRejectReason())), $onRejectedThen = $this->delegateMock())->when($promise->then($onFulfilled)->then(null, $onRejectedThen))->then()->delegateCall($onRejectedThen)->withArguments($this->defaultRejectReason())->once();
 }
 /**
  * {@inheritdoc}
  */
 public function testResolve()
 {
     parent::testResolve();
     $this->given($deferred = new Deferred(), $onFulfilled = $this->delegateMockWithReturn($deferred->promise()), $resolver = $this->newTestedInstance($onFulfilled), $onFulfilledPromise = $this->delegateMock(), $onNotifyPromise = $this->delegateMock())->when(function () use($resolver, $onFulfilledPromise, $onNotifyPromise) {
         $resolver->resolve();
         $resolver->promise()->then($onFulfilledPromise, null, $onNotifyPromise);
     })->then()->delegateCall($onFulfilledPromise)->never()->delegateCall($onNotifyPromise)->never();
     $this->when($deferred->notify('state'))->then()->delegateCall($onNotifyPromise)->withArguments('state')->once();
     $this->when($deferred->resolve('foo'))->then()->delegateCall($onFulfilledPromise)->withArguments('foo')->once();
     $this->given($reason = new \Exception(), $onFulfilled = $this->delegateMockWithReturn(new RejectedPromise($reason)), $resolver = $this->newTestedInstance($onFulfilled), $onRejectedPromise = $this->delegateMock())->when(function () use($resolver, $onRejectedPromise) {
         $resolver->resolve();
         $resolver->promise()->then(null, $onRejectedPromise);
     })->then()->delegateCall($onRejectedPromise)->withArguments($reason)->once();
 }