22use PHPUnit\Framework\Attributes\DataProvider;
28use PHPUnit\Framework\TestCase;
34require_once(__DIR__ .
'/../../../../vendor/composer/vendor/autoload.php');
44 protected function setUp(): void
46 $language_mock = $this->createMock(\ilLanguage::class);
53 $static_flush->flush();
64 [self::TEST_CONTAINER],
66 public function getNodes(): array
68 return [
new Node(
'127.0.0.1', 11211, 100)];
83 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'one')));
84 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'two')));
85 $this->assertInstanceOf(VoidContainer::class, $services->get($this->getDummyRequest(
'three')));
93 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'one')));
94 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'two')));
95 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'three')));
112 $this->assertSame(
'one', $one->getContainerKey());
113 $this->assertSame(
'two', $two->getContainerKey());
114 $this->assertSame(
'three', $three->getContainerKey());
116 $container_one = $services->get($one);
117 $container_two = $services->get($two);
118 $container_three = $services->get($three);
120 $this->assertInstanceOf(ActiveContainer::class, $container_one);
121 $this->assertInstanceOf(ActiveContainer::class, $container_two);
122 $this->assertInstanceOf(VoidContainer::class, $container_three);
124 $container_one->set(
'test',
'test_value');
125 $this->assertTrue($container_one->has(
'test'));
126 $this->assertSame(
'test_value', $container_one->get(
'test', $this->refinery->to()->string()));
128 $container_two->set(
'test',
'test_value');
129 $this->assertTrue($container_two->has(
'test'));
130 $this->assertSame(
'test_value', $container_two->get(
'test', $this->refinery->to()->string()));
132 $container_three->set(
'test',
'test_value');
133 $this->assertFalse($container_three->has(
'test'));
134 $this->assertNull($container_three->get(
'test', $this->refinery->to()->string()));
145 $this->assertSame(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
150 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
154 $this->assertSame(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
160 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
164 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
178 #[DataProvider('getInvalidLockTimes')]
183 $this->expectException(\InvalidArgumentException::class);
194 $this->assertSame(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
198 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
205 $to_string = $this->
refinery->kindlyTo()->string();
210 $this->assertTrue($static->isAvailable());
214 $this->assertInstanceOf(ActiveContainer::class,
$container);
216 $this->assertSame(self::TEST_CONTAINER,
$container->getContainerName());
221 $this->assertSame(
'test_value',
$container->get(
'test', $to_string));
243 $this->assertSame(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
247 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
251 $this->assertSame(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
253 $services->flushAdapter();
255 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
264 $this->assertSame(self::TEST_CONTAINER,
$container->getContainerName());
266 $apcu =
new APCu($config);
267 if (!$apcu->isAvailable() || !(
bool) ini_get(
'apc.enable_cli')) {
268 $this->markTestSkipped(
'APCu is not available or not enabled for CLI');
271 $to_string = $this->
refinery->kindlyTo()->string();
276 $this->assertSame(
'test_value',
$container->get(
'test', $to_string));
301 $this->assertSame(self::TEST_CONTAINER,
$container->getContainerName());
304 if (!$apcu->isAvailable()) {
305 $this->markTestSkipped(
'Memcached is not available');
311 $this->assertSame(
'test_value',
$container->get(
'test'));
331 $first_object = new \stdClass();
332 $first_object->test =
'test';
333 $container->set(
'first_object', serialize($first_object));
335 $this->assertTrue(
$container->has(
'first_object'));
337 $to_string = $this->
refinery->kindlyTo()->string();
340 $first_object_from_cache = unserialize(
$data, [
'allowed_classes' => [\stdClass::class]]);
341 $this->assertInstanceOf(\stdClass::class, $first_object_from_cache);
342 $this->assertEquals($first_object, $first_object_from_cache);
351 $to_string = $this->
refinery->to()->string();
352 $to_int = $this->
refinery->to()->int();
353 $to_array = $this->
refinery->to()->listOf($to_string);
354 $to_bool = $this->
refinery->to()->bool();
360 $string_from_cache =
$container->get(
'string', $to_string);
361 $this->assertSame($string, $string_from_cache);
362 $this->assertEquals(
null,
$container->get(
'string', $to_int));
363 $this->assertEquals(
null,
$container->get(
'string', $to_bool));
364 $this->assertEquals(
null,
$container->get(
'string', $to_array));
365 $this->assertIsString($string_from_cache);
368 $array = [
'test',
'test2',
'test3'];
371 $array_from_cache =
$container->get(
'array', $to_array);
372 $this->assertSame($array, $array_from_cache);
373 $this->assertEquals(
null,
$container->get(
'array', $to_int));
374 $this->assertEquals(
null,
$container->get(
'array', $to_bool));
375 $this->assertEquals(
null,
$container->get(
'array', $to_string));
376 $this->assertIsArray($array_from_cache);
382 $bool_from_cache =
$container->get(
'bool', $to_bool);
383 $this->assertEquals($bool, $bool_from_cache);
384 $this->assertEquals(
null,
$container->get(
'bool', $to_int));
385 $this->assertEquals(
null,
$container->get(
'bool', $to_array));
386 $this->assertEquals(
null,
$container->get(
'bool', $to_string));
387 $this->assertIsBool($bool_from_cache);
390 $array_with_different_values = [
'test' =>
true,
'test2' => 123,
'test3' => [
'test' =>
'test'],
'test4' =>
null];
391 $container->set(
'array_with_different_values', $array_with_different_values);
392 $this->assertTrue(
$container->has(
'array_with_different_values'));
394 $trafo = $this->
refinery->to()->dictOf(
395 $this->
refinery->custom()->transformation(
400 $array_with_different_values_from_cache =
$container->get(
'array_with_different_values', $trafo);
401 $this->assertEquals($array_with_different_values, $array_with_different_values_from_cache);
402 $this->assertIsArray($array_with_different_values_from_cache);
403 $this->assertIsBool($array_with_different_values_from_cache[
'test']);
404 $this->assertIsInt($array_with_different_values_from_cache[
'test2']);
405 $this->assertIsArray($array_with_different_values_from_cache[
'test3']);
406 $this->assertNull($array_with_different_values_from_cache[
'test4']);
408 $this->assertEquals(
null,
$container->get(
'array_with_different_values', $to_int));
409 $this->assertEquals(
null,
$container->get(
'array_with_different_values', $to_bool));
410 $this->assertEquals(
null,
$container->get(
'array_with_different_values', $to_string));
416 $int_from_cache =
$container->get(
'int', $to_int);
417 $this->assertSame($int, $int_from_cache);
418 $this->assertEquals(
null,
$container->get(
'int', $to_string));
419 $this->assertEquals(
null,
$container->get(
'int', $to_bool));
420 $this->assertEquals(
null,
$container->get(
'int', $to_array));
421 $this->assertIsInt($int_from_cache);
431 $this->expectException(\TypeError::class);
441 $array_with_incompatible_type_in_it = [
444 'test3' => [
'test' => new \stdClass()]
446 $this->expectException(\InvalidArgumentException::class);
448 'array_with_incompatible_type_in_it',
449 $array_with_incompatible_type_in_it
458 $array_with_incompatible_type_in_it = [
461 'test3' => [
'test' => new \stdClass()]
463 $this->expectException(\InvalidArgumentException::class);
464 $container->set(
'array_with_incompatible_type_in_it', $array_with_incompatible_type_in_it);
static getInvalidLockTimes()
getConfig(string $adaptor_name=Config::PHPSTATIC)
testActivatedComponents()
testIncomatibleNestedType()
getDummyRequest(string $container_key)
testIncomatibleTypeNested()
testInvalidLockTimes(float|int $time)
deactivatedTestMemcachedAdapter()
@description this test cannot be executed in the CI on github sincewe do not have a memcached server ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.