Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require argument for resolve() function #213

Merged
merged 1 commit into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ $deferred = new React\Promise\Deferred();

$promise = $deferred->promise();

$deferred->resolve(mixed $value = null);
$deferred->resolve(mixed $value);
$deferred->reject(\Throwable $reason);
```

Expand All @@ -119,7 +119,7 @@ keeping the authority to modify its state to yourself.
#### Deferred::resolve()

```php
$deferred->resolve(mixed $value = null);
$deferred->resolve(mixed $value);
```

Resolves the promise returned by `promise()`. All consumers are notified by
Expand Down
2 changes: 1 addition & 1 deletion src/Deferred.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function promise(): PromiseInterface
return $this->promise;
}

public function resolve($value = null): void
public function resolve($value): void
{
($this->resolveCallback)($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private function call(callable $cb): void
$target =& $this;

$callback(
static function ($value = null) use (&$target) {
static function ($value) use (&$target) {
if ($target !== null) {
$target->settle(resolve($value));
$target = null;
Expand Down
5 changes: 2 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* @param mixed $promiseOrValue
* @return PromiseInterface
*/

function resolve($promiseOrValue = null): PromiseInterface
function resolve($promiseOrValue): PromiseInterface
{
if ($promiseOrValue instanceof PromiseInterface) {
return $promiseOrValue;
Expand Down Expand Up @@ -346,7 +345,7 @@ function _checkTypehint(callable $callback, \Throwable $reason): bool

// Extract the type of the argument and handle different possibilities
$type = $expectedException->getType();

$isTypeUnion = true;
$types = [];

Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionAnyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function shouldCancelInputArrayPromises()
public function shouldNotCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()
{
$deferred = new Deferred($this->expectCallableNever());
$deferred->resolve();
$deferred->resolve(null);

$promise2 = new Promise(function () {}, $this->expectCallableNever());

Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionRaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function shouldCancelInputArrayPromises()
public function shouldNotCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()
{
$deferred = new Deferred($this->expectCallableNever());
$deferred->resolve();
$deferred->resolve(null);

$promise2 = new Promise(function () {}, $this->expectCallableNever());

Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionSomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function shouldCancelInputArrayPromises()
public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfill()
{
$deferred = new Deferred($this->expectCallableNever());
$deferred->resolve();
$deferred->resolve(null);

$promise2 = new Promise(function () {}, $this->expectCallableNever());

Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest/CancelTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function cancelShouldCallCancellerOnlyOnceIfCancellerResolves()
->expects($this->once())
->method('__invoke')
->will($this->returnCallback(function ($resolve) {
$resolve();
$resolve(null);
}));

$adapter = $this->getPromiseTestAdapter($mock);
Expand Down
4 changes: 2 additions & 2 deletions tests/PromiseTest/PromiseFulfilledTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function cancelShouldReturnNullForFulfilledPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->resolve();
$adapter->resolve(null);

self::assertNull($adapter->promise()->cancel());
}
Expand All @@ -200,7 +200,7 @@ public function cancelShouldHaveNoEffectForFulfilledPromise()
{
$adapter = $this->getPromiseTestAdapter($this->expectCallableNever());

$adapter->resolve();
$adapter->resolve(null);

$adapter->promise()->cancel();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/PromiseTest/PromisePendingTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function catchShouldNotInvokeRejectionHandlerForPendingPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);
$adapter->promise()->catch($this->expectCallableNever());
}

Expand All @@ -77,7 +77,7 @@ public function otherwiseShouldNotInvokeRejectionHandlerForPendingPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);
$adapter->promise()->otherwise($this->expectCallableNever());
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PromiseTest/PromiseRejectedTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ public function doneShouldTriggerFatalErrorWithDeepNestingPromiseChainsForReject
$exception = new Exception('UnhandledRejectionException');

$d = new Deferred();
$d->resolve();
$d->resolve(null);

$result = resolve(resolve($d->promise()->then(function () use ($exception) {
$d = new Deferred();
$d->resolve();
$d->resolve(null);

return resolve($d->promise()->then(function () {}))->then(
function () use ($exception) {
Expand Down
16 changes: 8 additions & 8 deletions tests/PromiseTest/PromiseSettledTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function thenShouldReturnAPromiseForSettledPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);
self::assertInstanceOf(PromiseInterface::class, $adapter->promise()->then());
}

Expand All @@ -26,7 +26,7 @@ public function thenShouldReturnAllowNullForSettledPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);
self::assertInstanceOf(PromiseInterface::class, $adapter->promise()->then(null, null));
}

Expand All @@ -35,7 +35,7 @@ public function cancelShouldReturnNullForSettledPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);

self::assertNull($adapter->promise()->cancel());
}
Expand All @@ -45,7 +45,7 @@ public function cancelShouldHaveNoEffectForSettledPromise()
{
$adapter = $this->getPromiseTestAdapter($this->expectCallableNever());

$adapter->settle();
$adapter->settle(null);

$adapter->promise()->cancel();
}
Expand All @@ -55,7 +55,7 @@ public function doneShouldReturnNullForSettledPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);
self::assertNull($adapter->promise()->done(null, function () {}));
}

Expand All @@ -64,7 +64,7 @@ public function doneShouldReturnAllowNullForSettledPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);
self::assertNull($adapter->promise()->done(null, function () {}, null));
}

Expand All @@ -73,7 +73,7 @@ public function finallyShouldReturnAPromiseForSettledPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);
self::assertInstanceOf(PromiseInterface::class, $adapter->promise()->finally(function () {}));
}

Expand All @@ -85,7 +85,7 @@ public function alwaysShouldReturnAPromiseForSettledPromise()
{
$adapter = $this->getPromiseTestAdapter();

$adapter->settle();
$adapter->settle(null);
self::assertInstanceOf(PromiseInterface::class, $adapter->promise()->always(function () {}));
}
}
4 changes: 2 additions & 2 deletions tests/PromiseTest/RejectTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function doneShouldTriggerFatalErrorWithDeepNestingPromiseChains()

$result = resolve(resolve($d->promise()->then(function () use ($exception) {
$d = new Deferred();
$d->resolve();
$d->resolve(null);

return resolve($d->promise()->then(function () {}))->then(
function () use ($exception) {
Expand All @@ -227,7 +227,7 @@ function () use ($exception) {

$result->done();

$d->resolve();
$d->resolve(null);

$errors = $errorCollector->stop();

Expand Down