19 declare(strict_types=1);
33 $language = $this->getMockBuilder(Language::class)->disableOriginalConstructor()->getMock();
40 public function testAccept(
string $value,
bool $successful): void
42 $language = $this->getMockBuilder(Language::class)->disableOriginalConstructor()->getMock();
45 $this->assertSame($successful, $transformation->accepts($value));
54 $this->expectException(UnexpectedValueException::class);
57 $language = $this->getMockBuilder(Language::class)->disableOriginalConstructor()->getMock();
60 $this->assertSame($value, $transformation->transform($value));
66 public function testApplyTo(
string $value,
bool $successful): void
68 $language = $this->getMockBuilder(Language::class)->disableOriginalConstructor()->getMock();
71 $result = $transformation->applyTo(
new Ok($value));
72 $this->assertSame($successful, $result->isOk());
74 $this->assertSame($value, $result->value());
76 $this->assertInstanceOf(UnexpectedValueException::class, $result->error());
83 'Invalid member.' => [
'hej',
false],
84 'Valid member.' => [
'foo',
true],
A result encapsulates a value or an error and simplifies the handling of those.