diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6a6ce0..1797b5e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,3 +64,6 @@ * introduced `Psl\Password\Algorithm` enum * **BC** - all constants of `Psl\Password` component has been removed. * **BC** - function `Psl\Password\algorithms()` have been removed. +* **BC** - `Psl\Result\ResultInterface::getException()` method has been renamed to `Psl\Result\ResultInterface::getThrowable()` +* **BC** - `Psl\Result\wrap` function now catches all `Throwable`s instead of only `Exception`s + diff --git a/src/Psl/Async/Awaitable.php b/src/Psl/Async/Awaitable.php index db313414..4a009959 100644 --- a/src/Psl/Async/Awaitable.php +++ b/src/Psl/Async/Awaitable.php @@ -5,11 +5,11 @@ namespace Psl\Async; use Closure; -use Exception as RootException; use Generator; use Psl\Async\Internal\AwaitableIterator; use Psl\Async\Internal\State; use Psl\Promise\PromiseInterface; +use Throwable; use function is_array; @@ -72,9 +72,9 @@ public static function iterate(iterable $awaitables): Generator /** @psalm-suppress MissingThrowsDocblock */ $iterator->complete(); - } catch (RootException $exception) { + } catch (Throwable $throwable) { /** @psalm-suppress MissingThrowsDocblock */ - $iterator->error($exception); + $iterator->error($throwable); } // @codeCoverageIgnoreEnd }); @@ -106,12 +106,12 @@ public static function complete(mixed $result): self /** * @return Awaitable */ - public static function error(RootException $exception): self + public static function error(Throwable $throwable): self { /** @var State $state */ $state = new State(); /** @psalm-suppress MissingThrowsDocblock */ - $state->error($exception); + $state->error($throwable); return new self($state); } @@ -130,8 +130,8 @@ public function isComplete(): bool * * @template Ts * - * @param (Closure(T): Ts) $success - * @param (Closure(RootException): Ts) $failure + * @param Closure(T): Ts $success + * @param Closure(Throwable): Ts $failure * * @return Awaitable */ @@ -142,15 +142,15 @@ public function then(Closure $success, Closure $failure): Awaitable $this->state->subscribe( /** - * @param null|RootException $error + * @param null|Throwable $error * @param null|T $value */ - static function (?RootException $error, mixed $value) use ($state, $success, $failure): void { + static function (?Throwable $error, mixed $value) use ($state, $success, $failure): void { if ($error) { try { $state->complete($failure($error)); - } catch (RootException $exception) { - $state->error($exception); + } catch (Throwable $throwable) { + $state->error($throwable); } return; @@ -161,8 +161,8 @@ static function (?RootException $error, mixed $value) use ($state, $success, $fa * @var T $value */ $state->complete($success($value)); - } catch (RootException $exception) { - $state->error($exception); + } catch (Throwable $throwable) { + $state->error($throwable); } }, ); @@ -175,13 +175,13 @@ static function (?RootException $error, mixed $value) use ($state, $success, $fa * * @template Ts * - * @param (Closure(T): Ts) $success + * @param Closure(T): Ts $success * * @return Awaitable */ public function map(Closure $success): Awaitable { - return $this->then($success, static fn (RootException $exception) => throw $exception); + return $this->then($success, static fn (Throwable $throwable) => throw $throwable); } /** @@ -189,7 +189,7 @@ public function map(Closure $success): Awaitable * * @template Ts * - * @param (Closure(RootException): Ts) $failure + * @param Closure(Throwable): Ts $failure * * @return Awaitable */ @@ -211,7 +211,7 @@ static function (mixed $value): mixed { /** * {@inheritDoc} * - * @param (Closure(): void) $always + * @param Closure(): void $always * * @return Awaitable */ @@ -220,7 +220,7 @@ public function always(Closure $always): Awaitable /** @var State $state */ $state = new State(); - $this->state->subscribe(static function (?RootException $error, mixed $value) use ($state, $always): void { + $this->state->subscribe(static function (?Throwable $error, mixed $value) use ($state, $always): void { try { $always(); @@ -232,8 +232,8 @@ public function always(Closure $always): Awaitable */ $state->complete($value); } - } catch (RootException $exception) { - $state->error($exception); + } catch (Throwable $throwable) { + $state->error($throwable); } }); @@ -243,7 +243,7 @@ public function always(Closure $always): Awaitable /** * Awaits the operation to complete. * - * Throws an exception if the operation fails. + * Throws a `Throwable` if the operation fails. * * @return T */ @@ -253,10 +253,10 @@ public function await(): mixed $this->state->subscribe( /** - * @param null|RootException $error + * @param null|Throwable $error * @param null|T $value */ - static function (?RootException $error, mixed $value) use ($suspension): void { + static function (?Throwable $error, mixed $value) use ($suspension): void { if ($error) { $suspension->throw($error); } else { diff --git a/src/Psl/Async/Deferred.php b/src/Psl/Async/Deferred.php index 2fb94f17..62e98dbb 100644 --- a/src/Psl/Async/Deferred.php +++ b/src/Psl/Async/Deferred.php @@ -4,8 +4,8 @@ namespace Psl\Async; -use Exception as RootException; use Psl; +use Throwable; /** * The following class was derived from code of Amphp. @@ -51,13 +51,13 @@ public function complete(mixed $result): void /** * Marks the operation as failed. * - * @param RootException $exception Throwable to indicate the error. + * @param Throwable $throwable Throwable to indicate the error. * * @throws Psl\Exception\InvariantViolationException If the operation is no longer pending. */ - public function error(RootException $exception): void + public function error(Throwable $throwable): void { - $this->state->error($exception); + $this->state->error($throwable); } /** diff --git a/src/Psl/Async/Exception/CompositeException.php b/src/Psl/Async/Exception/CompositeException.php index abdbc409..48ed59b4 100644 --- a/src/Psl/Async/Exception/CompositeException.php +++ b/src/Psl/Async/Exception/CompositeException.php @@ -5,8 +5,8 @@ namespace Psl\Async\Exception; use Exception; -use Exception as RootException; use Psl\Str; +use Throwable; use function count; @@ -15,12 +15,12 @@ final class CompositeException extends Exception implements ExceptionInterface { /** - * @var non-empty-array + * @var non-empty-array */ private array $reasons; /** - * @param non-empty-array $reasons Array of exceptions. + * @param non-empty-array $reasons Array of exceptions. * @param string|null $message Exception message, defaults to message generated from passed exceptions. */ public function __construct(array $reasons, ?string $message = null) @@ -31,7 +31,7 @@ public function __construct(array $reasons, ?string $message = null) } /** - * @return non-empty-array + * @return non-empty-array */ public function getReasons(): array { @@ -39,7 +39,7 @@ public function getReasons(): array } /** - * @param non-empty-array $reasons + * @param non-empty-array $reasons */ private function generateMessage(array $reasons): string { diff --git a/src/Psl/Async/Exception/UnhandledAwaitableException.php b/src/Psl/Async/Exception/UnhandledAwaitableException.php index 7da8efb6..e6de6270 100644 --- a/src/Psl/Async/Exception/UnhandledAwaitableException.php +++ b/src/Psl/Async/Exception/UnhandledAwaitableException.php @@ -4,18 +4,18 @@ namespace Psl\Async\Exception; -use Exception as RootException; use Psl\Exception\RuntimeException; use Psl\Str; +use Throwable; final class UnhandledAwaitableException extends RuntimeException implements ExceptionInterface { - public static function forException(RootException $exception): UnhandledAwaitableException + public static function forThrowable(Throwable $throwable): UnhandledAwaitableException { return new self( - Str\format('Unhandled awaitable error "%s", make sure to call `Awaitable::await()` before the awaitable is destroyed, or call `Awaitable::ignore()` to ignore exceptions.', $exception::class), - (int) $exception->getCode(), - $exception + Str\format('Unhandled awaitable error "%s", make sure to call `Awaitable::await()` before the awaitable is destroyed, or call `Awaitable::ignore()` to ignore exceptions.', $throwable::class), + (int) $throwable->getCode(), + $throwable ); } } diff --git a/src/Psl/Async/Internal/AwaitableIterator.php b/src/Psl/Async/Internal/AwaitableIterator.php index 977c4ee6..c664426f 100644 --- a/src/Psl/Async/Internal/AwaitableIterator.php +++ b/src/Psl/Async/Internal/AwaitableIterator.php @@ -4,9 +4,9 @@ namespace Psl\Async\Internal; -use Exception as RootException; use Psl; use Psl\Async\Awaitable; +use Throwable; use function array_shift; use function count; @@ -35,7 +35,7 @@ final class AwaitableIterator private readonly AwaitableIteratorQueue $queue; /** - * @var null|Awaitable|Awaitable|Awaitable}> + * @var null|Awaitable|Awaitable|Awaitable}> */ private ?Awaitable $complete = null; @@ -63,9 +63,9 @@ public function enqueue(State $state, mixed $key, Awaitable $awaitable): void * @param Tv|null $_result */ static function ( - ?RootException $_error, - mixed $_result, - string $id + ?Throwable $_error, + mixed $_result, + string $id ) use ( $key, $awaitable, @@ -106,7 +106,7 @@ public function complete(): void /** * @throws Psl\Exception\InvariantViolationException If the iterator has already been marked as complete. */ - public function error(RootException $exception): void + public function error(Throwable $exception): void { if (null !== $this->complete) { Psl\invariant_violation('Iterator has already been marked as complete'); @@ -123,7 +123,7 @@ public function error(RootException $exception): void /** * @throws Psl\Exception\InvariantViolationException If {@see consume()} is called concurrently. * - * @return null|array{0: Tk, 1: Awaitable} + * @return null|array{Tk, Awaitable} */ public function consume(): ?array { diff --git a/src/Psl/Async/Internal/State.php b/src/Psl/Async/Internal/State.php index eea6aa85..72d98fa4 100644 --- a/src/Psl/Async/Internal/State.php +++ b/src/Psl/Async/Internal/State.php @@ -5,11 +5,11 @@ namespace Psl\Async\Internal; use Closure; -use Exception as RootException; use Psl; use Psl\Async\Awaitable; use Psl\Async\Exception; use Psl\Async\Scheduler; +use Throwable; /** * The following class was derived from code of Amphp. @@ -36,7 +36,7 @@ final class State private bool $handled = false; /** - * @var array + * @var array */ private array $callbacks = []; @@ -45,15 +45,15 @@ final class State */ private mixed $result = null; - private ?RootException $exception = null; + private ?Throwable $throwable = null; /** * @throws Exception\UnhandledAwaitableException */ public function __destruct() { - if ($this->exception && !$this->handled) { - throw Exception\UnhandledAwaitableException::forException($this->exception); + if ($this->throwable && !$this->handled) { + throw Exception\UnhandledAwaitableException::forThrowable($this->throwable); } } @@ -62,7 +62,7 @@ public function __destruct() * * The callback is invoked directly from the event loop context, so suspension within the callback is not possible. * - * @param (Closure(?RootException, ?T, string): void) $callback Callback invoked on completion of the awaitable. + * @param Closure(?Throwable, ?T, string): void $callback Callback invoked on completion of the awaitable. * * @return string Identifier that can be used to cancel interest for this awaitable. */ @@ -74,7 +74,7 @@ public function subscribe(Closure $callback): string $this->handled = true; if ($this->complete) { - Scheduler::queue(fn() => $callback($this->exception, $this->result, $id)); + Scheduler::queue(fn() => $callback($this->throwable, $this->result, $id)); } else { $this->callbacks[$id] = $callback; } @@ -121,18 +121,18 @@ public function complete(mixed $result): void * * @throws Psl\Exception\InvariantViolationException If the operation is no longer pending. */ - public function error(RootException $exception): void + public function error(Throwable $throwable): void { if ($this->complete) { Psl\invariant_violation('Operation is no longer pending.'); } - $this->exception = $exception; + $this->throwable = $throwable; $this->invokeCallbacks(); } /** - * Suppress the exception thrown to the loop error handler if and operation error is not handled by a callback. + * Suppress the `Throwable`s thrown to the loop error handler if and operation error is not handled by a callback. */ public function ignore(): void { @@ -152,7 +152,7 @@ private function invokeCallbacks(): void $this->complete = true; foreach ($this->callbacks as $id => $callback) { - Scheduler::queue(fn() => $callback($this->exception, $this->result, $id)); + Scheduler::queue(fn() => $callback($this->throwable, $this->result, $id)); } $this->callbacks = []; diff --git a/src/Psl/Async/all.php b/src/Psl/Async/all.php index 4b8478c9..a534cdfb 100644 --- a/src/Psl/Async/all.php +++ b/src/Psl/Async/all.php @@ -4,7 +4,7 @@ namespace Psl\Async; -use Exception as RootException; +use Throwable; /** * Awaits all awaitables to complete concurrently. @@ -26,7 +26,7 @@ function all(iterable $awaitables): array foreach (Awaitable::iterate($awaitables) as $index => $awaitable) { try { $values[$index] = $awaitable->await(); - } catch (RootException $exception) { + } catch (Throwable $exception) { $errors = []; foreach ($awaitables as $original) { if ($original === $awaitable) { @@ -38,7 +38,7 @@ function all(iterable $awaitables): array } else { try { $original->await(); - } catch (RootException $error) { + } catch (Throwable $error) { $errors[] = $error; } } diff --git a/src/Psl/Async/any.php b/src/Psl/Async/any.php index 87f2f60e..9de48567 100644 --- a/src/Psl/Async/any.php +++ b/src/Psl/Async/any.php @@ -4,8 +4,8 @@ namespace Psl\Async; -use Exception as RootException; use Psl\Async\Exception\CompositeException; +use Throwable; /** * Unwraps the first successfully completed awaitable. @@ -34,7 +34,7 @@ function any(iterable $awaitables): mixed } return $result; - } catch (RootException $exception) { + } catch (Throwable $exception) { $errors[] = $exception; } } diff --git a/src/Psl/Async/run.php b/src/Psl/Async/run.php index 66ee3d85..1bee423b 100644 --- a/src/Psl/Async/run.php +++ b/src/Psl/Async/run.php @@ -5,7 +5,7 @@ namespace Psl\Async; use Closure; -use Exception as RootException; +use Throwable; /** * Create a new fiber asynchronously using the given closure. @@ -25,7 +25,7 @@ function run(Closure $closure): Awaitable $result = $closure(); $state->complete($result); - } catch (RootException $exception) { + } catch (Throwable $exception) { $state->error($exception); } }); diff --git a/src/Psl/Async/sleep.php b/src/Psl/Async/sleep.php index 814e76d6..0b7058b9 100644 --- a/src/Psl/Async/sleep.php +++ b/src/Psl/Async/sleep.php @@ -10,7 +10,7 @@ function sleep(float $seconds): void { $suspension = Scheduler::getSuspension(); - $watcher = Scheduler::delay($seconds, static fn () => $suspension->resume(null)); + $watcher = Scheduler::delay($seconds, $suspension->resume(...)); try { $suspension->suspend(); diff --git a/src/Psl/Promise/PromiseInterface.php b/src/Psl/Promise/PromiseInterface.php index c7eb825d..4c54478f 100644 --- a/src/Psl/Promise/PromiseInterface.php +++ b/src/Psl/Promise/PromiseInterface.php @@ -5,7 +5,7 @@ namespace Psl\Promise; use Closure; -use Exception as RootException; +use Throwable; /** * @template T @@ -27,7 +27,7 @@ interface PromiseInterface * @template Ts * * @param (Closure(T): Ts) $success - * @param (Closure(RootException): Ts) $failure + * @param (Closure(Throwable): Ts) $failure * * @return PromiseInterface */ @@ -37,7 +37,7 @@ public function then(Closure $success, Closure $failure): PromiseInterface; * Attaches a callback that is invoked if this promise is fulfilled. * * The returned promise is resolved with the return value of the callback, - * or is rejected with an exception thrown from the callback. + * or is rejected with a throwable thrown from the callback. * * @template Ts * @@ -51,11 +51,11 @@ public function map(Closure $success): PromiseInterface; * Attaches a callback that is invoked if this promise is rejected. * * The returned promise is resolved with the return value of the callback, - * or is rejected with an exception thrown from the callback. + * or is rejected with a throwable thrown from the callback. * * @template Ts * - * @param (Closure(RootException): Ts) $failure + * @param (Closure(Throwable): Ts) $failure * * @return PromiseInterface */ @@ -66,7 +66,7 @@ public function catch(Closure $failure): PromiseInterface; * * The returned promise resolves with the same value as this promise once the callback has finished execution. * - * If the callback throws, the returned promise will be rejected with the thrown exception. + * If the callback throws, the returned promise will be rejected with the thrown throwable. * * @param (Closure(): void) $always * diff --git a/src/Psl/Result/Failure.php b/src/Psl/Result/Failure.php index c21ddc16..7431c0ac 100644 --- a/src/Psl/Result/Failure.php +++ b/src/Psl/Result/Failure.php @@ -5,48 +5,48 @@ namespace Psl\Result; use Closure; -use Exception as RootException; +use Throwable; /** * Represents the result of failed operation. * * @template T - * @template Te of RootException + * @template Te of Throwable * * @implements ResultInterface */ final class Failure implements ResultInterface { /** - * @param Te $exception + * @param Te $throwable */ public function __construct( - private readonly RootException $exception + private readonly Throwable $throwable ) { } /** - * Since this is a failed result wrapper, this always throws the exception thrown during the operation. + * Since this is a failed result wrapper, this always throws the `Throwable` thrown during the operation. * - * @throws RootException + * @throws Throwable * * @psalm-mutation-free */ public function getResult(): void { - throw $this->exception; + throw $this->throwable; } /** - * Since this is a failed result wrapper, this always returns the exception thrown during the operation. + * Since this is a failed result wrapper, this always returns the `Throwable` thrown during the operation. * - * @return Te - The exception thrown during the operation. + * @return Te - The `Throwable` thrown during the operation. * * @psalm-mutation-free */ - public function getException(): RootException + public function getThrowable(): Throwable { - return $this->exception; + return $this->throwable; } /** @@ -74,14 +74,14 @@ public function isFailed(): bool * * @template Ts * - * @param (Closure(T): Ts) $success - * @param (Closure(RootException): Ts) $failure + * @param Closure(T): Ts $success + * @param Closure(Throwable): Ts $failure * * @return Ts */ public function proceed(Closure $success, Closure $failure): mixed { - return $failure($this->exception); + return $failure($this->throwable); } /** @@ -89,14 +89,14 @@ public function proceed(Closure $success, Closure $failure): mixed * * @template Ts * - * @param (Closure(T): Ts) $success - * @param (Closure(RootException): Ts) $failure + * @param Closure(T): Ts $success + * @param Closure(Throwable): Ts $failure * * @return ResultInterface */ public function then(Closure $success, Closure $failure): ResultInterface { - return wrap(fn () => $failure($this->exception)); + return wrap(fn () => $failure($this->throwable)); } /** @@ -104,13 +104,13 @@ public function then(Closure $success, Closure $failure): ResultInterface * * @template Ts * - * @param (Closure(T): Ts) $success + * @param Closure(T): Ts $success * * @return Failure */ public function map(Closure $success): Failure { - return new Failure($this->exception); + return new Failure($this->throwable); } /** @@ -118,19 +118,19 @@ public function map(Closure $success): Failure * * @template Ts * - * @param (Closure(RootException): Ts) $failure + * @param Closure(Throwable): Ts $failure * * @return ResultInterface */ public function catch(Closure $failure): ResultInterface { - return wrap(fn() => $failure($this->exception)); + return wrap(fn() => $failure($this->throwable)); } /** * {@inheritDoc} * - * @param (Closure(): void) $always + * @param Closure(): void $always * * @return ResultInterface */ @@ -139,7 +139,7 @@ public function always(Closure $always): ResultInterface return wrap(function () use ($always): never { $always(); - throw $this->exception; + throw $this->throwable; }); } } diff --git a/src/Psl/Result/ResultInterface.php b/src/Psl/Result/ResultInterface.php index cce120ba..2a29a951 100644 --- a/src/Psl/Result/ResultInterface.php +++ b/src/Psl/Result/ResultInterface.php @@ -5,11 +5,11 @@ namespace Psl\Result; use Closure; -use Exception as RootException; use Psl; +use Throwable; /** - * Represents a result of operation that either has a successful result or the exception object if + * Represents a result of operation that either has a successful result or the throwable object if * that operation failed. * * This is an interface. You get generally `ResultInterface` by calling `wrap()`, passing in @@ -22,10 +22,10 @@ interface ResultInterface extends Psl\Promise\PromiseInterface { /** - * Return the result of the operation, or throw underlying exception. + * Return the result of the operation, or throw underlying throwable. * * - if the operation succeeded: return its result. - * - if the operation failed: throw the exception inciting failure. + * - if the operation failed: throw the throwable inciting failure. * * @return T - The result of the operation upon success * @@ -34,16 +34,16 @@ interface ResultInterface extends Psl\Promise\PromiseInterface public function getResult(); /** - * Return the underlying exception, or fail with a invariant violation exception exception. + * Return the underlying throwable, or fail with a invariant violation exception. * * - if the operation succeeded: fails with a invariant violation exception. - * - if the operation failed: returns the exception indicating failure. + * - if the operation failed: returns the throwable indicating failure. * * @throws Psl\Exception\InvariantViolationException - When the operation succeeded * * @psalm-mutation-free */ - public function getException(): RootException; + public function getThrowable(): Throwable; /** * Indicates whether the operation associated with this wrapper existed normally. @@ -57,7 +57,7 @@ public function getException(): RootException; public function isSucceeded(): bool; /** - * Indicates whether the operation associated with this wrapper exited abnormally via an exception of some sort. + * Indicates whether the operation associated with this wrapper exited abnormally via a throwable of some sort. * * if `isFailed()` returns `true`, `isSucceeded()` returns false. * @@ -70,13 +70,13 @@ public function isFailed(): bool; /** * Unwrapping and transforming a result can be done by using the proceed method. * The implementation will either run the `$on_success` or `$on_failure` callback. - * The callback will receive the result or Exception as an argument, + * The callback will receive the result or Throwable as an argument, * so that you can transform it to anything you want. * * @template Ts * * @param (Closure(T): Ts) $success - * @param (Closure(RootException): Ts) $failure + * @param (Closure(Throwable): Ts) $failure * * @return Ts */ diff --git a/src/Psl/Result/Success.php b/src/Psl/Result/Success.php index c9a20bb7..77fe694d 100644 --- a/src/Psl/Result/Success.php +++ b/src/Psl/Result/Success.php @@ -54,7 +54,7 @@ public function getResult(): mixed * * @psalm-mutation-free */ - public function getException(): never + public function getThrowable(): never { Psl\invariant_violation('No exception thrown from the operation.'); } diff --git a/src/Psl/Result/wrap.php b/src/Psl/Result/wrap.php index 7f016841..275a6dc8 100644 --- a/src/Psl/Result/wrap.php +++ b/src/Psl/Result/wrap.php @@ -5,11 +5,11 @@ namespace Psl\Result; use Closure; -use Exception; +use Throwable; /** * Wrap the given closure result in a `Success`, or `Failure` if the closure throws - * an `Exception`. + * an `Throwable`. * * @template T * @@ -22,7 +22,7 @@ function wrap(Closure $closure): ResultInterface try { $result = $closure(); return $result instanceof ResultInterface ? $result : new Success($result); - } catch (Exception $e) { + } catch (Throwable $e) { return new Failure($e); } } diff --git a/tests/unit/Async/ReflectTest.php b/tests/unit/Async/ReflectTest.php index 16c66e4b..887671b5 100644 --- a/tests/unit/Async/ReflectTest.php +++ b/tests/unit/Async/ReflectTest.php @@ -27,7 +27,7 @@ public function testReflectParallel(): void static::assertInstanceOf(Result\Failure::class, $one); static::assertInstanceOf(Result\Success::class, $two); - static::assertSame('failure', $one->getException()->getMessage()); + static::assertSame('failure', $one->getThrowable()->getMessage()); static::assertSame('success', $two->getResult()); } } diff --git a/tests/unit/Result/FailureTest.php b/tests/unit/Result/FailureTest.php index 5b35225b..a37e5978 100644 --- a/tests/unit/Result/FailureTest.php +++ b/tests/unit/Result/FailureTest.php @@ -37,7 +37,7 @@ public function testGetException(): void { $exception = new Exception('bar'); $wrapper = new Failure($exception); - $e = $wrapper->getException(); + $e = $wrapper->getThrowable(); static::assertSame($exception, $e); } @@ -80,7 +80,7 @@ static function () { ); static::assertFalse($actual->isSucceeded()); - static::assertSame($actual->getException(), $exception); + static::assertSame($actual->getThrowable(), $exception); } public function testCatch(): void @@ -90,7 +90,7 @@ public function testCatch(): void $actual = $wrapper->catch(Fun\rethrow()); static::assertFalse($actual->isSucceeded()); - static::assertSame($actual->getException(), $exception); + static::assertSame($actual->getThrowable(), $exception); $exception = new Exception('bar'); $wrapper = new Failure($exception); @@ -109,7 +109,7 @@ public function testMap(): void }); static::assertTrue($actual->isFailed()); - static::assertSame($exception, $actual->getException()); + static::assertSame($exception, $actual->getThrowable()); } public function testAlways(): void @@ -122,7 +122,7 @@ public function testAlways(): void }); static::assertTrue($actual->isFailed()); - static::assertSame($exception, $actual->getException()); + static::assertSame($exception, $actual->getThrowable()); static::assertSame('hello', $ref->value); } } diff --git a/tests/unit/Result/SuccessTest.php b/tests/unit/Result/SuccessTest.php index e92b0f88..af4f5bd0 100644 --- a/tests/unit/Result/SuccessTest.php +++ b/tests/unit/Result/SuccessTest.php @@ -38,7 +38,7 @@ public function testGetException(): void $this->expectException(InvariantViolationException::class); $this->expectExceptionMessage('No exception thrown'); - $wrapper->getException(); + $wrapper->getThrowable(); } public function testProceed(): void @@ -77,7 +77,7 @@ static function () use ($exception) { ); static::assertFalse($actual->isSucceeded()); - static::assertSame($actual->getException(), $exception); + static::assertSame($actual->getThrowable(), $exception); } public function testCatch(): void @@ -107,7 +107,7 @@ public function testMap(): void static::assertNotSame($wrapper, $actual); static::assertFalse($actual->isSucceeded()); static::assertTrue($actual->isFailed()); - static::assertSame('bye', $actual->getException()->getMessage()); + static::assertSame('bye', $actual->getThrowable()->getMessage()); } public function testAlways(): void diff --git a/tests/unit/Result/WrapTest.php b/tests/unit/Result/WrapTest.php index 12bc63a1..60fff79a 100644 --- a/tests/unit/Result/WrapTest.php +++ b/tests/unit/Result/WrapTest.php @@ -19,7 +19,7 @@ public function testWrapException(): void }); static::assertFalse($wrapper->isSucceeded()); static::assertTrue($wrapper->isFailed()); - static::assertSame($exception, $wrapper->getException()); + static::assertSame($exception, $wrapper->getThrowable()); $this->expectExceptionObject($exception); @@ -38,7 +38,7 @@ public function testWrapResult(): void $this->expectException(InvariantViolationException::class); $this->expectExceptionMessage('No exception thrown'); - $wrapper->getException(); + $wrapper->getThrowable(); } public function testWrapOtherResult(): void