Skip to content

Commit 234121c

Browse files
committed
Use When methods in tests instead of direct promise instances
1 parent 9e9f215 commit 234121c

8 files changed

Lines changed: 43 additions & 69 deletions

File tree

tests/React/Promise/UtilPromiseForTest.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,34 +65,4 @@ public function shouldRejectARejectedPromise()
6565
$mock
6666
);
6767
}
68-
69-
/** @test */
70-
public function shouldSupportDeepNestingInPromiseChains()
71-
{
72-
$d = new Deferred();
73-
$d->resolve(false);
74-
75-
$result = Util::promiseFor(Util::promiseFor($d->then(function ($val) {
76-
$d = new Deferred();
77-
$d->resolve($val);
78-
79-
$identity = function ($val) {
80-
return $val;
81-
};
82-
83-
return Util::promiseFor($d->then($identity))->then(
84-
function ($val) {
85-
return !$val;
86-
}
87-
);
88-
})));
89-
90-
$mock = $this->createCallableMock();
91-
$mock
92-
->expects($this->once())
93-
->method('__invoke')
94-
->with($this->identicalTo(true));
95-
96-
$result->then($mock);
97-
}
9868
}

tests/React/Promise/WhenAllTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function shouldResolvePromisesArray()
4545
->with($this->identicalTo(array(1, 2, 3)));
4646

4747
When::all(
48-
array(new FulfilledPromise(1), new FulfilledPromise(2), new FulfilledPromise(3)),
48+
array(When::resolve(1), When::resolve(2), When::resolve(3)),
4949
$mock
5050
);
5151
}
@@ -75,7 +75,7 @@ public function shouldRejectIfAnyInputPromiseRejects()
7575
->with($this->identicalTo(2));
7676

7777
When::all(
78-
array(new FulfilledPromise(1), new RejectedPromise(2), new FulfilledPromise(3)),
78+
array(When::resolve(1), When::reject(2), When::resolve(3)),
7979
$this->expectCallableNever(),
8080
$mock
8181
);
@@ -91,7 +91,7 @@ public function shouldAcceptAPromiseForAnArray()
9191
->with($this->identicalTo(array(1, 2, 3)));
9292

9393
When::all(
94-
new FulfilledPromise(array(1, 2, 3)),
94+
When::resolve(array(1, 2, 3)),
9595
$mock
9696
);
9797
}
@@ -106,7 +106,7 @@ public function shouldResolveToEmptyArrayWhenInputPromiseDoesNotResolveToArray()
106106
->with($this->identicalTo(array()));
107107

108108
When::all(
109-
new FulfilledPromise(1),
109+
When::resolve(1),
110110
$mock
111111
);
112112
}

tests/React/Promise/WhenAnyTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function shouldResolveWithAPromisedInputValue()
4545
->with($this->identicalTo(1));
4646

4747
When::any(
48-
array(new FulfilledPromise(1), new FulfilledPromise(2), new FulfilledPromise(3)),
48+
array(When::resolve(1), When::resolve(2), When::resolve(3)),
4949
$mock
5050
);
5151
}
@@ -60,7 +60,7 @@ public function shouldRejectWithAllRejectedInputValuesIfAllInputsAreRejected()
6060
->with($this->identicalTo(array(0 => 1, 1 => 2, 2 => 3)));
6161

6262
When::any(
63-
array(new RejectedPromise(1), new RejectedPromise(2), new RejectedPromise(3)),
63+
array(When::reject(1), When::reject(2), When::reject(3)),
6464
$this->expectCallableNever(),
6565
$mock
6666
);
@@ -76,7 +76,7 @@ public function shouldResolveWhenFirstInputPromiseResolves()
7676
->with($this->identicalTo(1));
7777

7878
When::any(
79-
array(new FulfilledPromise(1), new RejectedPromise(2), new RejectedPromise(3)),
79+
array(When::resolve(1), When::reject(2), When::reject(3)),
8080
$mock
8181
);
8282
}
@@ -91,7 +91,7 @@ public function shouldAcceptAPromiseForAnArray()
9191
->with($this->identicalTo(1));
9292

9393
When::any(
94-
new FulfilledPromise(array(1, 2, 3)),
94+
When::resolve(array(1, 2, 3)),
9595
$mock
9696
);
9797
}
@@ -106,7 +106,7 @@ public function shouldResolveToNullArrayWhenInputPromiseDoesNotResolveToArray()
106106
->with($this->identicalTo(null));
107107

108108
When::any(
109-
new FulfilledPromise(1),
109+
When::resolve(1),
110110
$mock
111111
);
112112
}

tests/React/Promise/WhenMapTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function mapper()
1818
protected function promiseMapper()
1919
{
2020
return function ($val) {
21-
return new FulfilledPromise($val * 2);
21+
return When::resolve($val * 2);
2222
};
2323
}
2424

@@ -47,7 +47,7 @@ public function shouldMapInputPromisesArray()
4747
->with($this->identicalTo(array(2, 4, 6)));
4848

4949
When::map(
50-
array(new FulfilledPromise(1), new FulfilledPromise(2), new FulfilledPromise(3)),
50+
array(When::resolve(1), When::resolve(2), When::resolve(3)),
5151
$this->mapper()
5252
)->then($mock);
5353
}
@@ -62,7 +62,7 @@ public function shouldMapMixedInputArray()
6262
->with($this->identicalTo(array(2, 4, 6)));
6363

6464
When::map(
65-
array(1, new FulfilledPromise(2), 3),
65+
array(1, When::resolve(2), 3),
6666
$this->mapper()
6767
)->then($mock);
6868
}
@@ -92,7 +92,7 @@ public function shouldAcceptAPromiseForAnArray()
9292
->with($this->identicalTo(array(2, 4, 6)));
9393

9494
When::map(
95-
new FulfilledPromise(array(1, new FulfilledPromise(2), 3)),
95+
When::resolve(array(1, When::resolve(2), 3)),
9696
$this->mapper()
9797
)->then($mock);
9898
}
@@ -107,7 +107,7 @@ public function shouldResolveToEmptyArrayWhenInputPromiseDoesNotResolveToArray()
107107
->with($this->identicalTo(array()));
108108

109109
When::map(
110-
new FulfilledPromise(1),
110+
When::resolve(1),
111111
$this->mapper()
112112
)->then($mock);
113113
}
@@ -122,7 +122,7 @@ public function shouldRejectWhenInputContainsRejection()
122122
->with($this->identicalTo(2));
123123

124124
When::map(
125-
array(new FulfilledPromise(1), new RejectedPromise(2), new FulfilledPromise(3)),
125+
array(When::resolve(1), When::reject(2), When::resolve(3)),
126126
$this->mapper()
127127
)->then($this->expectCallableNever(), $mock);
128128
}

tests/React/Promise/WhenReduceTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function shouldReduceValuesWithInitialPromise()
6565
When::reduce(
6666
array(1, 2, 3),
6767
$this->plus(),
68-
new FulfilledPromise(1)
68+
When::resolve(1)
6969
)->then($mock);
7070
}
7171

@@ -79,7 +79,7 @@ public function shouldReducePromisedValuesWithoutInitialValue()
7979
->with($this->identicalTo(6));
8080

8181
When::reduce(
82-
array(new FulfilledPromise(1), new FulfilledPromise(2), new FulfilledPromise(3)),
82+
array(When::resolve(1), When::resolve(2), When::resolve(3)),
8383
$this->plus()
8484
)->then($mock);
8585
}
@@ -94,7 +94,7 @@ public function shouldReducePromisedValuesWithInitialValue()
9494
->with($this->identicalTo(7));
9595

9696
When::reduce(
97-
array(new FulfilledPromise(1), new FulfilledPromise(2), new FulfilledPromise(3)),
97+
array(When::resolve(1), When::resolve(2), When::resolve(3)),
9898
$this->plus(),
9999
1
100100
)->then($mock);
@@ -110,9 +110,9 @@ public function shouldReducePromisedValuesWithInitialPromise()
110110
->with($this->identicalTo(7));
111111

112112
When::reduce(
113-
array(new FulfilledPromise(1), new FulfilledPromise(2), new FulfilledPromise(3)),
113+
array(When::resolve(1), When::resolve(2), When::resolve(3)),
114114
$this->plus(),
115-
new FulfilledPromise(1)
115+
When::resolve(1)
116116
)->then($mock);
117117
}
118118

@@ -144,7 +144,7 @@ public function shouldReduceEmptyInputWithInitialPromise()
144144
When::reduce(
145145
array(),
146146
$this->plus(),
147-
new FulfilledPromise(1)
147+
When::resolve(1)
148148
)->then($mock);
149149
}
150150

@@ -158,9 +158,9 @@ public function shouldRejectWhenInputContainsRejection()
158158
->with($this->identicalTo(2));
159159

160160
When::reduce(
161-
array(new FulfilledPromise(1), new RejectedPromise(2), new FulfilledPromise(3)),
161+
array(When::resolve(1), When::reject(2), When::resolve(3)),
162162
$this->plus(),
163-
new FulfilledPromise(1)
163+
When::resolve(1)
164164
)->then($this->expectCallableNever(), $mock);
165165
}
166166

@@ -240,7 +240,7 @@ public function shouldAcceptAPromiseForAnArray()
240240
->with($this->identicalTo('123'));
241241

242242
When::reduce(
243-
new FulfilledPromise(array(1, 2, 3)),
243+
When::resolve(array(1, 2, 3)),
244244
$this->append(),
245245
''
246246
)->then($mock);
@@ -256,7 +256,7 @@ public function shouldResolveToInitialValueWhenInputPromiseDoesNotResolveToAnArr
256256
->with($this->identicalTo(1));
257257

258258
When::reduce(
259-
new FulfilledPromise(1),
259+
When::resolve(1),
260260
$this->plus(),
261261
1
262262
)->then($mock);

tests/React/Promise/WhenRejectTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ public function shouldRejectAnImmediateValue()
2727
}
2828

2929
/** @test */
30-
public function shouldRejectAFulfilledPromise()
30+
public function shouldRejectAResolvedPromise()
3131
{
3232
$expected = 123;
3333

34-
$resolved = new FulfilledPromise($expected);
34+
$d = new Deferred();
35+
$d->resolve($expected);
3536

3637
$mock = $this->createCallableMock();
3738
$mock
3839
->expects($this->once())
3940
->method('__invoke')
4041
->with($this->identicalTo($expected));
4142

42-
When::reject($resolved)
43+
When::reject($d->promise())
4344
->then(
4445
$this->expectCallableNever(),
4546
$mock
@@ -51,15 +52,16 @@ public function shouldRejectARejectedPromise()
5152
{
5253
$expected = 123;
5354

54-
$resolved = new RejectedPromise($expected);
55+
$d = new Deferred();
56+
$d->reject($expected);
5557

5658
$mock = $this->createCallableMock();
5759
$mock
5860
->expects($this->once())
5961
->method('__invoke')
6062
->with($this->identicalTo($expected));
6163

62-
When::reject($resolved)
64+
When::reject($d->promise())
6365
->then(
6466
$this->expectCallableNever(),
6567
$mock

tests/React/Promise/WhenResolveTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ public function shouldResolveAnImmediateValue()
2727
}
2828

2929
/** @test */
30-
public function shouldResolveAFulfilledPromise()
30+
public function shouldResolveAResolvedPromise()
3131
{
3232
$expected = 123;
3333

34-
$resolved = new FulfilledPromise($expected);
34+
$d = new Deferred();
35+
$d->resolve($expected);
3536

3637
$mock = $this->createCallableMock();
3738
$mock
3839
->expects($this->once())
3940
->method('__invoke')
4041
->with($this->identicalTo($expected));
4142

42-
When::resolve($resolved)
43+
When::resolve($d->promise())
4344
->then(
4445
$mock,
4546
$this->expectCallableNever()
@@ -51,15 +52,16 @@ public function shouldRejectARejectedPromise()
5152
{
5253
$expected = 123;
5354

54-
$resolved = new RejectedPromise($expected);
55+
$d = new Deferred();
56+
$d->reject($expected);
5557

5658
$mock = $this->createCallableMock();
5759
$mock
5860
->expects($this->once())
5961
->method('__invoke')
6062
->with($this->identicalTo($expected));
6163

62-
When::resolve($resolved)
64+
When::resolve($d->promise())
6365
->then(
6466
$this->expectCallableNever(),
6567
$mock

tests/React/Promise/WhenSomeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function shouldResolvePromisesArray()
4646
->with($this->identicalTo(array(1, 2)));
4747

4848
When::some(
49-
array(new FulfilledPromise(1), new FulfilledPromise(2), new FulfilledPromise(3)),
49+
array(When::resolve(1), When::resolve(2), When::resolve(3)),
5050
2,
5151
$mock
5252
);
@@ -78,7 +78,7 @@ public function shouldRejectIfAnyInputPromiseRejectsBeforeDesiredNumberOfInputsA
7878
->with($this->identicalTo(array(1 => 2, 2 => 3)));
7979

8080
When::some(
81-
array(new FulfilledPromise(1), new RejectedPromise(2), new RejectedPromise(3)),
81+
array(When::resolve(1), When::reject(2), When::reject(3)),
8282
2,
8383
$this->expectCallableNever(),
8484
$mock
@@ -95,7 +95,7 @@ public function shouldAcceptAPromiseForAnArray()
9595
->with($this->identicalTo(array(1, 2)));
9696

9797
When::some(
98-
new FulfilledPromise(array(1, 2, 3)),
98+
When::resolve(array(1, 2, 3)),
9999
2,
100100
$mock
101101
);
@@ -111,7 +111,7 @@ public function shouldResolveToEmptyArrayWhenInputPromiseDoesNotResolveToArray()
111111
->with($this->identicalTo(array()));
112112

113113
When::some(
114-
new FulfilledPromise(1),
114+
When::resolve(1),
115115
1,
116116
$mock
117117
);

0 commit comments

Comments
 (0)