@@ 57-81 (lines=25) @@ | ||
54 | /** |
|
55 | * Test resolve. |
|
56 | */ |
|
57 | public function testResolve() |
|
58 | { |
|
59 | $this |
|
60 | ->given( |
|
61 | /** @var \Cubiche\Core\Async\Promise\DeferredInterface $deferred */ |
|
62 | $deferred = $this->newDefaultTestedInstance(), |
|
63 | $value = 'foo' |
|
64 | ) |
|
65 | ->when($deferred->resolve($value)) |
|
66 | ->then() |
|
67 | ->boolean($deferred->promise()->state()->equals(State::FULFILLED())) |
|
68 | ->isTrue() |
|
69 | ; |
|
70 | ||
71 | $this |
|
72 | ->given($onFulfilled = $this->delegateMock()) |
|
73 | ->when($deferred->promise()->then($onFulfilled)) |
|
74 | ->then() |
|
75 | ->delegateCall($onFulfilled) |
|
76 | ->withArguments($value) |
|
77 | ->once() |
|
78 | ; |
|
79 | ||
80 | $this->invalidActionTest($deferred); |
|
81 | } |
|
82 | ||
83 | /** |
|
84 | * Test reject. |
|
@@ 86-110 (lines=25) @@ | ||
83 | /** |
|
84 | * Test reject. |
|
85 | */ |
|
86 | public function testReject() |
|
87 | { |
|
88 | $this |
|
89 | ->given( |
|
90 | /** @var \Cubiche\Core\Async\Promise\DeferredInterface $deferred */ |
|
91 | $deferred = $this->newDefaultTestedInstance(), |
|
92 | $reason = new \Exception() |
|
93 | ) |
|
94 | ->when($deferred->reject($reason)) |
|
95 | ->then() |
|
96 | ->boolean($deferred->promise()->state()->equals(State::REJECTED())) |
|
97 | ->isTrue() |
|
98 | ; |
|
99 | ||
100 | $this |
|
101 | ->given($onRejected = $this->delegateMock()) |
|
102 | ->when($deferred->promise()->then(null, $onRejected)) |
|
103 | ->then() |
|
104 | ->delegateCall($onRejected) |
|
105 | ->withArguments($reason) |
|
106 | ->once() |
|
107 | ; |
|
108 | ||
109 | $this->invalidActionTest($deferred); |
|
110 | } |
|
111 | ||
112 | /** |
|
113 | * Test notify. |
@@ 85-110 (lines=26) @@ | ||
82 | /** |
|
83 | * Test __construct. |
|
84 | */ |
|
85 | public function testConstruct() |
|
86 | { |
|
87 | $this |
|
88 | ->given( |
|
89 | $resolve = $this->delegateMock(), |
|
90 | $reject = $this->delegateMock(), |
|
91 | $notify = $this->delegateMock() |
|
92 | ) |
|
93 | ->when($this->newTestedInstance($resolve, $reject, $notify)) |
|
94 | ->then() |
|
95 | ->delegateCall($resolve) |
|
96 | ->once() |
|
97 | ->delegateCall($reject) |
|
98 | ->once() |
|
99 | ->delegateCall($notify) |
|
100 | ->once() |
|
101 | ; |
|
102 | ||
103 | $this |
|
104 | /* @var \Cubiche\Core\Async\Promise\PromiseInterface $promise */ |
|
105 | ->given($promise = $this->newDefaultTestedInstance()) |
|
106 | ->then() |
|
107 | ->boolean($promise->state()->equals(State::PENDING())) |
|
108 | ->isTrue() |
|
109 | ; |
|
110 | } |
|
111 | ||
112 | /** |
|
113 | * Test notify. |