19declare(strict_types=1);
26use PHPUnit\Framework\TestCase;
27use UnexpectedValueException;
38 $result = $transformation->transform([
'hello' =>
'world']);
40 $this->assertEquals([
'hello' =>
'world'], $result);
45 $this->expectNotToPerformAssertions();
50 $result = $transformation->transform([
'world']);
51 }
catch (UnexpectedValueException $exception) {
60 $this->expectNotToPerformAssertions();
65 $result = $transformation->transform([
'hello' => 1]);
66 }
catch (UnexpectedValueException $exception) {
75 $this->expectNotToPerformAssertions();
80 $result = $transformation->transform(1);
81 }
catch (UnexpectedValueException $exception) {
92 $result = $transformation->applyTo(
new Ok([
'hello' =>
'world']));
94 $this->assertEquals([
'hello' =>
'world'], $result->value());
101 $result = $transformation->applyTo(
new Ok([
'world']));
103 $this->assertTrue($result->isError());
110 $result = $transformation->applyTo(
new Ok([
'hello' => 1]));
112 $this->assertTrue($result->isError());
119 $result = $transformation->applyTo(
new Ok(1));
121 $this->assertTrue($result->isError());
A result encapsulates a value or an error and simplifies the handling of those.