Exemple #1
0
 public function testFail()
 {
     $results = array();
     $doneCallback = function ($result) use(&$results) {
         $results[] = $result;
     };
     $reasons = array();
     $failCallback = function ($reason) use(&$reasons) {
         $reasons[] = $reason;
     };
     $promise1 = new Promise();
     $promise2 = new Promise();
     $promise3 = new Promise();
     $promise4 = new Promise();
     $when = new When(array($promise1, $promise2, $promise3, $promise4));
     $when->done($doneCallback);
     $when->fail($failCallback);
     $promise1->resolve('foo');
     $promise2->reject('bar');
     $promise3->reject('foobar');
     $promise4->resolve('barfoo');
     $this->assertCount(0, $results);
     $this->assertCount(1, $reasons);
     $this->assertSame(array('bar'), $reasons);
 }
Exemple #2
0
 /**
  * Starts a process and returns a promise
  *
  * @param Process $process
  *
  * @return Promise
  */
 public function start(Process $process)
 {
     $promise = new Promise();
     $process->start(function ($type, $update) use($promise) {
         $promise->notify($update, $type);
     });
     $this->promises[] = $promise;
     $this->prosesses[] = $process;
     return $promise;
 }
 public function testState()
 {
     $promise1 = new Promise();
     $promise2 = new Promise();
     $promise3 = new Promise();
     $promise2->resolve('foo');
     $promise3->reject('bar');
     $this->assertSame(Promise::STATE_PENDING, $promise1->state());
     $this->assertSame(Promise::STATE_RESOLVED, $promise2->state());
     $this->assertSame(Promise::STATE_REJECTED, $promise3->state());
     $this->assertFalse($promise1->isResolved());
     $this->assertFalse($promise1->isRejected());
     $this->assertTrue($promise2->isResolved());
     $this->assertFalse($promise2->isRejected());
     $this->assertFalse($promise3->isResolved());
     $this->assertTrue($promise3->isRejected());
 }