Add tap for Option and Result
This commit is contained in:
@@ -237,4 +237,26 @@ class OptionTest extends TestCase
|
||||
{
|
||||
$this->assertEquals('boy howdy', Option::unwrap(Option::Some('boy howdy')), '"Some" should return its value');
|
||||
}
|
||||
|
||||
#[TestDox('Tap succeeds with Some')]
|
||||
public function testTapSucceedsWithSome(): void
|
||||
{
|
||||
$value = '';
|
||||
$original = Option::Some('testing');
|
||||
$tapped = Option::tap(
|
||||
function (Option $it) use (&$value) { $value = Option::isSome($it) ? $it->get() : 'none'; }, $original);
|
||||
$this->assertEquals('testing', $value, 'The tapped function was not called');
|
||||
$this->assertSame($original, $tapped, 'The same option should have been returned');
|
||||
}
|
||||
|
||||
#[TestDox('Tap succeeds with None')]
|
||||
public function testTapSucceedsWithNone(): void
|
||||
{
|
||||
$value = '';
|
||||
$original = Option::None();
|
||||
$tapped = Option::tap(
|
||||
function (Option $it) use (&$value) { $value = Option::isSome($it) ? $it->get() : 'none'; }, $original);
|
||||
$this->assertEquals('none', $value, 'The tapped function was not called');
|
||||
$this->assertSame($original, $tapped, 'The same option should have been returned');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user