Skip to content

Commit 57e873c

Browse files
committed
Merge branch 'master' into enforce-exception-reasons
2 parents 060b245 + d726517 commit 57e873c

16 files changed

+66
-206
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
React/Promise
2-
=============
1+
Promise
2+
=======
33

44
A lightweight implementation of
55
[CommonJS Promises/A](http://wiki.commonjs.org/wiki/Promises/A) for PHP.
@@ -56,7 +56,7 @@ Table of Contents
5656
Introduction
5757
------------
5858

59-
React/Promise is a library implementing
59+
Promise is a library implementing
6060
[CommonJS Promises/A](http://wiki.commonjs.org/wiki/Promises/A) for PHP.
6161

6262
It also provides several other useful promise-related concepts, such as joining
@@ -710,7 +710,7 @@ getJsonResult()
710710
Credits
711711
-------
712712

713-
React/Promise is a port of [when.js](https://github.com/cujojs/when)
713+
Promise is a port of [when.js](https://github.com/cujojs/when)
714714
by [Brian Cavalier](https://github.com/briancavalier).
715715

716716
Also, large parts of the documentation have been ported from the when.js
@@ -720,4 +720,4 @@ Also, large parts of the documentation have been ported from the when.js
720720
License
721721
-------
722722

723-
React/Promise is released under the [MIT](https://github.com/reactphp/promise/blob/master/LICENSE) license.
723+
Released under the [MIT](LICENSE) license.

src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function all(array $promisesOrValues)
4040
function race(array $promisesOrValues)
4141
{
4242
if (!$promisesOrValues) {
43-
return new Promise(function() {});
43+
return new Promise(function () {});
4444
}
4545

4646
$cancellationQueue = new Internal\CancellationQueue();

tests/FunctionAnyTest.php

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function shouldRejectWithLengthExceptionWithEmptyInputArray()
1515
->expects($this->once())
1616
->method('__invoke')
1717
->with(
18-
$this->callback(function($exception){
18+
$this->callback(function ($exception) {
1919
return $exception instanceof LengthException &&
2020
'Input array must contain at least 1 item but contains only 0 items.' === $exception->getMessage();
2121
})
@@ -110,42 +110,20 @@ public function shouldNotRelyOnArryIndexesWhenUnwrappingToASingleResolutionValue
110110
/** @test */
111111
public function shouldCancelInputArrayPromises()
112112
{
113-
$mock1 = $this
114-
->getMockBuilder('React\Promise\PromiseInterface')
115-
->getMock();
116-
$mock1
117-
->expects($this->once())
118-
->method('cancel');
119-
120-
$mock2 = $this
121-
->getMockBuilder('React\Promise\PromiseInterface')
122-
->getMock();
123-
$mock2
124-
->expects($this->once())
125-
->method('cancel');
113+
$promise1 = new Promise(function () {}, $this->expectCallableOnce());
114+
$promise2 = new Promise(function () {}, $this->expectCallableOnce());
126115

127-
any([$mock1, $mock2])->cancel();
116+
any([$promise1, $promise2])->cancel();
128117
}
129118

130119
/** @test */
131120
public function shouldNotCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()
132121
{
133-
$mock = $this->createCallableMock();
134-
$mock
135-
->expects($this->never())
136-
->method('__invoke');
137-
138-
139-
$deferred = New Deferred($mock);
122+
$deferred = new Deferred($this->expectCallableNever());
140123
$deferred->resolve();
141124

142-
$mock2 = $this
143-
->getMockBuilder('React\Promise\PromiseInterface')
144-
->getMock();
145-
$mock2
146-
->expects($this->never())
147-
->method('cancel');
125+
$promise2 = new Promise(function () {}, $this->expectCallableNever());
148126

149-
some([$deferred->promise(), $mock2], 1)->cancel();
127+
some([$deferred->promise(), $promise2], 1)->cancel();
150128
}
151129
}

tests/FunctionCheckTypehintTest.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,36 @@ class FunctionCheckTypehintTest extends TestCase
77
/** @test */
88
public function shouldAcceptClosureCallbackWithTypehint()
99
{
10-
$this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) {
11-
}, new \InvalidArgumentException()));
12-
$this->assertfalse(_checkTypehint(function (\InvalidArgumentException $e) {
13-
}, new \Exception()));
10+
$this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) {}, new \InvalidArgumentException()));
11+
$this->assertFalse(_checkTypehint(function (\InvalidArgumentException $e) {}, new \Exception()));
1412
}
1513

1614
/** @test */
1715
public function shouldAcceptFunctionStringCallbackWithTypehint()
1816
{
1917
$this->assertTrue(_checkTypehint('React\Promise\testCallbackWithTypehint', new \InvalidArgumentException()));
20-
$this->assertfalse(_checkTypehint('React\Promise\testCallbackWithTypehint', new \Exception()));
18+
$this->assertFalse(_checkTypehint('React\Promise\testCallbackWithTypehint', new \Exception()));
2119
}
2220

2321
/** @test */
2422
public function shouldAcceptInvokableObjectCallbackWithTypehint()
2523
{
2624
$this->assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new \InvalidArgumentException()));
27-
$this->assertfalse(_checkTypehint(new TestCallbackWithTypehintClass(), new \Exception()));
25+
$this->assertFalse(_checkTypehint(new TestCallbackWithTypehintClass(), new \Exception()));
2826
}
2927

3028
/** @test */
3129
public function shouldAcceptObjectMethodCallbackWithTypehint()
3230
{
3331
$this->assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \InvalidArgumentException()));
34-
$this->assertfalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \Exception()));
32+
$this->assertFalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \Exception()));
3533
}
3634

3735
/** @test */
3836
public function shouldAcceptStaticClassCallbackWithTypehint()
3937
{
4038
$this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException()));
41-
$this->assertfalse(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \Exception()));
39+
$this->assertFalse(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \Exception()));
4240
}
4341

4442
/** @test */
@@ -85,34 +83,28 @@ class TestCallbackWithTypehintClass
8583
{
8684
public function __invoke(\InvalidArgumentException $e)
8785
{
88-
8986
}
9087

9188
public function testCallback(\InvalidArgumentException $e)
9289
{
93-
9490
}
9591

9692
public static function testCallbackStatic(\InvalidArgumentException $e)
9793
{
98-
9994
}
10095
}
10196

10297
class TestCallbackWithoutTypehintClass
10398
{
10499
public function __invoke()
105100
{
106-
107101
}
108102

109103
public function testCallback()
110104
{
111-
112105
}
113106

114107
public static function testCallbackStatic()
115108
{
116-
117109
}
118110
}

tests/FunctionMapTest.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,11 @@ public function shouldRejectWhenInputContainsRejection()
118118
/** @test */
119119
public function shouldCancelInputArrayPromises()
120120
{
121-
$mock1 = $this
122-
->getMockBuilder('React\Promise\PromiseInterface')
123-
->getMock();
124-
$mock1
125-
->method('then')
126-
->will($this->returnSelf());
127-
$mock1
128-
->expects($this->once())
129-
->method('cancel');
130-
131-
$mock2 = $this
132-
->getMockBuilder('React\Promise\PromiseInterface')
133-
->getMock();
134-
$mock2
135-
->method('then')
136-
->will($this->returnSelf());
137-
$mock2
138-
->expects($this->once())
139-
->method('cancel');
121+
$promise1 = new Promise(function () {}, $this->expectCallableOnce());
122+
$promise2 = new Promise(function () {}, $this->expectCallableOnce());
140123

141124
map(
142-
[$mock1, $mock2],
125+
[$promise1, $promise2],
143126
$this->mapper()
144127
)->cancel();
145128
}

tests/FunctionRaceTest.php

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -91,62 +91,31 @@ public function shouldRejectIfFirstSettledPromiseRejects()
9191
/** @test */
9292
public function shouldCancelInputArrayPromises()
9393
{
94-
$mock1 = $this
95-
->getMockBuilder('React\Promise\PromiseInterface')
96-
->getMock();
97-
$mock1
98-
->expects($this->once())
99-
->method('cancel');
100-
101-
$mock2 = $this
102-
->getMockBuilder('React\Promise\PromiseInterface')
103-
->getMock();
104-
$mock2
105-
->expects($this->once())
106-
->method('cancel');
94+
$promise1 = new Promise(function () {}, $this->expectCallableOnce());
95+
$promise2 = new Promise(function () {}, $this->expectCallableOnce());
10796

108-
race([$mock1, $mock2])->cancel();
97+
race([$promise1, $promise2])->cancel();
10998
}
11099

111100
/** @test */
112101
public function shouldNotCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()
113102
{
114-
$mock = $this->createCallableMock();
115-
$mock
116-
->expects($this->never())
117-
->method('__invoke');
118-
119-
$deferred = New Deferred($mock);
103+
$deferred = new Deferred($this->expectCallableNever());
120104
$deferred->resolve();
121105

122-
$mock2 = $this
123-
->getMockBuilder('React\Promise\PromiseInterface')
124-
->getMock();
125-
$mock2
126-
->expects($this->never())
127-
->method('cancel');
106+
$promise2 = new Promise(function () {}, $this->expectCallableNever());
128107

129-
race([$deferred->promise(), $mock2])->cancel();
108+
race([$deferred->promise(), $promise2])->cancel();
130109
}
131110

132111
/** @test */
133112
public function shouldNotCancelOtherPendingInputArrayPromisesIfOnePromiseRejects()
134113
{
135-
$mock = $this->createCallableMock();
136-
$mock
137-
->expects($this->never())
138-
->method('__invoke');
139-
140-
$deferred = New Deferred($mock);
114+
$deferred = new Deferred($this->expectCallableNever());
141115
$deferred->reject(new \Exception());
142116

143-
$mock2 = $this
144-
->getMockBuilder('React\Promise\PromiseInterface')
145-
->getMock();
146-
$mock2
147-
->expects($this->never())
148-
->method('cancel');
117+
$promise2 = new Promise(function () {}, $this->expectCallableNever());
149118

150-
race([$deferred->promise(), $mock2])->cancel();
119+
race([$deferred->promise(), $promise2])->cancel();
151120
}
152121
}

tests/FunctionReduceTest.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -261,28 +261,11 @@ public function shouldProvideCorrectBasisValue()
261261
/** @test */
262262
public function shouldCancelInputArrayPromises()
263263
{
264-
$mock1 = $this
265-
->getMockBuilder('React\Promise\PromiseInterface')
266-
->getMock();
267-
$mock1
268-
->method('then')
269-
->will($this->returnSelf());
270-
$mock1
271-
->expects($this->once())
272-
->method('cancel');
273-
274-
$mock2 = $this
275-
->getMockBuilder('React\Promise\PromiseInterface')
276-
->getMock();
277-
$mock2
278-
->method('then')
279-
->will($this->returnSelf());
280-
$mock2
281-
->expects($this->once())
282-
->method('cancel');
264+
$promise1 = new Promise(function () {}, $this->expectCallableOnce());
265+
$promise2 = new Promise(function () {}, $this->expectCallableOnce());
283266

284267
reduce(
285-
[$mock1, $mock2],
268+
[$promise1, $promise2],
286269
$this->plus(),
287270
1
288271
)->cancel();

tests/FunctionResolveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function shouldSupportVeryDeepNestedPromises()
132132

133133
$last = $p;
134134
for ($j = 0; $j < 250; $j++) {
135-
$last = $last->then(function($result) {
135+
$last = $last->then(function ($result) {
136136
return $result;
137137
});
138138
}

0 commit comments

Comments
 (0)