ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ComponentHelperTest Class Reference
+ Inheritance diagram for ComponentHelperTest:
+ Collaboration diagram for ComponentHelperTest:

Public Member Functions

 setUp ()
 
 test_check_arg_ok ()
 
 test_check_arg_not_ok ()
 
 test_check_int_arg_ok ()
 
 test_check_int_arg_not_ok ()
 
 test_check_string_arg_ok ()
 
 test_check_string_arg_not_ok ()
 
 test_check_arg_instanceof_ok ()
 
 test_check_arg_instanceof_not_ok ()
 
 test_check_arg_is_element_ok ()
 
 test_check_string_arg_is_element_not_ok ()
 
 test_to_array_with_array ()
 
 test_to_array_with_int ()
 
 test_check_arg_list_elements_ok ()
 
 test_check_arg_list_elements_no_ok ()
 
 test_check_arg_list_elements_multi_class_ok ()
 
 test_check_arg_list_elements_multi_class_not_ok ()
 
 test_check_arg_list_elements_string_or_int_ok ()
 
 test_check_arg_list_elements_string_or_int_not_ok ()
 
 test_check_arg_list_ok ()
 
 test_check_arg_list_not_ok_1 ()
 
 test_check_arg_list_not_ok_2 ()
 

Detailed Description

Member Function Documentation

◆ setUp()

ComponentHelperTest::setUp ( )

Definition at line 47 of file ComponentHelperTest.php.

47 {
48 $this->mock = new ComponentMock();
49 }

◆ test_check_arg_instanceof_not_ok()

ComponentHelperTest::test_check_arg_instanceof_not_ok ( )

Definition at line 117 of file ComponentHelperTest.php.

117 {
118 try {
119 $this->mock->_checkArgInstanceOf("some_arg", $this, ComponentMock::class);
120 $this->assertFalse("This should not happen.");
121 }
122 catch (\InvalidArgumentException $e) {
123 $this->assertEquals("Argument 'some_arg': expected ComponentMock, got ComponentHelperTest", $e->getMessage());
124 }
125 }

◆ test_check_arg_instanceof_ok()

ComponentHelperTest::test_check_arg_instanceof_ok ( )

Definition at line 108 of file ComponentHelperTest.php.

108 {
109 try {
110 $this->mock->_checkArgInstanceOf("some_arg", $this->mock, ComponentMock::class);
111 }
112 catch (\InvalidArgumentException $e) {
113 $this->assertFalse("This should not happen.");
114 }
115 }

◆ test_check_arg_is_element_ok()

ComponentHelperTest::test_check_arg_is_element_ok ( )

Definition at line 129 of file ComponentHelperTest.php.

129 {
130 try {
131 $this->mock->_checkArgIsElement("some_arg", "bar", array("foo", "bar"), "foobar");
132 }
133 catch (\InvalidArgumentException $e) {
134 $this->assertFalse("This should not happen.");
135 }
136 }

◆ test_check_arg_list_elements_multi_class_not_ok()

ComponentHelperTest::test_check_arg_list_elements_multi_class_not_ok ( )

Definition at line 192 of file ComponentHelperTest.php.

192 {
193 $l = array(new Class1(), new Class2(), new Class3(), new Class2());
194 try {
195 $this->mock->_checkArgListElements("some_arg", $l, array("Class1", "Class2"));
196 $this->assertFalse("This should not happen.");
197 }
198 catch (\InvalidArgumentException $e) {
199 $this->assertEquals("Argument 'some_arg': expected Class1, Class2, got Class3", $e->getMessage());
200 }
201 }
global $l
Definition: afr.php:30

References $l.

◆ test_check_arg_list_elements_multi_class_ok()

ComponentHelperTest::test_check_arg_list_elements_multi_class_ok ( )

Definition at line 182 of file ComponentHelperTest.php.

182 {
183 $l = array(new Class1(), new Class2(), new Class1());
184 try {
185 $this->mock->_checkArgListElements("some_arg", $l, array("Class1", "Class2"));
186 }
187 catch (\InvalidArgumentException $e) {
188 $this->assertFalse("This should not happen.");
189 }
190 }

References $l.

◆ test_check_arg_list_elements_no_ok()

ComponentHelperTest::test_check_arg_list_elements_no_ok ( )

Definition at line 171 of file ComponentHelperTest.php.

171 {
172 $l = array(new Class1(), new Class1(), new Class2());
173 try {
174 $this->mock->_checkArgListElements("some_arg", $l, array("Class1"));
175 $this->assertFalse("This should not happen.");
176 }
177 catch (\InvalidArgumentException $e) {
178 $this->assertEquals("Argument 'some_arg': expected Class1, got Class2", $e->getMessage());
179 }
180 }

References $l.

◆ test_check_arg_list_elements_ok()

ComponentHelperTest::test_check_arg_list_elements_ok ( )

Definition at line 161 of file ComponentHelperTest.php.

161 {
162 $l = array(new Class1(), new Class1(), new Class1());
163 try {
164 $this->mock->_checkArgListElements("some_arg", $l, array("Class1"));
165 }
166 catch (\InvalidArgumentException $e) {
167 $this->assertFalse("This should not happen.");
168 }
169 }

References $l.

◆ test_check_arg_list_elements_string_or_int_not_ok()

ComponentHelperTest::test_check_arg_list_elements_string_or_int_not_ok ( )

Definition at line 213 of file ComponentHelperTest.php.

213 {
214 $l = array(1, new Class1());
215 try {
216 $this->mock->_checkArgListElements("some_arg", $l, array("string", "int"));
217 $this->assertFalse("This should not happen.");
218 }
219 catch (\InvalidArgumentException $e) {
220 $this->assertEquals("Argument 'some_arg': expected string, int, got Class1", $e->getMessage());
221 }
222 }

References $l.

◆ test_check_arg_list_elements_string_or_int_ok()

ComponentHelperTest::test_check_arg_list_elements_string_or_int_ok ( )

Definition at line 203 of file ComponentHelperTest.php.

203 {
204 $l = array(1, "foo");
205 try {
206 $this->mock->_checkArgListElements("some_arg", $l, array("string", "int"));
207 }
208 catch (\InvalidArgumentException $e) {
209 $this->assertFalse("This should not happen.");
210 }
211 }

References $l.

◆ test_check_arg_list_not_ok_1()

ComponentHelperTest::test_check_arg_list_not_ok_1 ( )

Definition at line 242 of file ComponentHelperTest.php.

242 {
243 $l = array("a" => 1, "b" => 2, 4 => 3);
244 try {
245 $this->mock->_checkArgList
246 ( "some_arg"
247 , $l
248 , function($k,$v) {
249 return is_string($k) && is_int($v);
250 }
251 , function($k, $v) {
252 return "expected keys of type string and integer values, got ($k => $v)";
253 });
254 $this->assertFalse("This should not happen.");
255 }
256 catch (\InvalidArgumentException $e) {
257 $m = "expected keys of type string and integer values, got (4 => 3)";
258 $this->assertEquals("Argument 'some_arg': $m", $e->getMessage());
259 }
260 }

References $l.

◆ test_check_arg_list_not_ok_2()

ComponentHelperTest::test_check_arg_list_not_ok_2 ( )

Definition at line 262 of file ComponentHelperTest.php.

262 {
263 $l = array("a" => 1, "b" => 2, "c" => "d");
264 try {
265 $this->mock->_checkArgList
266 ( "some_arg"
267 , $l
268 , function($k,$v) {
269 return is_string($k) && is_int($v);
270 }
271 , function($k, $v) {
272 return "expected keys of type string and integer values, got ($k => $v)";
273 });
274
275 $this->assertFalse("This should not happen.");
276 }
277 catch (\InvalidArgumentException $e) {
278 $m = "expected keys of type string and integer values, got (c => d)";
279 $this->assertEquals("Argument 'some_arg': $m", $e->getMessage());
280 }
281 }

References $l.

◆ test_check_arg_list_ok()

ComponentHelperTest::test_check_arg_list_ok ( )

Definition at line 224 of file ComponentHelperTest.php.

224 {
225 $l = array("a" => 1, "b" => 2, "c" => 3);
226 try {
227 $this->mock->_checkArgList
228 ( "some_arg"
229 , $l
230 , function($k,$v) {
231 return is_string($k) && is_int($v);
232 }
233 , function($k, $v) {
234 return "expected keys of type string and integer values, got ($k => $v)";
235 });
236 }
237 catch (\InvalidArgumentException $e) {
238 $this->assertFalse("This should not happen.");
239 }
240 }

References $l.

◆ test_check_arg_not_ok()

ComponentHelperTest::test_check_arg_not_ok ( )

Definition at line 60 of file ComponentHelperTest.php.

60 {
61 try {
62 $this->mock->_checkArg("some_arg", false, "some message");
63 $this->assertFalse("This should not happen.");
64 }
65 catch (\InvalidArgumentException $e) {
66 $this->assertEquals("Argument 'some_arg': some message", $e->getMessage());
67 }
68 }

◆ test_check_arg_ok()

ComponentHelperTest::test_check_arg_ok ( )

Definition at line 51 of file ComponentHelperTest.php.

51 {
52 try {
53 $this->mock->_checkArg("some_arg", true, "some message");
54 }
55 catch (\InvalidArgumentException $e) {
56 $this->assertFalse("This should not happen.");
57 }
58 }

◆ test_check_int_arg_not_ok()

ComponentHelperTest::test_check_int_arg_not_ok ( )

Definition at line 79 of file ComponentHelperTest.php.

79 {
80 try {
81 $this->mock->_checkIntArg("some_arg", "foo");
82 $this->assertFalse("This should not happen.");
83 }
84 catch (\InvalidArgumentException $e) {
85 $this->assertEquals("Argument 'some_arg': expected integer, got string 'foo'", $e->getMessage());
86 }
87 }

◆ test_check_int_arg_ok()

ComponentHelperTest::test_check_int_arg_ok ( )

Definition at line 70 of file ComponentHelperTest.php.

70 {
71 try {
72 $this->mock->_checkIntArg("some_arg", 1);
73 }
74 catch (\InvalidArgumentException $e) {
75 $this->assertFalse("This should not happen.");
76 }
77 }

◆ test_check_string_arg_is_element_not_ok()

ComponentHelperTest::test_check_string_arg_is_element_not_ok ( )

Definition at line 138 of file ComponentHelperTest.php.

138 {
139 try {
140 $this->mock->_checkArgIsElement("some_arg", "baz", array("foo", "bar"), "foobar");
141 $this->assertFalse("This should not happen.");
142 }
143 catch (\InvalidArgumentException $e) {
144 $this->assertEquals("Argument 'some_arg': expected foobar, got 'baz'", $e->getMessage());
145 }
146 }

◆ test_check_string_arg_not_ok()

ComponentHelperTest::test_check_string_arg_not_ok ( )

Definition at line 98 of file ComponentHelperTest.php.

98 {
99 try {
100 $this->mock->_checkStringArg("some_arg", 1);
101 $this->assertFalse("This should not happen.");
102 }
103 catch (\InvalidArgumentException $e) {
104 $this->assertEquals("Argument 'some_arg': expected string, got integer '1'", $e->getMessage());
105 }
106 }

◆ test_check_string_arg_ok()

ComponentHelperTest::test_check_string_arg_ok ( )

Definition at line 89 of file ComponentHelperTest.php.

89 {
90 try {
91 $this->mock->_checkStringArg("some_arg", "bar");
92 }
93 catch (\InvalidArgumentException $e) {
94 $this->assertFalse("This should not happen.");
95 }
96 }

◆ test_to_array_with_array()

ComponentHelperTest::test_to_array_with_array ( )

Definition at line 148 of file ComponentHelperTest.php.

148 {
149 $foo = array("foo", "bar");
150 $res = $this->mock->_toArray($foo);
151
152 $this->assertEquals($foo, $res);
153 }

References $res.

◆ test_to_array_with_int()

ComponentHelperTest::test_to_array_with_int ( )

Definition at line 155 of file ComponentHelperTest.php.

155 {
156 $foo = 1;
157 $res = $this->mock->_toArray($foo);
158 $this->assertEquals(array($foo), $res);
159 }

References $res.


The documentation for this class was generated from the following file: