TestCase for Custom transformations.
More...
◆ setUp()
TransformationsCustomTest::setUp |
( |
| ) |
|
|
protected |
Definition at line 27 of file TransformationsCustomTest.php.
27 : void
28 {
29 $language = $this->createMock(\ilLanguage::class);
31
32 $this->custom = $this->f->custom()->transformation(
33 function ($value) {
34 if (!is_string($value)) {
35 throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
36 }
37 return $value;
38 }
39 );
40 }
Class ChatMainBarProvider \MainMenu\Provider.
◆ tearDown()
TransformationsCustomTest::tearDown |
( |
| ) |
|
|
protected |
◆ testApplyToWithValidValueReturnsAnOkResult()
TransformationsCustomTest::testApplyToWithValidValueReturnsAnOkResult |
( |
| ) |
|
Definition at line 140 of file TransformationsCustomTest.php.
141 {
142 $factory = new \ILIAS\Data\Factory();
143 $valueObject =
$factory->ok(self::TEST_STRING);
144
145 $resultObject = $this->custom->applyTo($valueObject);
146
147 $this->assertEquals(self::TEST_STRING, $resultObject->value());
148 $this->assertFalse($resultObject->isError());
149 }
References $factory.
◆ testInvoke()
TransformationsCustomTest::testInvoke |
( |
| ) |
|
Definition at line 85 of file TransformationsCustomTest.php.
86 {
87 $custom = $this->f->custom()->transformation(
88 function ($value) {
89 if (!is_string($value)) {
90 throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
91 }
92 return $value;
93 }
94 );
95
97 $this->assertEquals(self::TEST_STRING,
$result);
98 }
References $custom, and $result.
◆ testInvokeFails()
TransformationsCustomTest::testInvokeFails |
( |
| ) |
|
Definition at line 100 of file TransformationsCustomTest.php.
101 {
102 $custom = $this->f->custom()->transformation(
103 function ($value) {
104 if (!is_string($value)) {
105 throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
106 }
107 return $value;
108 }
109 );
110
111 $raised = false;
112 try {
113 $lower_string =
$custom(array());
114 }
catch (InvalidArgumentException
$e) {
115 $this->assertEquals(
"'array' is not a string.",
$e->getMessage());
116 $raised = true;
117 }
118 $this->assertTrue($raised);
119
120 $raised = false;
121 try {
122 $lower_string =
$custom(12345);
123 }
catch (InvalidArgumentException
$e) {
124 $this->assertEquals(
"'integer' is not a string.",
$e->getMessage());
125 $raised = true;
126 }
127 $this->assertTrue($raised);
128
129 $raised = false;
130 try {
131 $std_class = new stdClass();
132 $lower_string =
$custom($std_class);
133 }
catch (InvalidArgumentException
$e) {
134 $this->assertEquals(
"'object' is not a string.",
$e->getMessage());
135 $raised = true;
136 }
137 $this->assertTrue($raised);
138 }
References $custom, and Vendor\Package\$e.
◆ testTransform()
TransformationsCustomTest::testTransform |
( |
| ) |
|
◆ testTransformFails()
TransformationsCustomTest::testTransformFails |
( |
| ) |
|
Definition at line 54 of file TransformationsCustomTest.php.
55 {
56 $raised = false;
57 try {
58 $lower_string = $this->custom->transform(array());
59 }
catch (InvalidArgumentException
$e) {
60 $this->assertEquals(
"'array' is not a string.",
$e->getMessage());
61 $raised = true;
62 }
63 $this->assertTrue($raised);
64
65 $raised = false;
66 try {
67 $lower_string = $this->custom->transform(12345);
68 }
catch (InvalidArgumentException
$e) {
69 $this->assertEquals(
"'integer' is not a string.",
$e->getMessage());
70 $raised = true;
71 }
72 $this->assertTrue($raised);
73
74 $raised = false;
75 try {
76 $std_class = new stdClass();
77 $lower_string = $this->custom->transform($std_class);
78 }
catch (InvalidArgumentException
$e) {
79 $this->assertEquals(
"'object' is not a string.",
$e->getMessage());
80 $raised = true;
81 }
82 $this->assertTrue($raised);
83 }
References Vendor\Package\$e.
◆ $custom
TransformationsCustomTest::$custom |
|
private |
◆ $f
TransformationsCustomTest::$f |
|
private |
◆ TEST_STRING
const TransformationsCustomTest::TEST_STRING = "Test" |
The documentation for this class was generated from the following file: