32 require_once(__DIR__ .
'/../../../../vendor/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));
307 $this->assertEquals(self::TEST_CONTAINER,
$container->getContainerName());
310 if (!$apcu->isAvailable()) {
311 $this->markTestSkipped(
'Memcached is not available');
317 $this->assertEquals(
'test_value',
$container->get(
'test'));
337 $first_object = new \stdClass();
338 $first_object->test =
'test';
339 $container->set(
'first_object', serialize($first_object));
341 $this->assertTrue(
$container->has(
'first_object'));
343 $to_string = $this->
refinery->kindlyTo()->string();
346 $first_object_from_cache = unserialize(
$data, [
'allowed_classes' => [\stdClass::class]]);
347 $this->assertInstanceOf(\stdClass::class, $first_object_from_cache);
348 $this->assertEquals($first_object, $first_object_from_cache);
357 $to_string = $this->
refinery->to()->string();
358 $to_int = $this->
refinery->to()->int();
359 $to_array = $this->
refinery->to()->listOf($to_string);
360 $to_bool = $this->
refinery->to()->bool();
366 $string_from_cache =
$container->get(
'string', $to_string);
367 $this->assertEquals($string, $string_from_cache);
368 $this->assertEquals(null,
$container->get(
'string', $to_int));
369 $this->assertEquals(null,
$container->get(
'string', $to_bool));
370 $this->assertEquals(null,
$container->get(
'string', $to_array));
371 $this->assertIsString($string_from_cache);
374 $array = [
'test',
'test2',
'test3'];
377 $array_from_cache =
$container->get(
'array', $to_array);
378 $this->assertEquals($array, $array_from_cache);
379 $this->assertEquals(null,
$container->get(
'array', $to_int));
380 $this->assertEquals(null,
$container->get(
'array', $to_bool));
381 $this->assertEquals(null,
$container->get(
'array', $to_string));
382 $this->assertIsArray($array_from_cache);
388 $bool_from_cache =
$container->get(
'bool', $to_bool);
389 $this->assertEquals($bool, $bool_from_cache);
390 $this->assertEquals(null,
$container->get(
'bool', $to_int));
391 $this->assertEquals(null,
$container->get(
'bool', $to_array));
392 $this->assertEquals(null,
$container->get(
'bool', $to_string));
393 $this->assertIsBool($bool_from_cache);
396 $array_with_different_values = [
'test' =>
true,
'test2' => 123,
'test3' => [
'test' =>
'test'],
'test4' => null];
397 $container->set(
'array_with_different_values', $array_with_different_values);
398 $this->assertTrue(
$container->has(
'array_with_different_values'));
400 $trafo = $this->
refinery->to()->dictOf(
401 $this->
refinery->custom()->transformation(
411 $array_with_different_values_from_cache =
$container->get(
'array_with_different_values', $trafo);
412 $this->assertEquals($array_with_different_values, $array_with_different_values_from_cache);
413 $this->assertIsArray($array_with_different_values_from_cache);
414 $this->assertIsBool($array_with_different_values_from_cache[
'test']);
415 $this->assertIsInt($array_with_different_values_from_cache[
'test2']);
416 $this->assertIsArray($array_with_different_values_from_cache[
'test3']);
417 $this->assertNull($array_with_different_values_from_cache[
'test4']);
419 $this->assertEquals(null,
$container->get(
'array_with_different_values', $to_int));
420 $this->assertEquals(null,
$container->get(
'array_with_different_values', $to_bool));
421 $this->assertEquals(null,
$container->get(
'array_with_different_values', $to_string));
427 $int_from_cache =
$container->get(
'int', $to_int);
428 $this->assertEquals($int, $int_from_cache);
429 $this->assertEquals(null,
$container->get(
'int', $to_string));
430 $this->assertEquals(null,
$container->get(
'int', $to_bool));
431 $this->assertEquals(null,
$container->get(
'int', $to_array));
432 $this->assertIsInt($int_from_cache);
442 $this->expectException(\TypeError::class);
452 $array_with_incompatible_type_in_it = [
455 'test3' => [
'test' => new \stdClass()]
457 $this->expectException(\InvalidArgumentException::class);
459 'array_with_incompatible_type_in_it',
460 $array_with_incompatible_type_in_it
469 $array_with_incompatible_type_in_it = [
472 'test3' => [
'test' => new \stdClass()]
474 $this->expectException(\InvalidArgumentException::class);
475 $container->set(
'array_with_incompatible_type_in_it', $array_with_incompatible_type_in_it);
deactivatedTestMemcachedAdapter()
this test cannot be executed in the CI on github sincewe do not have a memcached server there...
testIncomatibleNestedType()
Interface Observer Contains several chained tasks and infos about them.
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)
static getInvalidLockTimes()