32 require_once(__DIR__ .
'/../../libs/composer/vendor/autoload.php');
46 protected function setUp(): void
48 $this->language_mock = $this->createMock(\ilLanguage::class);
49 $this->
refinery = new \ILIAS\Refinery\Factory(
55 $static_flush->flush();
66 [self::TEST_CONTAINER],
68 public function getNodes(): array
70 return [
new Node(
'127.0.0.1', 11211, 100)];
85 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'one')));
86 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'two')));
87 $this->assertInstanceOf(VoidContainer::class, $services->get($this->getDummyRequest(
'three')));
95 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'one')));
96 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'two')));
97 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'three')));
114 $this->assertEquals(
'one', $one->getContainerKey());
115 $this->assertEquals(
'two', $two->getContainerKey());
116 $this->assertEquals(
'three', $three->getContainerKey());
118 $container_one = $services->get($one);
119 $container_two = $services->get($two);
120 $container_three = $services->get($three);
122 $this->assertInstanceOf(ActiveContainer::class, $container_one);
123 $this->assertInstanceOf(ActiveContainer::class, $container_two);
124 $this->assertInstanceOf(VoidContainer::class, $container_three);
126 $container_one->set(
'test',
'test_value');
127 $this->assertTrue($container_one->has(
'test'));
128 $this->assertEquals(
'test_value', $container_one->get(
'test', $this->refinery->to()->string()));
130 $container_two->set(
'test',
'test_value');
131 $this->assertTrue($container_two->has(
'test'));
132 $this->assertEquals(
'test_value', $container_two->get(
'test', $this->refinery->to()->string()));
134 $container_three->set(
'test',
'test_value');
135 $this->assertFalse($container_three->has(
'test'));
136 $this->assertNull($container_three->get(
'test', $this->refinery->to()->string()));
147 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
152 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
156 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
162 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
166 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
189 $this->expectException(\InvalidArgumentException::class);
200 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
204 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
211 $to_string = $this->
refinery->kindlyTo()->string();
216 $this->assertTrue($static->isAvailable());
220 $this->assertInstanceOf(ActiveContainer::class,
$container);
222 $this->assertEquals(self::TEST_CONTAINER,
$container->getContainerName());
227 $this->assertEquals(
'test_value',
$container->get(
'test', $to_string));
249 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
253 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
257 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
259 $services->flushAdapter();
261 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
270 $this->assertEquals(self::TEST_CONTAINER,
$container->getContainerName());
272 $apcu =
new APCu($config);
273 if (!$apcu->isAvailable() || !(bool) ini_get(
'apc.enable_cli')) {
274 $this->markTestSkipped(
'APCu is not available or not enabled for CLI');
277 $to_string = $this->
refinery->kindlyTo()->string();
282 $this->assertEquals(
'test_value',
$container->get(
'test', $to_string));
303 $this->assertEquals(self::TEST_CONTAINER,
$container->getContainerName());
306 if (!$apcu->isAvailable()) {
307 $this->markTestSkipped(
'Memcached is not available');
313 $this->assertEquals(
'test_value',
$container->get(
'test'));
333 $first_object = new \stdClass();
334 $first_object->test =
'test';
335 $container->set(
'first_object', serialize($first_object));
337 $this->assertTrue(
$container->has(
'first_object'));
339 $to_string = $this->
refinery->kindlyTo()->string();
342 $first_object_from_cache = unserialize(
$data, [
'allowed_classes' => [\stdClass::class]]);
343 $this->assertInstanceOf(\stdClass::class, $first_object_from_cache);
344 $this->assertEquals($first_object, $first_object_from_cache);
353 $to_string = $this->
refinery->to()->string();
354 $to_int = $this->
refinery->to()->int();
355 $to_array = $this->
refinery->to()->listOf($to_string);
356 $to_bool = $this->
refinery->to()->bool();
362 $string_from_cache =
$container->get(
'string', $to_string);
363 $this->assertEquals($string, $string_from_cache);
364 $this->assertEquals(null,
$container->get(
'string', $to_int));
365 $this->assertEquals(null,
$container->get(
'string', $to_bool));
366 $this->assertEquals(null,
$container->get(
'string', $to_array));
367 $this->assertIsString($string_from_cache);
370 $array = [
'test',
'test2',
'test3'];
373 $array_from_cache =
$container->get(
'array', $to_array);
374 $this->assertEquals($array, $array_from_cache);
375 $this->assertEquals(null,
$container->get(
'array', $to_int));
376 $this->assertEquals(null,
$container->get(
'array', $to_bool));
377 $this->assertEquals(null,
$container->get(
'array', $to_string));
378 $this->assertIsArray($array_from_cache);
384 $bool_from_cache =
$container->get(
'bool', $to_bool);
385 $this->assertEquals($bool, $bool_from_cache);
386 $this->assertEquals(null,
$container->get(
'bool', $to_int));
387 $this->assertEquals(null,
$container->get(
'bool', $to_array));
388 $this->assertEquals(null,
$container->get(
'bool', $to_string));
389 $this->assertIsBool($bool_from_cache);
392 $array_with_different_values = [
'test' =>
true,
'test2' => 123,
'test3' => [
'test' =>
'test'],
'test4' => null];
393 $container->set(
'array_with_different_values', $array_with_different_values);
394 $this->assertTrue(
$container->has(
'array_with_different_values'));
396 $trafo = $this->
refinery->to()->dictOf(
397 $this->
refinery->custom()->transformation(
407 $array_with_different_values_from_cache =
$container->get(
'array_with_different_values', $trafo);
408 $this->assertEquals($array_with_different_values, $array_with_different_values_from_cache);
409 $this->assertIsArray($array_with_different_values_from_cache);
410 $this->assertIsBool($array_with_different_values_from_cache[
'test']);
411 $this->assertIsInt($array_with_different_values_from_cache[
'test2']);
412 $this->assertIsArray($array_with_different_values_from_cache[
'test3']);
413 $this->assertNull($array_with_different_values_from_cache[
'test4']);
415 $this->assertEquals(null,
$container->get(
'array_with_different_values', $to_int));
416 $this->assertEquals(null,
$container->get(
'array_with_different_values', $to_bool));
417 $this->assertEquals(null,
$container->get(
'array_with_different_values', $to_string));
423 $int_from_cache =
$container->get(
'int', $to_int);
424 $this->assertEquals($int, $int_from_cache);
425 $this->assertEquals(null,
$container->get(
'int', $to_string));
426 $this->assertEquals(null,
$container->get(
'int', $to_bool));
427 $this->assertEquals(null,
$container->get(
'int', $to_array));
428 $this->assertIsInt($int_from_cache);
436 $this->expectException(\TypeError::class);
439 $array_with_incompatible_type_in_it = [
442 'test3' => [
'test' => new \stdClass()]
444 $this->expectException(\TypeError::class);
445 $container->set(
'array_with_incompatible_type_in_it', $array_with_incompatible_type_in_it);
453 $array_with_incompatible_type_in_it = [
456 'test3' => [
'test' => new \stdClass()]
458 $this->expectException(\InvalidArgumentException::class);
459 $container->set(
'array_with_incompatible_type_in_it', $array_with_incompatible_type_in_it);
Class ChatMainBarProvider .
ILIAS Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testActivatedComponents()
getConfig(string $adaptor_name=Config::PHPSTATIC)
ilLanguage $language_mock
testInvalidLockTimes(float|int $time)
getInvalidLockTimes
testIncomatibleTypeNested()
getDummyRequest(string $container_key)