19 declare(strict_types=1);
26 require_once(
"vendor/composer/vendor/autoload.php");
28 require_once(__DIR__ .
"/../Renderer/TestComponent.php");
36 $this->checkArg($which, $check, $message);
41 $this->checkStringArg($which, $value);
46 $this->checkBoolArg($which, $value);
51 $this->checkArgInstanceOf($which, $value, $class);
56 $this->checkArgIsElement($which, $value, $array, $name);
61 return $this->toArray($value);
66 $this->checkArgListElements($which, $value, $classes);
71 $this->checkArgList($which, $value, $check, $message);
110 $this->assertEquals(
"Test Component Test",
$c->getCanonicalName());
113 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 116 $this->mock->_checkArg(
"some_arg",
true,
"some message");
121 $this->expectException(InvalidArgumentException::class);
122 $this->expectExceptionMessage(
"Argument 'some_arg': some message");
123 $this->mock->_checkArg(
"some_arg",
false,
"some message");
126 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 129 $this->mock->_checkStringArg(
"some_arg",
"bar");
134 $this->expectException(InvalidArgumentException::class);
135 $this->expectExceptionMessage(
"Argument 'some_arg': expected string, got integer '1'");
136 $this->mock->_checkStringArg(
"some_arg", 1);
139 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 142 $this->mock->_checkBoolArg(
"some_arg",
true);
147 $this->expectException(InvalidArgumentException::class);
148 $this->expectExceptionMessage(
"Argument 'some_arg': expected bool, got integer '1'");
149 $this->mock->_checkBoolArg(
"some_arg", 1);
152 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 155 $this->mock->_checkArgInstanceOf(
"some_arg", $this->mock, ComponentMock::class);
160 $this->expectException(InvalidArgumentException::class);
161 $this->expectExceptionMessage(
"Argument 'some_arg': expected ComponentMock, got ComponentHelperTest");
162 $this->mock->_checkArgInstanceOf(
"some_arg", $this, ComponentMock::class);
166 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 169 $this->mock->_checkArgIsElement(
"some_arg",
"bar", array(
"foo",
"bar"),
"foobar");
174 $this->expectException(InvalidArgumentException::class);
175 $this->expectExceptionMessage(
"Argument 'some_arg': expected foobar, got 'baz'");
176 $this->mock->_checkArgIsElement(
"some_arg",
"baz", array(
"foo",
"bar"),
"foobar");
181 $foo = array(
"foo",
"bar");
191 $this->assertEquals(array(
$foo),
$res);
194 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 198 $this->mock->_checkArgListElements(
"some_arg", $l, array(
"Class1"));
203 $this->expectException(InvalidArgumentException::class);
204 $this->expectExceptionMessage(
"Argument 'some_arg': expected Class1, got Class2");
206 $this->mock->_checkArgListElements(
"some_arg", $l, array(
"Class1"));
209 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 213 $this->mock->_checkArgListElements(
"some_arg", $l, array(
"Class1",
"Class2"));
218 $this->expectException(InvalidArgumentException::class);
219 $this->expectExceptionMessage(
"Argument 'some_arg': expected Class1, Class2, got Class3");
221 $this->mock->_checkArgListElements(
"some_arg", $l, array(
"Class1",
"Class2"));
224 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 227 $l = array(1,
"foo");
228 $this->mock->_checkArgListElements(
"some_arg", $l, array(
"string",
"int"));
233 $this->expectException(InvalidArgumentException::class);
234 $this->expectExceptionMessage(
"Argument 'some_arg': expected string, int, got Class1");
235 $l = array(1,
new Class1());
236 $this->mock->_checkArgListElements(
"some_arg", $l, array(
"string",
"int"));
239 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] 242 $l = array(
"a" => 1,
"b" => 2,
"c" => 3);
243 $this->mock->_checkArgList(
"some_arg", $l,
function ($k, $v) {
244 return is_string($k) && is_int($v);
245 },
function ($k, $v) {
246 return "expected keys of type string and integer values, got ($k => $v)";
252 $m =
"expected keys of type string and integer values, got (4 => 3)";
253 $this->expectException(InvalidArgumentException::class);
254 $this->expectExceptionMessage(
"Argument 'some_arg': $m");
255 $l = array(
"a" => 1,
"b" => 2, 4 => 3);
256 $this->mock->_checkArgList(
"some_arg", $l,
function ($k, $v) {
257 return is_string($k) && is_int($v);
258 },
function ($k, $v) {
259 return "expected keys of type string and integer values, got ($k => $v)";
265 $m =
"expected keys of type string and integer values, got (c => d)";
266 $this->expectException(InvalidArgumentException::class);
267 $this->expectExceptionMessage(
"Argument 'some_arg': $m");
268 $l = array(
"a" => 1,
"b" => 2,
"c" =>
"d");
269 $this->mock->_checkArgList(
"some_arg", $l,
function ($k, $v) {
270 return is_string($k) && is_int($v);
271 },
function ($k, $v) {
272 return "expected keys of type string and integer values, got ($k => $v)";
279 $a->random_data =
"A";
281 $b->random_data =
"B";
283 $c->random_data =
"C";
284 $c->sub_components = [
$a,
$b];
303 $a->random_data =
"A";
305 $b->random_data =
"B";
307 $c->random_data =
"C";
308 $c->sub_components = [
$a,
$b];
312 $clone->random_data = strtolower($c->random_data);
313 $clone->sub_components =
$res;
316 $c2 =
$c->reduceWith(
$f);
318 [$a2, $b2] = $c2->sub_components;
320 $this->assertNotEquals(spl_object_id(
$a), spl_object_id($a2));
321 $this->assertNotEquals(spl_object_id(
$b), spl_object_id($b2));
322 $this->assertNotEquals(spl_object_id(
$c), spl_object_id($c2));
324 $this->assertEquals(
"A",
$a->random_data);
325 $this->assertEquals(
"B",
$b->random_data);
326 $this->assertEquals(
"C",
$c->random_data);
327 $this->assertEquals([
$a,
$b],
$c->sub_components);
329 $this->assertEquals(
"a", $a2->random_data);
330 $this->assertEquals(
"b", $b2->random_data);
331 $this->assertEquals(
"c", $c2->random_data);
337 $a->random_data =
"A";
339 $b->random_data =
"B";
341 $c->random_data =
"C";
342 $c->sub_components = [
$a,
$b];
345 return [
$c,
$c->random_data];
349 $this->assertEquals([
$a,
$b],
$res->sub_components);
_checkArgListElements(string $which, array &$value, $classes)
testReduceWithSubStructureIsTransient()
_checkBoolArg(string $which, $value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testCheckArgListElementsStringOrIntNotOk()
_checkArg(string $which, bool $check, string $message)
testCheckStringArgNotOk()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
_checkStringArg(string $which, $value)
testCheckArgInstanceofOk()
testCheckArgListElementsStringOrIntOk()
testCheckArgListElementsNoOk()
testCheckArgListElementsMultiClassOk()
testCheckArgIsElementOk()
testReduceWithDoesNotModify()
_checkArgIsElement(string $which, $value, array $array, string $name)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
testCheckStringArgIsElementNotOk()
testCheckArgListElementsOk()
testCheckArgListElementsMultiClassNotOk()
testCheckArgInstanceofNotOk()
_checkArgInstanceOf(string $which, $value, string $class)
_checkArgList(string $which, array &$value, Closure $check, Closure $message)