Skip to content

Commit fb35482

Browse files
committed
Fix bug in When::any() not correctly unwrapping to a single result value
1 parent 88437f2 commit fb35482

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5+
* 1.0.2 (xxxx-xx-xx)
6+
7+
* Fix bug in When::any() not correctly unwrapping to a single result value
8+
49
* 1.0.1 (2012-11-13)
510

611
* Prevent deep recursion which was reaching `xdebug.max_nesting_level` default of 100

src/React/Promise/When.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function all($promisesOrValues, $fulfilledHandler = null, $errorHa
2828
public static function any($promisesOrValues, $fulfilledHandler = null, $errorHandler = null, $progressHandler = null)
2929
{
3030
$unwrapSingleResult = function ($val) use ($fulfilledHandler) {
31-
$val = isset($val[0]) ? $val[0] : null;
31+
$val = array_shift($val);
3232

3333
return $fulfilledHandler ? $fulfilledHandler($val) : $val;
3434
};

tests/React/Promise/WhenAnyTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,25 @@ public function shouldResolveToNullArrayWhenInputPromiseDoesNotResolveToArray()
110110
$mock
111111
);
112112
}
113+
114+
/** @test */
115+
public function shouldNotRelyOnArryIndexesWhenUnwrappingToASingleResolutionValue()
116+
{
117+
$mock = $this->createCallableMock();
118+
$mock
119+
->expects($this->once())
120+
->method('__invoke')
121+
->with($this->identicalTo(2));
122+
123+
$d1 = new Deferred();
124+
$d2 = new Deferred();
125+
126+
When::any(
127+
array('abc' => $d1->promise(), 1 => $d2->promise()),
128+
$mock
129+
);
130+
131+
$d2->resolve(2);
132+
$d1->resolve(1);
133+
}
113134
}

0 commit comments

Comments
 (0)