5require_once(
"libs/composer/vendor/autoload.php");
7require_once(__DIR__ .
"/../Renderer/TestComponent.php");
53 $this->called_gcnbfqn++;
80 $c = new \ILIAS\UI\Component\Test\TestComponent(
"foo");
81 $this->assertEquals(
"Test Component Test", $c->getCanonicalName());
86 $name1 = $this->mock->getCanonicalName();
87 $name2 = $this->mock->getCanonicalName();
88 $this->assertEquals($name1, $name2);
89 $this->assertEquals(1, $this->mock->called_gcnbfqn);
95 $this->mock->_checkArg(
"some_arg",
true,
"some message");
96 }
catch (\InvalidArgumentException $e) {
97 $this->assertFalse(
"This should not happen.");
104 $this->mock->_checkArg(
"some_arg",
false,
"some message");
105 $this->assertFalse(
"This should not happen.");
106 }
catch (\InvalidArgumentException $e) {
107 $this->assertEquals(
"Argument 'some_arg': some message", $e->getMessage());
114 $this->mock->_checkIntArg(
"some_arg", 1);
115 }
catch (\InvalidArgumentException $e) {
116 $this->assertFalse(
"This should not happen.");
123 $this->mock->_checkIntArg(
"some_arg",
"foo");
124 $this->assertFalse(
"This should not happen.");
125 }
catch (\InvalidArgumentException $e) {
126 $this->assertEquals(
"Argument 'some_arg': expected integer, got string 'foo'", $e->getMessage());
133 $this->mock->_checkStringArg(
"some_arg",
"bar");
134 }
catch (\InvalidArgumentException $e) {
135 $this->assertFalse(
"This should not happen.");
142 $this->mock->_checkStringArg(
"some_arg", 1);
143 $this->assertFalse(
"This should not happen.");
144 }
catch (\InvalidArgumentException $e) {
145 $this->assertEquals(
"Argument 'some_arg': expected string, got integer '1'", $e->getMessage());
152 $this->mock->_checkArgInstanceOf(
"some_arg", $this->mock, ComponentMock::class);
153 }
catch (\InvalidArgumentException $e) {
154 $this->assertFalse(
"This should not happen.");
161 $this->mock->_checkArgInstanceOf(
"some_arg", $this, ComponentMock::class);
162 $this->assertFalse(
"This should not happen.");
163 }
catch (\InvalidArgumentException $e) {
164 $this->assertEquals(
"Argument 'some_arg': expected ComponentMock, got ComponentHelperTest", $e->getMessage());
173 $this->mock->_checkArgIsElement(
"some_arg",
"bar", array(
"foo",
"bar"),
"foobar");
174 }
catch (\InvalidArgumentException $e) {
175 $this->assertFalse(
"This should not happen.");
182 $this->mock->_checkArgIsElement(
"some_arg",
"baz", array(
"foo",
"bar"),
"foobar");
183 $this->assertFalse(
"This should not happen.");
184 }
catch (\InvalidArgumentException $e) {
185 $this->assertEquals(
"Argument 'some_arg': expected foobar, got 'baz'", $e->getMessage());
191 $foo = array(
"foo",
"bar");
192 $res = $this->mock->_toArray($foo);
194 $this->assertEquals($foo,
$res);
200 $res = $this->mock->_toArray($foo);
201 $this->assertEquals(array($foo),
$res);
208 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1"));
209 }
catch (\InvalidArgumentException $e) {
210 $this->assertFalse(
"This should not happen.");
218 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1"));
219 $this->assertFalse(
"This should not happen.");
220 }
catch (\InvalidArgumentException $e) {
221 $this->assertEquals(
"Argument 'some_arg': expected Class1, got Class2", $e->getMessage());
229 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1",
"Class2"));
230 }
catch (\InvalidArgumentException $e) {
231 $this->assertFalse(
"This should not happen.");
239 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1",
"Class2"));
240 $this->assertFalse(
"This should not happen.");
241 }
catch (\InvalidArgumentException $e) {
242 $this->assertEquals(
"Argument 'some_arg': expected Class1, Class2, got Class3", $e->getMessage());
248 $l = array(1,
"foo");
250 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"string",
"int"));
251 }
catch (\InvalidArgumentException $e) {
252 $this->assertFalse(
"This should not happen.");
260 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"string",
"int"));
261 $this->assertFalse(
"This should not happen.");
262 }
catch (\InvalidArgumentException $e) {
263 $this->assertEquals(
"Argument 'some_arg': expected string, int, got Class1", $e->getMessage());
269 $l = array(
"a" => 1,
"b" => 2,
"c" => 3);
271 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
272 return is_string($k) && is_int($v);
273 },
function ($k, $v) {
274 return "expected keys of type string and integer values, got ($k => $v)";
276 }
catch (\InvalidArgumentException $e) {
277 $this->assertFalse(
"This should not happen.");
283 $l = array(
"a" => 1,
"b" => 2, 4 => 3);
285 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
286 return is_string($k) && is_int($v);
287 },
function ($k, $v) {
288 return "expected keys of type string and integer values, got ($k => $v)";
290 $this->assertFalse(
"This should not happen.");
291 }
catch (\InvalidArgumentException $e) {
292 $m =
"expected keys of type string and integer values, got (4 => 3)";
293 $this->assertEquals(
"Argument 'some_arg': $m", $e->getMessage());
299 $l = array(
"a" => 1,
"b" => 2,
"c" =>
"d");
301 $this->mock->_checkArgList(
"some_arg",
$l,
function ($k, $v) {
302 return is_string($k) && is_int($v);
303 },
function ($k, $v) {
304 return "expected keys of type string and integer values, got ($k => $v)";
307 $this->assertFalse(
"This should not happen.");
308 }
catch (\InvalidArgumentException $e) {
309 $m =
"expected keys of type string and integer values, got (c => d)";
310 $this->assertEquals(
"Argument 'some_arg': $m", $e->getMessage());
317 $this->mock->_checkFloatArg(
"some_arg", 1.73);
318 }
catch (\InvalidArgumentException $e) {
319 $this->assertFalse(
"This should not happen.");
326 $this->mock->_checkFloatArg(
"some_arg",
"foo");
327 $this->assertFalse(
"This should not happen.");
328 }
catch (\InvalidArgumentException $e) {
329 $this->assertEquals(
"Argument 'some_arg': expected float, got string 'foo'", $e->getMessage());
An exception for terminatinating execution or to throw for unit testing.
test_check_float_arg_ok()
test_check_arg_list_elements_multi_class_not_ok()
test_check_arg_list_elements_multi_class_ok()
test_check_arg_list_elements_string_or_int_ok()
test_check_string_arg_is_element_not_ok()
test_check_arg_list_not_ok_1()
test_check_arg_instanceof_not_ok()
test_check_arg_is_element_ok()
test_check_string_arg_ok()
test_check_arg_list_elements_no_ok()
test_check_float_arg_not_ok()
test_check_string_arg_not_ok()
test_cachesCanonicalName()
test_check_arg_list_elements_string_or_int_not_ok()
test_check_arg_instanceof_ok()
test_check_arg_list_not_ok_2()
test_to_array_with_array()
test_check_arg_list_elements_ok()
test_check_int_arg_not_ok()
_checkFloatArg($which, $value)
_checkIntArg($which, $value)
_checkArgList($which, &$value, $check, $message)
_checkArgListElements($which, &$value, $classes)
_checkArgInstanceOf($which, $value, $class)
getCanonicalNameByFullyQualifiedName()
_checkArgIsElement($which, $value, $array, $name)
_checkStringArg($which, $value)
_checkArg($which, $check, $message)
catch(Exception $e) $message
checkArgList($which, array &$values, \Closure $check, \Closure $message)
Check every key and value of the list with a supplied closure.
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
checkArg($which, $check, $message)
/** Throw an InvalidArgumentException containing the message if $check is false.
checkIntArg($which, $value)
Throw an InvalidArgumentException if $value is no int.
toArray($value)
Wrap the given value in an array if it is no array.
checkArgListElements($which, array &$values, &$classes)
Check every element of the list if it is an instance of one of the given classes.
trait ComponentHelper
Provides common functionality for component implementations.
checkArgIsElement($which, $value, $array, $name)
Throw an InvalidArgumentException if $value is not an element of array.
checkFloatArg($which, $value)
Throw an InvalidArgumentException if $value is not a float.
checkArgInstanceOf($which, $value, $class)
Throw an InvalidArgumentException if $value is not an instance of $class.
foreach($_POST as $key=> $value) $res