5require_once(
"libs/composer/vendor/autoload.php");
8 use \ILIAS\UI\Implementation\Component\ComponentHelper;
10 public function _checkArg($which, $check, $message) {
11 $this->checkArg($which, $check, $message);
14 $this->checkIntArg($which, $value);
17 $this->checkStringArg($which, $value);
20 $this->checkArgInstanceOf($which, $value, $class);
23 $this->checkArgIsElement($which, $value, $array, $name);
26 return $this->toArray($value);
29 $this->checkArgListElements($which, $value, $classes);
32 $this->checkArgList($which, $value, $check, $message);
53 $this->mock->_checkArg(
"some_arg",
true,
"some message");
55 catch (\InvalidArgumentException $e) {
56 $this->assertFalse(
"This should not happen.");
62 $this->mock->_checkArg(
"some_arg",
false,
"some message");
63 $this->assertFalse(
"This should not happen.");
65 catch (\InvalidArgumentException $e) {
66 $this->assertEquals(
"Argument 'some_arg': some message", $e->getMessage());
72 $this->mock->_checkIntArg(
"some_arg", 1);
74 catch (\InvalidArgumentException $e) {
75 $this->assertFalse(
"This should not happen.");
81 $this->mock->_checkIntArg(
"some_arg",
"foo");
82 $this->assertFalse(
"This should not happen.");
84 catch (\InvalidArgumentException $e) {
85 $this->assertEquals(
"Argument 'some_arg': expected integer, got string 'foo'", $e->getMessage());
91 $this->mock->_checkStringArg(
"some_arg",
"bar");
93 catch (\InvalidArgumentException $e) {
94 $this->assertFalse(
"This should not happen.");
100 $this->mock->_checkStringArg(
"some_arg", 1);
101 $this->assertFalse(
"This should not happen.");
103 catch (\InvalidArgumentException $e) {
104 $this->assertEquals(
"Argument 'some_arg': expected string, got integer '1'", $e->getMessage());
110 $this->mock->_checkArgInstanceOf(
"some_arg", $this->mock, ComponentMock::class);
112 catch (\InvalidArgumentException $e) {
113 $this->assertFalse(
"This should not happen.");
119 $this->mock->_checkArgInstanceOf(
"some_arg", $this, ComponentMock::class);
120 $this->assertFalse(
"This should not happen.");
122 catch (\InvalidArgumentException $e) {
123 $this->assertEquals(
"Argument 'some_arg': expected ComponentMock, got ComponentHelperTest", $e->getMessage());
131 $this->mock->_checkArgIsElement(
"some_arg",
"bar", array(
"foo",
"bar"),
"foobar");
133 catch (\InvalidArgumentException $e) {
134 $this->assertFalse(
"This should not happen.");
140 $this->mock->_checkArgIsElement(
"some_arg",
"baz", array(
"foo",
"bar"),
"foobar");
141 $this->assertFalse(
"This should not happen.");
143 catch (\InvalidArgumentException $e) {
144 $this->assertEquals(
"Argument 'some_arg': expected foobar, got 'baz'", $e->getMessage());
149 $foo = array(
"foo",
"bar");
150 $res = $this->mock->_toArray($foo);
152 $this->assertEquals($foo,
$res);
157 $res = $this->mock->_toArray($foo);
158 $this->assertEquals(array($foo),
$res);
164 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1"));
166 catch (\InvalidArgumentException $e) {
167 $this->assertFalse(
"This should not happen.");
174 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1"));
175 $this->assertFalse(
"This should not happen.");
177 catch (\InvalidArgumentException $e) {
178 $this->assertEquals(
"Argument 'some_arg': expected Class1, got Class2", $e->getMessage());
185 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1",
"Class2"));
187 catch (\InvalidArgumentException $e) {
188 $this->assertFalse(
"This should not happen.");
195 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"Class1",
"Class2"));
196 $this->assertFalse(
"This should not happen.");
198 catch (\InvalidArgumentException $e) {
199 $this->assertEquals(
"Argument 'some_arg': expected Class1, Class2, got Class3", $e->getMessage());
204 $l = array(1,
"foo");
206 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"string",
"int"));
208 catch (\InvalidArgumentException $e) {
209 $this->assertFalse(
"This should not happen.");
216 $this->mock->_checkArgListElements(
"some_arg",
$l, array(
"string",
"int"));
217 $this->assertFalse(
"This should not happen.");
219 catch (\InvalidArgumentException $e) {
220 $this->assertEquals(
"Argument 'some_arg': expected string, int, got Class1", $e->getMessage());
225 $l = array(
"a" => 1,
"b" => 2,
"c" => 3);
227 $this->mock->_checkArgList
231 return is_string($k) && is_int($v);
234 return "expected keys of type string and integer values, got ($k => $v)";
237 catch (\InvalidArgumentException $e) {
238 $this->assertFalse(
"This should not happen.");
243 $l = array(
"a" => 1,
"b" => 2, 4 => 3);
245 $this->mock->_checkArgList
249 return is_string($k) && is_int($v);
252 return "expected keys of type string and integer values, got ($k => $v)";
254 $this->assertFalse(
"This should not happen.");
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());
263 $l = array(
"a" => 1,
"b" => 2,
"c" =>
"d");
265 $this->mock->_checkArgList
269 return is_string($k) && is_int($v);
272 return "expected keys of type string and integer values, got ($k => $v)";
275 $this->assertFalse(
"This should not happen.");
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());
An exception for terminatinating execution or to throw for unit testing.
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_string_arg_not_ok()
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()
_checkIntArg($which, $value)
_checkArgList($which, &$value, $check, $message)
_checkArgListElements($which, &$value, $classes)
_checkArgInstanceOf($which, $value, $class)
_checkArgIsElement($which, $value, $array, $name)
_checkStringArg($which, $value)
_checkArg($which, $check, $message)