19 declare(strict_types=1);
38 $this->assertInstanceOf(Transform::class,
new Transform());
41 #[Depends('testConstruct')] 46 $transformation = $this->getMockBuilder(Transformation::class)->getMock();
47 $transformation->method(
'applyTo')->willReturnCallback(
function (
Result $x) use ($transformed):
Result {
48 $this->assertEquals(
'x', $x->
value());
49 return new Ok($transformed);
59 $this->assertEquals([$transformed], $x->
value()->accepted());
63 $this->assertEquals($end, $x->
value());
66 #[Depends('testConstruct')] 70 $transformation = $this->getMockBuilder(Transformation::class)->getMock();
71 $transformation->method(
'applyTo')->willReturnCallback(
function (
Result $x):
Result {
72 $this->assertEquals(
'x', $x->
value());
73 return new Error(
'Sorryy.');
83 $this->assertFalse($x->
isOK());
87 $this->assertEquals($end, $x->
value());
90 #[Depends('testConstruct')] 94 $transformCalled =
false;
95 $transformation = $this->getMockBuilder(Transformation::class)->getMock();
96 $transformation->method(
'applyTo')->willReturnCallback(
function (
Result $x) use (&$transformCalled):
Result {
97 $transformCalled =
true;
108 $this->assertFalse($x->
isOK());
112 $this->assertEquals($end, $x->
value());
113 $this->assertFalse($transformCalled);
127 $this->assertTrue($result->isOK());
128 $this->assertEquals([
'hej' =>
'l'], $result->value());
isOK()
Get to know if the result is ok.
value()
Get the encapsulated value.
map(callable $f)
Create a new result where the contained value is modified with $f.
A result encapsulates a value or an error and simplifies the handling of those.