ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ListTransformationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use PHPUnit\Framework\TestCase;
27use UnexpectedValueException;
28
29class ListTransformationTest extends TestCase
30{
34 public function testListTransformationIsValid(): void
35 {
36 $listTransformation = new ListTransformation(new StringTransformation());
37
38 $result = $listTransformation->transform(['hello', 'world']);
39
40 $this->assertEquals(['hello', 'world'], $result);
41 }
42
44 {
45 $listTransformation = new ListTransformation(new StringTransformation());
46 $this->assertSame([], $listTransformation->transform([]));
47 }
48
49 public function testApplyToOnEmptyArrayDoesNotFail(): void
50 {
51 $listTransformation = new ListTransformation(new StringTransformation());
52 $result = $listTransformation->applyTo(new Ok([]));
53 $this->assertFalse($result->isError());
54 }
55
56 public function testTransformOnNullFails(): void
57 {
58 $this->expectNotToPerformAssertions();
59
60 $listTransformation = new ListTransformation(new StringTransformation());
61 try {
62 $result = $listTransformation->transform(null);
63 } catch (UnexpectedValueException $exception) {
64 return;
65 }
66
67 $this->fail();
68 }
69
70 public function testApplyToOnNullFails(): void
71 {
72 $listTransformation = new ListTransformation(new StringTransformation());
73 $result = $listTransformation->applyTo(new Ok(null));
74 $this->assertTrue($result->isError());
75 }
76
77
78 public function testListTransformationIsInvalid(): void
79 {
80 $this->expectNotToPerformAssertions();
81
82 $listTransformation = new ListTransformation(new StringTransformation());
83
84 try {
85 $result = $listTransformation->transform(['hello', 2]);
86 } catch (UnexpectedValueException $exception) {
87 return;
88 }
89
90 $this->fail();
91 }
92
93 public function testListApplyIsValid(): void
94 {
95 $listTransformation = new ListTransformation(new StringTransformation());
96
97 $result = $listTransformation->applyTo(new Ok(['hello', 'world']));
98
99 $this->assertEquals(['hello', 'world'], $result->value());
100 $this->assertTrue($result->isOK());
101 }
102
103 public function testListApplyIsInvalid(): void
104 {
105 $listTransformation = new ListTransformation(new StringTransformation());
106
107 $result = $listTransformation->applyTo(new Ok(['hello', 2]));
108
109 $this->assertTrue($result->isError());
110 }
111}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31