diff --git a/tests/ErrTest.php b/tests/ErrTest.php index 335ceb5..b919ee0 100644 --- a/tests/ErrTest.php +++ b/tests/ErrTest.php @@ -59,15 +59,6 @@ public function unwrap_throws_exception(): void $err->unwrap(); } - #[Test] - public function expect_throws_withGivenMessage(): void - { - $err = new Err('error'); - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('config file should be readable'); - $err->expect('config file should be readable'); - } - #[Test] public function expectErr_returns_error_value(): void { @@ -102,18 +93,6 @@ public function unwrap_withArrayError_describesType(): void $err->unwrap(); } - #[Test] - public function unwrapException_remainsCatchableAsLogicException(): void - { - $err = new Err('error'); - - try { - $err->unwrap(); - } catch (\LogicException $e) { - $this->assertInstanceOf(UnwrapException::class, $e); - } - } - #[Test] public function unwrap_withThrowingStringableError_stillThrowsUnwrapException(): void { @@ -178,29 +157,6 @@ public function unwrapErr_returns_error_value(): void $this->assertSame('error message', $err->unwrapErr()); } - #[Test] - public function unwrapErr_withIntValue_returns_int(): void - { - $err = new Err(404); - $this->assertSame(404, $err->unwrapErr()); - } - - #[Test] - public function unwrapErr_withArrayValue_returns_array(): void - { - $error = ['code' => 500, 'message' => 'Internal Server Error']; - $err = new Err($error); - $this->assertSame($error, $err->unwrapErr()); - } - - #[Test] - public function unwrapErr_withObjectValue_returns_object(): void - { - $error = new \Exception('Test exception'); - $err = new Err($error); - $this->assertSame($error, $err->unwrapErr()); - } - #[Test] public function unwrapOr_returns_default(): void { @@ -208,14 +164,6 @@ public function unwrapOr_returns_default(): void $this->assertSame(42, $err->unwrapOr(42)); } - #[Test] - public function unwrapOr_withDifferentTypes_returns_default(): void - { - $err = new Err('error'); - $this->assertSame('default', $err->unwrapOr('default')); - $this->assertSame(['default'], $err->unwrapOr(['default'])); - } - #[Test] public function unwrapOrElse_calls_function(): void { @@ -250,15 +198,6 @@ public function mapErr_applies_function_to_error(): void $this->assertSame('ERROR', $mapped->unwrapErr()); } - #[Test] - public function mapErr_withTypeChange_transforms_type(): void - { - $err = new Err(404); - $mapped = $err->mapErr(fn ($code) => "Error code: $code"); - $this->assertInstanceOf(Err::class, $mapped); - $this->assertSame('Error code: 404', $mapped->unwrapErr()); - } - #[Test] public function inspect_does_not_call_function(): void { @@ -328,16 +267,6 @@ public function andThen_returns_self(): void $this->assertSame('error', $result->unwrapErr()); } - #[Test] - public function andThen_withDifferentErrorType_keeps_original_error(): void - { - $err = new Err(self::asString('validation failed')); - $result = $err->andThen(fn ($x) => new Err(new \DomainException('unreachable'))); - - $this->assertSame($err, $result); - $this->assertSame('validation failed', $result->unwrapErr()); - } - #[Test] public function or_withAnotherErr_returns_second_err(): void { @@ -378,17 +307,6 @@ public function match_calls_err_function(): void $this->assertSame('Error: error', $result); } - #[Test] - public function match_withDifferentReturnTypes_returns_err_branch(): void - { - $err = new Err(404); - $result = $err->match( - fn ($value) => ['status' => 'ok', 'data' => $value], - fn ($error) => ['status' => 'error', 'code' => $error], - ); - $this->assertSame(['status' => 'error', 'code' => 404], $result); - } - #[Test] public function match_supportsNamedArguments(): void { @@ -425,22 +343,6 @@ public function err_withFalseValue_handles_false(): void $this->assertTrue($err->isErr()); } - #[Test] - public function err_withZeroValue_handles_zero(): void - { - $err = new Err(0); - $this->assertSame(0, $err->unwrapErr()); - $this->assertTrue($err->isErr()); - } - - #[Test] - public function err_withEmptyString_handles_empty_string(): void - { - $err = new Err(''); - $this->assertSame('', $err->unwrapErr()); - $this->assertTrue($err->isErr()); - } - #[Test] public function chainingOperations_applies_transformations(): void { @@ -454,19 +356,6 @@ public function chainingOperations_applies_transformations(): void $this->assertSame('Final: [INITIAL ERROR]', $result->unwrapErr()); } - #[Test] - public function exceptionAsErrorValue_handles_exception(): void - { - $exception = new \RuntimeException('Something went wrong'); - $err = new Err($exception); - - $this->assertTrue($err->isErr()); - $this->assertSame($exception, $err->unwrapErr()); - - $handled = $err->mapErr(fn ($e) => $e->getMessage()); - $this->assertSame('Something went wrong', $handled->unwrapErr()); - } - /** * リテラル型を int に広げます(共変テンプレートは定数型を保持するため). */ diff --git a/tests/OkTest.php b/tests/OkTest.php index ba2bcdb..3824549 100644 --- a/tests/OkTest.php +++ b/tests/OkTest.php @@ -57,30 +57,6 @@ public function unwrap_returns_value(): void $this->assertSame(42, $ok->unwrap()); } - #[Test] - public function unwrap_withStringValue_returns_string(): void - { - $ok = new Ok('hello'); - $this->assertSame('hello', $ok->unwrap()); - } - - #[Test] - public function unwrap_withArrayValue_returns_array(): void - { - $value = ['foo' => 'bar']; - $ok = new Ok($value); - $this->assertSame($value, $ok->unwrap()); - } - - #[Test] - public function unwrap_withObjectValue_returns_object(): void - { - $value = new \stdClass(); - $value->foo = 'bar'; - $ok = new Ok($value); - $this->assertSame($value, $ok->unwrap()); - } - #[Test] public function unwrapErr_throws_exception(): void { @@ -97,15 +73,6 @@ public function expect_returns_value(): void $this->assertSame(42, $ok->expect('should have a value')); } - #[Test] - public function expectErr_throws_withGivenMessage(): void - { - $ok = new Ok(42); - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('should have an error'); - $ok->expectErr('should have an error'); - } - #[Test] public function unwrapErr_throwsUnwrapException_withValueInMessage(): void { @@ -163,15 +130,6 @@ public function map_applies_function_to_value(): void $this->assertSame(20, $mapped->unwrap()); } - #[Test] - public function map_withTypeChange_transforms_type(): void - { - $ok = new Ok(42); - $mapped = $ok->map(fn ($x) => "Value is: $x"); - $this->assertInstanceOf(Ok::class, $mapped); - $this->assertSame('Value is: 42', $mapped->unwrap()); - } - #[Test] public function mapErr_does_nothing(): void { @@ -240,32 +198,6 @@ public function andThen_applies_function(): void $this->assertSame(20, $result->unwrap()); } - #[Test] - public function andThen_withDifferentErrorType_chains_results(): void - { - $ok = new Ok(self::asInt(10)); - $result = $ok->andThen( - fn ($x) => $x > 5 ? new Ok("value: $x") : new Err(new \DomainException('too small')), - ); - - $this->assertInstanceOf(Ok::class, $result); - $this->assertSame('value: 10', $result->unwrap()); - } - - #[Test] - public function andThen_withDifferentErrorType_returns_new_err(): void - { - $ok = new Ok(self::asInt(3)); - $result = $ok->andThen( - fn ($x) => $x > 5 ? new Ok("value: $x") : new Err(new \DomainException('too small')), - ); - - $this->assertInstanceOf(Err::class, $result); - $error = $result->unwrapErr(); - $this->assertInstanceOf(\DomainException::class, $error); - $this->assertSame('too small', $error->getMessage()); - } - #[Test] public function or_returns_self(): void { @@ -306,17 +238,6 @@ public function match_calls_ok_function(): void $this->assertSame('Success: 42', $result); } - #[Test] - public function match_withDifferentReturnTypes_returns_ok_branch(): void - { - $ok = new Ok('hello'); - $result = $ok->match( - fn ($value) => \strlen($value), - fn ($error) => -1, - ); - $this->assertSame(5, $result); - } - #[Test] public function match_supportsNamedArguments(): void { @@ -353,22 +274,6 @@ public function ok_withFalseValue_handles_false(): void $this->assertTrue($ok->isOk()); } - #[Test] - public function ok_withZeroValue_handles_zero(): void - { - $ok = new Ok(0); - $this->assertSame(0, $ok->unwrap()); - $this->assertTrue($ok->isOk()); - } - - #[Test] - public function ok_withEmptyString_handles_empty_string(): void - { - $ok = new Ok(''); - $this->assertSame('', $ok->unwrap()); - $this->assertTrue($ok->isOk()); - } - #[Test] public function chainingOperations_applies_transformations(): void {