From 47cb28dca1ba605c88810730f6ea91b384e80823 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:43:02 -0500 Subject: [PATCH 01/26] Delete ErrorInterface.php Signed-off-by: Nathanael Esayeas --- src/Contract/ErrorInterface.php | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 src/Contract/ErrorInterface.php diff --git a/src/Contract/ErrorInterface.php b/src/Contract/ErrorInterface.php deleted file mode 100644 index d747fbb..0000000 --- a/src/Contract/ErrorInterface.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ -interface ErrorInterface extends ResultInterface -{ - /** - * Create a new error value. - * - * @return self - */ - public static function create(Throwable $throwable): self; -} From 238ae80fa063b6050d473d8d47662602abb95f4b Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:43:05 -0500 Subject: [PATCH 02/26] Delete ResultExceptionInterface.php Signed-off-by: Nathanael Esayeas --- src/Contract/Exception/ResultExceptionInterface.php | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/Contract/Exception/ResultExceptionInterface.php diff --git a/src/Contract/Exception/ResultExceptionInterface.php b/src/Contract/Exception/ResultExceptionInterface.php deleted file mode 100644 index 6bd5428..0000000 --- a/src/Contract/Exception/ResultExceptionInterface.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Wed, 5 Jul 2023 19:43:07 -0500 Subject: [PATCH 03/26] Delete ResultInterface.php Signed-off-by: Nathanael Esayeas --- src/Contract/ResultInterface.php | 149 ------------------------------- 1 file changed, 149 deletions(-) delete mode 100644 src/Contract/ResultInterface.php diff --git a/src/Contract/ResultInterface.php b/src/Contract/ResultInterface.php deleted file mode 100644 index 5ef4735..0000000 --- a/src/Contract/ResultInterface.php +++ /dev/null @@ -1,149 +0,0 @@ - $result - * - * @return self - */ - public function and(self $result): self; - - /** - * Calls $function if the result is Success, otherwise returns the Error value of self. - * - * @template TNewValue - * - * @param callable(TValue):TNewValue $function - * - * @return self - */ - public function andThen(callable $function): self; - - /** - * Converts from Result to Option. - */ - public function error(): OptionInterface; - - /** - * Unwraps a result, yielding the content of a Success. - * - * @throws Throwable - */ - public function expect(Throwable $throwable): mixed; - - /** - * Unwraps a result, yielding the content of an Error. - * - * @throws Throwable - */ - public function expectError(Throwable $throwable): Throwable; - - /** - * Returns true if the result is Error. - */ - public function isError(): bool; - - /** - * Returns true if the result is Success. - */ - public function isSuccess(): bool; - - /** - * Maps a Result to Result by applying a function to a contained Success value, leaving an Error value - * untouched. - * - * @template TMap - * - * @param callable(TValue):TMap $function - * - * @return self - */ - public function map(callable $function): self; - - /** - * Maps a Result to Result by applying a function to a contained Error value, leaving a Success value - * untouched. - * - * @template TMapError - * - * @param callable(TValue):TMapError $function - * - * @return self - */ - public function mapError(callable $function): self; - - /** - * Returns $result if the result is Error, otherwise returns the Success value of self. - */ - public function or(self $result): self; - - /** - * Calls $function if the result is Error, otherwise returns the Success value of self. - * - * @template TOrElse - * - * @param callable(TValue):TOrElse $function - * - * @return self - */ - public function orElse(callable $function): self; - - /** - * Converts from Result to Option. - * - * @return OptionInterface - */ - public function success(): OptionInterface; - - /** - * Unwraps a result, yielding the content of a Success. - * - * @return TValue - */ - public function unwrap(): mixed; - - /** - * Unwraps a result, yielding the content of an Error. - * - * @return TValue - */ - public function unwrapError(): mixed; - - /** - * Unwraps a result, yielding the content of a Success. Else, it returns $fallback. - * - * @template TUnwrapOr - * - * @param TUnwrapOr $fallback - * - * @return TUnwrapOr|TValue - */ - public function unwrapOr(mixed $fallback): mixed; - - /** - * Unwraps a result, yielding the content of a Success. If the value is an Error then it calls $function with its - * value. - * - * @template TUnwrapOrElse - * - * @param callable(TValue):TUnwrapOrElse $function - * - * @return TUnwrapOrElse|TValue - */ - public function unwrapOrElse(callable $function): mixed; -} From 9e026b5a39d7ba7d57c2c808a1dfb8b7c4440c1d Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:43:09 -0500 Subject: [PATCH 04/26] Delete SuccessInterface.php Signed-off-by: Nathanael Esayeas --- src/Contract/SuccessInterface.php | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 src/Contract/SuccessInterface.php diff --git a/src/Contract/SuccessInterface.php b/src/Contract/SuccessInterface.php deleted file mode 100644 index 7f5b65c..0000000 --- a/src/Contract/SuccessInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - */ -interface SuccessInterface extends ResultInterface -{ - /** - * Create a new success value. - * - * @template TSuccess - * - * @param TSuccess $value - * - * @return self - */ - public static function create(mixed $value): self; -} From 4832bb2aea849e5079b10ffd2269e73490c5b32a Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:43:17 -0500 Subject: [PATCH 05/26] Create ResultInterface.php Signed-off-by: Nathanael Esayeas --- src/ResultInterface.php | 149 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 src/ResultInterface.php diff --git a/src/ResultInterface.php b/src/ResultInterface.php new file mode 100644 index 0000000..3f60b3a --- /dev/null +++ b/src/ResultInterface.php @@ -0,0 +1,149 @@ + $result + * + * @return self + */ + public function and(self $result): self; + + /** + * Calls $function if the result is Success, otherwise returns the Error value of self. + * + * @template TNewValue + * + * @param callable(TValue):TNewValue $function + * + * @return self + */ + public function andThen(callable $function): self; + + /** + * Converts from Result to Option. + */ + public function error(): OptionInterface; + + /** + * Unwraps a result, yielding the content of a Success. + * + * @throws Throwable + */ + public function expect(Throwable $throwable): mixed; + + /** + * Unwraps a result, yielding the content of an Error. + * + * @throws Throwable + */ + public function expectError(Throwable $throwable): Throwable; + + /** + * Returns true if the result is Error. + */ + public function isError(): bool; + + /** + * Returns true if the result is Success. + */ + public function isSuccess(): bool; + + /** + * Maps a Result to Result by applying a function to a contained Success value, leaving an Error value + * untouched. + * + * @template TMap + * + * @param callable(TValue):TMap $function + * + * @return self + */ + public function map(callable $function): self; + + /** + * Maps a Result to Result by applying a function to a contained Error value, leaving a Success value + * untouched. + * + * @template TMapError + * + * @param callable(TValue):TMapError $function + * + * @return self + */ + public function mapError(callable $function): self; + + /** + * Returns $result if the result is Error, otherwise returns the Success value of self. + */ + public function or(self $result): self; + + /** + * Calls $function if the result is Error, otherwise returns the Success value of self. + * + * @template TOrElse + * + * @param callable(TValue):TOrElse $function + * + * @return self + */ + public function orElse(callable $function): self; + + /** + * Converts from Result to Option. + * + * @return OptionInterface + */ + public function success(): OptionInterface; + + /** + * Unwraps a result, yielding the content of a Success. + * + * @return TValue + */ + public function unwrap(): mixed; + + /** + * Unwraps a result, yielding the content of an Error. + * + * @return TValue + */ + public function unwrapError(): mixed; + + /** + * Unwraps a result, yielding the content of a Success. Else, it returns $fallback. + * + * @template TUnwrapOr + * + * @param TUnwrapOr $fallback + * + * @return TUnwrapOr|TValue + */ + public function unwrapOr(mixed $fallback): mixed; + + /** + * Unwraps a result, yielding the content of a Success. If the value is an Error then it calls $function with its + * value. + * + * @template TUnwrapOrElse + * + * @param callable(TValue):TUnwrapOrElse $function + * + * @return TUnwrapOrElse|TValue + */ + public function unwrapOrElse(callable $function): mixed; +} From 83811f5220e5a89268dccd9ceb6cb228fea0ba42 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:43:26 -0500 Subject: [PATCH 06/26] Create ErrorInterface.php Signed-off-by: Nathanael Esayeas --- src/ErrorInterface.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/ErrorInterface.php diff --git a/src/ErrorInterface.php b/src/ErrorInterface.php new file mode 100644 index 0000000..d5f2e71 --- /dev/null +++ b/src/ErrorInterface.php @@ -0,0 +1,22 @@ + + */ +interface ErrorInterface extends ResultInterface +{ + /** + * Create a new error value. + * + * @return self + */ + public static function create(Throwable $throwable): self; +} From fc9d743bf65bb337a081113a1626ec10e293bc9b Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:44:53 -0500 Subject: [PATCH 07/26] Update AbstractResult.php Signed-off-by: Nathanael Esayeas --- src/AbstractResult.php | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/AbstractResult.php b/src/AbstractResult.php index 4b93331..9c5494f 100644 --- a/src/AbstractResult.php +++ b/src/AbstractResult.php @@ -7,9 +7,6 @@ use Ghostwriter\Option\None; use Ghostwriter\Option\Option; use Ghostwriter\Option\OptionInterface; -use Ghostwriter\Result\Contract\ErrorInterface; -use Ghostwriter\Result\Contract\ResultInterface; -use Ghostwriter\Result\Contract\SuccessInterface; use Ghostwriter\Result\Exception\ResultException; use Throwable; @@ -22,8 +19,10 @@ abstract class AbstractResult implements ResultInterface { /** * @var OptionInterface + * + * @readonly */ - private readonly OptionInterface $option; + private OptionInterface $option; /** * @param TValue $value @@ -75,8 +74,10 @@ public function expectError(Throwable $throwable): Throwable throw $throwable; } - /** @var OptionInterface $this->option */ - return $this->option->unwrap(); + /** @var Throwable $throwable */ + $throwable = $this->option->unwrap(); + + return $throwable; } public function isError(): bool @@ -149,7 +150,7 @@ public function unwrap(): mixed return $this->option->unwrap(); } - throw ResultException::invalidMethodCall('unwrap', ErrorInterface::class); + throw new ResultException(sprintf('Invalid method call "unwrap()" on a Result of type %s', static::class)); } public function unwrapError(): mixed @@ -158,7 +159,9 @@ public function unwrapError(): mixed return $this->option->unwrap(); } - throw ResultException::invalidMethodCall('unwrapError', SuccessInterface::class); + throw new ResultException( + sprintf('Invalid method call "unwrapError()" on a Result of type %s', static::class) + ); } public function unwrapOr(mixed $fallback): mixed @@ -180,10 +183,18 @@ public function unwrapOrElse(callable $function): mixed ->unwrap(); } + /** + * @template TNewValue + * + * @param callable(TValue):TNewValue $function + */ private function call(callable $function): ResultInterface { try { - return self::of($function($this->option->unwrap())); + /** @var TValue $value */ + $value = $this->option->unwrap(); + + return self::of($function($value)); } catch (Throwable $throwable) { return Error::create($throwable); } From 365bc38d6d760236344c64d3a97b0661b3e7c174 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:45:02 -0500 Subject: [PATCH 08/26] Update ResultException.php Signed-off-by: Nathanael Esayeas --- src/Exception/ResultException.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Exception/ResultException.php b/src/Exception/ResultException.php index bda1fc5..c66c28b 100644 --- a/src/Exception/ResultException.php +++ b/src/Exception/ResultException.php @@ -4,13 +4,9 @@ namespace Ghostwriter\Result\Exception; -use Ghostwriter\Result\Contract\Exception\ResultExceptionInterface; +use Ghostwriter\Result\ExceptionInterface; use RuntimeException; -final class ResultException extends RuntimeException implements ResultExceptionInterface +final class ResultException extends RuntimeException implements ExceptionInterface { - public static function invalidMethodCall(string $method, string $type): self - { - return new self(sprintf('Invalid method call "%s()" on a Result of type %s', $method, $type)); - } } From 49f588e8f7bc700b7d08813d22acdeabfc93130f Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:45:10 -0500 Subject: [PATCH 09/26] Update Success.php Signed-off-by: Nathanael Esayeas --- src/Success.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Success.php b/src/Success.php index 133d86a..f4dd6c6 100644 --- a/src/Success.php +++ b/src/Success.php @@ -4,8 +4,6 @@ namespace Ghostwriter\Result; -use Ghostwriter\Result\Contract\SuccessInterface; - /** * Represents the result of successful operation. * From 70f5edf4875c52a997afa0326992df5c29b7f909 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:45:14 -0500 Subject: [PATCH 10/26] Update Error.php Signed-off-by: Nathanael Esayeas --- src/Error.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Error.php b/src/Error.php index ba5e41f..a784d74 100644 --- a/src/Error.php +++ b/src/Error.php @@ -4,7 +4,6 @@ namespace Ghostwriter\Result; -use Ghostwriter\Result\Contract\ErrorInterface; use Throwable; /** From 4bbe60b301e7a9cf84a2c69fbc148c0bdbd6f4a7 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:45:19 -0500 Subject: [PATCH 11/26] Create SuccessInterface.php Signed-off-by: Nathanael Esayeas --- src/SuccessInterface.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/SuccessInterface.php diff --git a/src/SuccessInterface.php b/src/SuccessInterface.php new file mode 100644 index 0000000..6225046 --- /dev/null +++ b/src/SuccessInterface.php @@ -0,0 +1,24 @@ + + */ +interface SuccessInterface extends ResultInterface +{ + /** + * Create a new success value. + * + * @template TSuccess + * + * @param TSuccess $value + * + * @return self + */ + public static function create(mixed $value): self; +} From aac43f574f7b67108a18ec938f6ea234fad5f37a Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:45:22 -0500 Subject: [PATCH 12/26] Create ExceptionInterface.php Signed-off-by: Nathanael Esayeas --- src/ExceptionInterface.php | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/ExceptionInterface.php diff --git a/src/ExceptionInterface.php b/src/ExceptionInterface.php new file mode 100644 index 0000000..eec6135 --- /dev/null +++ b/src/ExceptionInterface.php @@ -0,0 +1,11 @@ + Date: Wed, 5 Jul 2023 19:45:27 -0500 Subject: [PATCH 13/26] Update SuccessTest.php Signed-off-by: Nathanael Esayeas --- tests/Unit/SuccessTest.php | 132 +++++-------------------------------- 1 file changed, 18 insertions(+), 114 deletions(-) diff --git a/tests/Unit/SuccessTest.php b/tests/Unit/SuccessTest.php index 4538530..138294b 100644 --- a/tests/Unit/SuccessTest.php +++ b/tests/Unit/SuccessTest.php @@ -6,20 +6,20 @@ use Ghostwriter\Option\None; use Ghostwriter\Option\Some; -use Ghostwriter\Result\Contract\SuccessInterface; +use Ghostwriter\Result\AbstractResult; +use Ghostwriter\Result\Error; +use Ghostwriter\Result\ErrorInterface; use Ghostwriter\Result\Exception\ResultException; use Ghostwriter\Result\Success; +use Ghostwriter\Result\SuccessInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use RuntimeException; use Throwable; -/** - * @coversDefaultClass \Ghostwriter\Result\Success - * - * @internal - * - * @small - */ +#[CoversClass(AbstractResult::class)] +#[CoversClass(Success::class)] +#[CoversClass(Error::class)] final class SuccessTest extends TestCase { private SuccessInterface $success; @@ -29,15 +29,6 @@ protected function setUp(): void $this->success = Success::create(42); } - /** - * @covers \Ghostwriter\Result\AbstractResult::and - * @covers \Ghostwriter\Result\AbstractResult::error - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::success - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testAnd(): void { $success = Success::create(true); @@ -48,15 +39,6 @@ public function testAnd(): void self::assertTrue($success->unwrap()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::andThen - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::call - * @covers \Ghostwriter\Result\AbstractResult::of - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testAndThen(): void { $result = Success::create('foo') @@ -66,24 +48,21 @@ public function testAndThen(): void self::assertSame('foobar', $result->unwrap()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ + public function testAndThenThrow(): void + { + $result = Success::create('foo') + ->andThen(static fn (): never => throw new RuntimeException()); + + self::assertTrue($result->isError()); + self::assertInstanceOf(ErrorInterface::class, $result); + } + public function testConstruct(): void { $success = Success::create('foo'); self::assertTrue($success->isSuccess()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::error - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testError(): void { self::assertSame(42, $this->success->unwrap()); @@ -94,9 +73,6 @@ public function testError(): void } /** - * @covers \Ghostwriter\Result\AbstractResult::expect - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create * * @throws Throwable */ @@ -107,10 +83,6 @@ public function testExpect(): void } /** - * @covers \Ghostwriter\Result\AbstractResult::expectError - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create * * @throws Throwable */ @@ -121,35 +93,16 @@ public function testExpectError(): void $this->success->expectError(new RuntimeException('oops!')); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testisError(): void { self::assertFalse($this->success->isError()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testIsSuccess(): void { self::assertTrue($this->success->isSuccess()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::map - * @covers \Ghostwriter\Result\AbstractResult::call - * @covers \Ghostwriter\Result\AbstractResult::of - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testMap(): void { $result = $this->success->map(static fn (mixed $x): mixed => $x); @@ -162,12 +115,6 @@ public function testMap(): void self::assertSame(420, $mapped->unwrap()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::mapError - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testMapError(): void { $result = $this->success->mapError(static fn (mixed $x): mixed => $x); @@ -175,13 +122,6 @@ public function testMapError(): void self::assertSame($this->success, $result); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::or - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testOr(): void { $success = Success::create('foobar'); @@ -191,13 +131,6 @@ public function testOr(): void self::assertSame(42, $result->unwrap()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::orElse - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testOrElse(): void { $result = $this->success->orElse(static function (): never { @@ -208,58 +141,29 @@ public function testOrElse(): void self::assertSame(42, $result->unwrap()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::success - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testSuccess(): void { self::assertInstanceOf(Some::class, $this->success->success()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testUnwrap(): void { self::assertSame(42, $this->success->unwrap()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\AbstractResult::unwrapError - * @covers \Ghostwriter\Result\Exception\ResultException::invalidMethodCall - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testUnwrapError(): void { $this->expectException(ResultException::class); - $this->expectExceptionMessage( - ResultException::invalidMethodCall('unwrapError', SuccessInterface::class)->getMessage() - ); + $this->expectExceptionMessage('unwrapError'); $this->success->unwrapError(); } - /** - * @covers \Ghostwriter\Result\AbstractResult::unwrapOr - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testUnwrapOr(): void { self::assertSame(42, $this->success->unwrapOr(false)); } - /** - * @covers \Ghostwriter\Result\AbstractResult::unwrapOrElse - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - */ public function testUnwrapOrElse(): void { $fn = static fn (): bool => false; From 87bdd7c01c2980c07ea7fb87e8f6f3446a1c522c Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:45:34 -0500 Subject: [PATCH 14/26] Update ErrorTest.php Signed-off-by: Nathanael Esayeas --- tests/Unit/ErrorTest.php | 146 +++++---------------------------------- 1 file changed, 16 insertions(+), 130 deletions(-) diff --git a/tests/Unit/ErrorTest.php b/tests/Unit/ErrorTest.php index a925ed7..e269201 100644 --- a/tests/Unit/ErrorTest.php +++ b/tests/Unit/ErrorTest.php @@ -7,22 +7,20 @@ use Ghostwriter\Option\None; use Ghostwriter\Option\Some; use Ghostwriter\Option\SomeInterface; -use Ghostwriter\Result\Contract\ErrorInterface; -use Ghostwriter\Result\Contract\SuccessInterface; +use Ghostwriter\Result\AbstractResult; use Ghostwriter\Result\Error; +use Ghostwriter\Result\ErrorInterface; use Ghostwriter\Result\Exception\ResultException; use Ghostwriter\Result\Success; +use Ghostwriter\Result\SuccessInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use RuntimeException; use Throwable; -/** - * @coversDefaultClass \Ghostwriter\Result\Error - * - * @internal - * - * @small - */ +#[CoversClass(AbstractResult::class)] +#[CoversClass(Success::class)] +#[CoversClass(Error::class)] final class ErrorTest extends TestCase { /** @@ -43,15 +41,6 @@ protected function setUp(): void $this->error = Error::create($this->runtimeException); } - /** - * @covers \Ghostwriter\Result\AbstractResult::of - * @covers \Ghostwriter\Result\AbstractResult::and - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testAnd(): void { $success = Success::of('foobar'); @@ -60,14 +49,6 @@ public function testAnd(): void self::assertTrue($result->isError()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::andThen - * @covers \Ghostwriter\Result\AbstractResult::call - * @covers \Ghostwriter\Result\AbstractResult::of - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testAndThen(): void { $result = $this->error->andThen(static fn (mixed $value): mixed => $value); @@ -75,34 +56,25 @@ public function testAndThen(): void self::assertSame($this->error, $result); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ + public function testAndThenThrow(): void + { + $result = $this->error->andThen(static fn (): never => throw new RuntimeException()); + + self::assertTrue($result->isError()); + self::assertSame($this->error, $result); + } + public function testConstruct(): void { $error = Error::create($this->runtimeException); self::assertTrue($error->isError()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::error - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testError(): void { self::assertInstanceOf(Some::class, $this->error->error()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::expect - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - * - * @throws Throwable - */ public function testExpect(): void { $this->expectException(RuntimeException::class); @@ -110,48 +82,21 @@ public function testExpect(): void $this->error->expect(new RuntimeException('oops!')); } - /** - * @covers \Ghostwriter\Result\AbstractResult::expectError - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - * - * @throws Throwable - */ public function testExpectError(): void { self::assertSame($this->runtimeException, $this->error->expectError(new RuntimeException('oops!'))); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testisError(): void { self::assertTrue($this->error->isError()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testIsSuccess(): void { self::assertFalse($this->error->isSuccess()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\AbstractResult::map - * @covers \Ghostwriter\Result\AbstractResult::call - * @covers \Ghostwriter\Result\AbstractResult::of - * @covers \Ghostwriter\Result\AbstractResult::unwrapError - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testMap(): void { $result = $this->error->map(static fn (mixed $x): mixed => $x); @@ -161,15 +106,6 @@ public function testMap(): void self::assertSame($this->runtimeException, $result->unwrapError()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\AbstractResult::of - * @covers \Ghostwriter\Result\AbstractResult::call - * @covers \Ghostwriter\Result\AbstractResult::mapError - * @covers \Ghostwriter\Result\AbstractResult::unwrapError - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testMapError(): void { $result = $this->error->mapError(static fn (mixed $x): mixed => $x); @@ -181,15 +117,6 @@ public function testMapError(): void self::assertSame($this->runtimeException, $result->unwrapError()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::or - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testOr(): void { $success = Success::create('foobar'); @@ -200,17 +127,6 @@ public function testOr(): void self::assertSame('foobar', $result->unwrap()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isSuccess - * @covers \Ghostwriter\Result\AbstractResult::orElse - * @covers \Ghostwriter\Result\AbstractResult::call - * @covers \Ghostwriter\Result\AbstractResult::of - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Success::__construct - * @covers \Ghostwriter\Result\Success::create - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testOrElse(): void { $success = Success::create('foobar'); @@ -221,58 +137,28 @@ public function testOrElse(): void self::assertSame('foobar', $result->unwrap()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::success - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testSuccess(): void { self::assertInstanceOf(None::class, $this->error->success()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::unwrap - * @covers \Ghostwriter\Result\Exception\ResultException::invalidMethodCall - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testUnwrap(): void { $this->expectException(ResultException::class); - $this->expectExceptionMessage( - ResultException::invalidMethodCall('unwrap', ErrorInterface::class)->getMessage() - ); + $this->expectExceptionMessage('unwrap'); $this->error->unwrap(); } - /** - * @covers \Ghostwriter\Result\AbstractResult::isError - * @covers \Ghostwriter\Result\AbstractResult::unwrapError - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testUnwrapError(): void { self::assertSame($this->runtimeException, $this->error->unwrapError()); } - /** - * @covers \Ghostwriter\Result\AbstractResult::unwrapOr - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testUnwrapOr(): void { self::assertTrue($this->error->unwrapOr(true)); } - /** - * @covers \Ghostwriter\Result\AbstractResult::error - * @covers \Ghostwriter\Result\AbstractResult::unwrapOrElse - * @covers \Ghostwriter\Result\Error::__construct - * @covers \Ghostwriter\Result\Error::create - */ public function testUnwrapOrElse(): void { $fn = static fn (): bool => true; From 0d830865faa2c94dbd8048d57720d2c576df138f Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:45:45 -0500 Subject: [PATCH 15/26] Update rector.php Signed-off-by: Nathanael Esayeas --- rector.php | 112 ++--------------------------------------------------- 1 file changed, 4 insertions(+), 108 deletions(-) diff --git a/rector.php b/rector.php index 5609620..1fe12ea 100644 --- a/rector.php +++ b/rector.php @@ -2,117 +2,13 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector; use Rector\Config\RectorConfig; use Rector\Core\ValueObject\PhpVersion; -use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector; -use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; -use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector; -use Rector\PHPUnit\Rector\Class_\AddSeeTestAnnotationRector; -use Rector\PHPUnit\Rector\Class_\ConstructClassMethodToSetUpTestCaseRector; -use Rector\PHPUnit\Rector\Class_\RemoveDataProviderTestPrefixRector; -use Rector\PHPUnit\Rector\Class_\TestListenerToHooksRector; -use Rector\PHPUnit\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector; -use Rector\PHPUnit\Rector\ClassMethod\ExceptionAnnotationRector; -use Rector\PHPUnit\Rector\ClassMethod\RemoveEmptyTestMethodRector; -use Rector\PHPUnit\Rector\ClassMethod\TryCatchToExpectExceptionRector; -use Rector\PHPUnit\Rector\Foreach_\SimplifyForeachInstanceOfRector; -use Rector\PHPUnit\Rector\MethodCall\AssertCompareToSpecificMethodRector; -use Rector\PHPUnit\Rector\MethodCall\AssertComparisonToSpecificMethodRector; -use Rector\PHPUnit\Rector\MethodCall\AssertEqualsParameterToSpecificMethodsTypeRector; -use Rector\PHPUnit\Rector\MethodCall\AssertEqualsToSameRector; -use Rector\PHPUnit\Rector\MethodCall\AssertFalseStrposToContainsRector; -use Rector\PHPUnit\Rector\MethodCall\AssertInstanceOfComparisonRector; -use Rector\PHPUnit\Rector\MethodCall\AssertIssetToSpecificMethodRector; -use Rector\PHPUnit\Rector\MethodCall\AssertNotOperatorRector; -use Rector\PHPUnit\Rector\MethodCall\AssertPropertyExistsRector; -use Rector\PHPUnit\Rector\MethodCall\AssertRegExpRector; -use Rector\PHPUnit\Rector\MethodCall\AssertResourceToClosedResourceRector; -use Rector\PHPUnit\Rector\MethodCall\AssertSameBoolNullToSpecificMethodRector; -use Rector\PHPUnit\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector; -use Rector\PHPUnit\Rector\MethodCall\AssertTrueFalseInternalTypeToSpecificMethodRector; -use Rector\PHPUnit\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector; -use Rector\PHPUnit\Rector\MethodCall\CreateMockToCreateStubRector; -use Rector\PHPUnit\Rector\MethodCall\DelegateExceptionArgumentsRector; -use Rector\PHPUnit\Rector\MethodCall\ExplicitPhpErrorApiRector; -use Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector; -use Rector\PHPUnit\Rector\MethodCall\RemoveExpectAnyFromMockRector; -use Rector\PHPUnit\Rector\MethodCall\ReplaceAssertArraySubsetWithDmsPolyfillRector; -use Rector\PHPUnit\Rector\MethodCall\SpecificAssertContainsRector; -use Rector\PHPUnit\Rector\MethodCall\SpecificAssertContainsWithoutIdentityRector; -use Rector\PHPUnit\Rector\MethodCall\SpecificAssertInternalTypeRector; -use Rector\PHPUnit\Rector\MethodCall\UseSpecificWillMethodRector; -use Rector\PHPUnit\Rector\StaticCall\GetMockRector; -use Rector\PHPUnit\Set\PHPUnitLevelSetList; -use Rector\Renaming\Rector\FileWithoutNamespace\PseudoNamespaceToNamespaceRector; -use Rector\Set\ValueObject\LevelSetList; -use Rector\Set\ValueObject\SetList; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->importNames(); - $rectorConfig->importShortClasses(); - $rectorConfig->parallel(); - $rectorConfig->sets([ - PHPUnitLevelSetList::UP_TO_PHPUNIT_90, - // PHPUnitLevelSetList::UP_TO_PHPUNIT_100, - LevelSetList::UP_TO_PHP_81, - SetList::CODE_QUALITY, - SetList::CODING_STYLE, - SetList::DEAD_CODE, - SetList::NAMING, - SetList::PRIVATIZATION, - SetList::PSR_4, - SetList::TYPE_DECLARATION, - SetList::EARLY_RETURN, - SetList::PHP_81, - ]); - $rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php']); + $rectorConfig->import(__DIR__ . '/vendor/ghostwriter/coding-standard/rector.php'); $rectorConfig->phpVersion(PhpVersion::PHP_81); - $rectorConfig->skip([ - __DIR__ . '*/tests/Fixture/*', - __DIR__ . '*/vendor/*', - AddDoesNotPerformAssertionToNonAssertingTestRector::class, - CallableThisArrayToAnonymousFunctionRector::class, - PseudoNamespaceToNamespaceRector::class, - RemoveEmptyClassMethodRector::class, - RemoveEmptyTestMethodRector::class, - StringClassNameToClassConstantRector::class, - ]); - $rectorConfig->rules([ - AddSeeTestAnnotationRector::class, - AssertCompareToSpecificMethodRector::class, - AssertComparisonToSpecificMethodRector::class, - AssertEqualsParameterToSpecificMethodsTypeRector::class, - AssertEqualsToSameRector::class, - AssertFalseStrposToContainsRector::class, - AssertInstanceOfComparisonRector::class, - AssertIssetToSpecificMethodRector::class, - AssertNotOperatorRector::class, - AssertPropertyExistsRector::class, - AssertRegExpRector::class, - AssertResourceToClosedResourceRector::class, - AssertSameBoolNullToSpecificMethodRector::class, - AssertSameTrueFalseToAssertTrueFalseRector::class, - AssertTrueFalseInternalTypeToSpecificMethodRector::class, - AssertTrueFalseToSpecificMethodRector::class, - ConstructClassMethodToSetUpTestCaseRector::class, - CreateMockToCreateStubRector::class, - DelegateExceptionArgumentsRector::class, - ExceptionAnnotationRector::class, - ExplicitPhpErrorApiRector::class, - GetMockBuilderGetMockToCreateMockRector::class, - GetMockRector::class, - RemoveDataProviderTestPrefixRector::class, - RemoveEmptyTestMethodRector::class, - RemoveExpectAnyFromMockRector::class, - ReplaceAssertArraySubsetWithDmsPolyfillRector::class, - RestoreDefaultNullToNullableTypePropertyRector::class, - SimplifyForeachInstanceOfRector::class, - SpecificAssertContainsRector::class, - SpecificAssertContainsWithoutIdentityRector::class, - SpecificAssertInternalTypeRector::class, - TestListenerToHooksRector::class, - TryCatchToExpectExceptionRector::class, - UseSpecificWillMethodRector::class, - ]); + + $rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php']); + $rectorConfig->skip([__DIR__ . '*/tests/Fixture/*', __DIR__ . '*/vendor/*']); }; From 530629921998462d658557472572ed2a81ab51cb Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:45:54 -0500 Subject: [PATCH 16/26] Update composer.json Signed-off-by: Nathanael Esayeas --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 36d3095..2909432 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ }, "autoload-dev": { "psr-4": { - "Ghostwriter\\Result\\Tests\\": "tests/" + "Ghostwriter\\Result\\Tests\\Unit\\": "tests/Unit" } }, "config": { @@ -88,7 +88,7 @@ "missing-returntypes": "psalm --alter --issues=MissingReturnType", "normalizer": "composer normalize --no-check-lock", "phpbench": "phpbench run", - "phpunit": "phpunit --colors=always --testdox --stop-on-failure", + "phpunit": "phpunit --colors=always --stop-on-defect", "psalm": "@psalm:shepherd", "psalm:baseline": "psalm --set-baseline=psalm-baseline.xml", "psalm:dry-run": "psalm --alter --issues=all --dry-run", From 2a2a1688eb8f4040e3e435468ff354268953c670 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:46:02 -0500 Subject: [PATCH 17/26] Update composer.lock Signed-off-by: Nathanael Esayeas --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index f1e3763..a955d08 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "67770afa5b65a5837ef7faf9cfd6a3e5", + "content-hash": "089f73e827cb99d3399f0fddb92ece6d", "packages": [ { "name": "ghostwriter/option", @@ -1194,16 +1194,16 @@ "source": { "type": "git", "url": "https://github.com/ghostwriter/coding-standard.git", - "reference": "989829fb899962fdc0223a3740fe7a1ac6c85a5e" + "reference": "3819363ec1be6b014af9b7c0b5d9dc1becc84351" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ghostwriter/coding-standard/zipball/989829fb899962fdc0223a3740fe7a1ac6c85a5e", - "reference": "989829fb899962fdc0223a3740fe7a1ac6c85a5e", + "url": "https://api.github.com/repos/ghostwriter/coding-standard/zipball/3819363ec1be6b014af9b7c0b5d9dc1becc84351", + "reference": "3819363ec1be6b014af9b7c0b5d9dc1becc84351", "shasum": "" }, "require": { - "friendsofphp/php-cs-fixer": "^3.20.0", + "friendsofphp/php-cs-fixer": "^3.21.1", "infection/infection": "^0.27.0", "php": ">=8.1,<8.3", "phpbench/phpbench": "^1.2.10", @@ -1248,7 +1248,7 @@ "type": "github" } ], - "time": "2023-06-30T14:30:34+00:00" + "time": "2023-07-06T00:20:30+00:00" }, { "name": "infection/abstract-testframework-adapter", @@ -6238,7 +6238,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": ">=8.1 <8.3" + "php": ">=8.1,<8.4" }, "platform-dev": [], "plugin-api-version": "2.3.0" From 55623b60368deb2811ec5b08ca1a599c9296dd10 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 19:46:05 -0500 Subject: [PATCH 18/26] Update phpunit.xml.dist Signed-off-by: Nathanael Esayeas --- phpunit.xml.dist | 8 -------- 1 file changed, 8 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d34a1d1..dce690a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -24,14 +24,6 @@ failOnSkipped="true" failOnWarning="true" requireCoverageMetadata="true" - stopOnDefect="true" - stopOnError="true" - stopOnFailure="true" - stopOnIncomplete="true" - stopOnRisky="true" - stopOnSkipped="true" - stopOnWarning="true" - testdox="true" > From a1df7b60b734f7960507105fedec73fe04703b31 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 20:05:49 -0500 Subject: [PATCH 19/26] Update composer.json Signed-off-by: Nathanael Esayeas --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2909432..6f202f7 100644 --- a/composer.json +++ b/composer.json @@ -88,7 +88,7 @@ "missing-returntypes": "psalm --alter --issues=MissingReturnType", "normalizer": "composer normalize --no-check-lock", "phpbench": "phpbench run", - "phpunit": "phpunit --colors=always --stop-on-defect", + "phpunit": "phpunit --colors=always", "psalm": "@psalm:shepherd", "psalm:baseline": "psalm --set-baseline=psalm-baseline.xml", "psalm:dry-run": "psalm --alter --issues=all --dry-run", From 27108a9fa408284180465bf7ec12e9be3c439d11 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 20:08:21 -0500 Subject: [PATCH 20/26] Update ErrorTest.php Signed-off-by: Nathanael Esayeas --- tests/Unit/ErrorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/ErrorTest.php b/tests/Unit/ErrorTest.php index e269201..e27f354 100644 --- a/tests/Unit/ErrorTest.php +++ b/tests/Unit/ErrorTest.php @@ -58,7 +58,7 @@ public function testAndThen(): void public function testAndThenThrow(): void { - $result = $this->error->andThen(static fn (): never => throw new RuntimeException()); + $result = $this->error->andThen(static fn (): mixed => throw new RuntimeException()); self::assertTrue($result->isError()); self::assertSame($this->error, $result); From 211e99df3d76bbcde6aeea325fc9e8f1b617fed1 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 20:08:23 -0500 Subject: [PATCH 21/26] Update SuccessTest.php Signed-off-by: Nathanael Esayeas --- tests/Unit/SuccessTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/SuccessTest.php b/tests/Unit/SuccessTest.php index 138294b..2698372 100644 --- a/tests/Unit/SuccessTest.php +++ b/tests/Unit/SuccessTest.php @@ -51,7 +51,7 @@ public function testAndThen(): void public function testAndThenThrow(): void { $result = Success::create('foo') - ->andThen(static fn (): never => throw new RuntimeException()); + ->andThen(static fn (): mixed => throw new RuntimeException()); self::assertTrue($result->isError()); self::assertInstanceOf(ErrorInterface::class, $result); From 4602b573d683fd6a5d1edbd34c5534fd3df9c074 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 20:14:13 -0500 Subject: [PATCH 22/26] Update SuccessTest.php Signed-off-by: Nathanael Esayeas --- tests/Unit/SuccessTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Unit/SuccessTest.php b/tests/Unit/SuccessTest.php index 2698372..4824cfb 100644 --- a/tests/Unit/SuccessTest.php +++ b/tests/Unit/SuccessTest.php @@ -51,7 +51,9 @@ public function testAndThen(): void public function testAndThenThrow(): void { $result = Success::create('foo') - ->andThen(static fn (): mixed => throw new RuntimeException()); + ->andThen(static function(): mixed { + throw new RuntimeException(__METHOD__); + }); self::assertTrue($result->isError()); self::assertInstanceOf(ErrorInterface::class, $result); From e29bdb5a9449161e5ccaa7d1f60a06065057abd2 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 20:14:17 -0500 Subject: [PATCH 23/26] Update ErrorTest.php Signed-off-by: Nathanael Esayeas --- tests/Unit/ErrorTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Unit/ErrorTest.php b/tests/Unit/ErrorTest.php index e27f354..6fd3ce8 100644 --- a/tests/Unit/ErrorTest.php +++ b/tests/Unit/ErrorTest.php @@ -58,7 +58,9 @@ public function testAndThen(): void public function testAndThenThrow(): void { - $result = $this->error->andThen(static fn (): mixed => throw new RuntimeException()); + $result = $this->error->andThen(static function(): mixed { + throw new RuntimeException(__METHOD__); + }); self::assertTrue($result->isError()); self::assertSame($this->error, $result); From 2781696959b82c425bdf681d10ef34c5e990b29c Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 20:14:19 -0500 Subject: [PATCH 24/26] Update psalm-baseline.xml Signed-off-by: Nathanael Esayeas --- psalm-baseline.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 0653e85..51b41ef 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,2 +1,2 @@ - + From 9f13fe711da9071fa8a06cb6dd916455d7afd143 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 20:16:29 -0500 Subject: [PATCH 25/26] Update SuccessTest.php Signed-off-by: Nathanael Esayeas --- tests/Unit/SuccessTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/SuccessTest.php b/tests/Unit/SuccessTest.php index 4824cfb..64b4871 100644 --- a/tests/Unit/SuccessTest.php +++ b/tests/Unit/SuccessTest.php @@ -51,7 +51,7 @@ public function testAndThen(): void public function testAndThenThrow(): void { $result = Success::create('foo') - ->andThen(static function(): mixed { + ->andThen(static function (): mixed { throw new RuntimeException(__METHOD__); }); From 5991c8aa331bd67162e38bd13b1830c529a4666a Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 5 Jul 2023 20:16:32 -0500 Subject: [PATCH 26/26] Update ErrorTest.php Signed-off-by: Nathanael Esayeas --- tests/Unit/ErrorTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Unit/ErrorTest.php b/tests/Unit/ErrorTest.php index 6fd3ce8..9c51027 100644 --- a/tests/Unit/ErrorTest.php +++ b/tests/Unit/ErrorTest.php @@ -58,9 +58,9 @@ public function testAndThen(): void public function testAndThenThrow(): void { - $result = $this->error->andThen(static function(): mixed { - throw new RuntimeException(__METHOD__); - }); + $result = $this->error->andThen(static function (): mixed { + throw new RuntimeException(__METHOD__); + }); self::assertTrue($result->isError()); self::assertSame($this->error, $result);