36 require_once(__DIR__ .
'/../../../../vendor/composer/vendor/autoload.php');
50 protected function setUp(): void
52 $this->language_mock = $this->createMock(\ilLanguage::class);
59 $static_flush->flush();
70 [self::TEST_CONTAINER],
72 public function getNodes(): array
74 return [
new Node(
'127.0.0.1', 11211, 100)];
89 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'one')));
90 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'two')));
91 $this->assertInstanceOf(VoidContainer::class, $services->get($this->getDummyRequest(
'three')));
99 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'one')));
100 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'two')));
101 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'three')));
118 $this->assertEquals(
'one', $one->getContainerKey());
119 $this->assertEquals(
'two', $two->getContainerKey());
120 $this->assertEquals(
'three', $three->getContainerKey());
122 $container_one = $services->get($one);
123 $container_two = $services->get($two);
124 $container_three = $services->get($three);
126 $this->assertInstanceOf(ActiveContainer::class, $container_one);
127 $this->assertInstanceOf(ActiveContainer::class, $container_two);
128 $this->assertInstanceOf(VoidContainer::class, $container_three);
130 $container_one->set(
'test',
'test_value');
131 $this->assertTrue($container_one->has(
'test'));
132 $this->assertEquals(
'test_value', $container_one->get(
'test', $this->refinery->to()->string()));
134 $container_two->set(
'test',
'test_value');
135 $this->assertTrue($container_two->has(
'test'));
136 $this->assertEquals(
'test_value', $container_two->get(
'test', $this->refinery->to()->string()));
138 $container_three->set(
'test',
'test_value');
139 $this->assertFalse($container_three->has(
'test'));
140 $this->assertNull($container_three->get(
'test', $this->refinery->to()->string()));
150 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
155 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
159 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
165 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
169 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
185 #[DataProvider('getInvalidLockTimes')] 190 $this->expectException(\InvalidArgumentException::class);
201 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
205 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
212 $to_string = $this->
refinery->kindlyTo()->string();
217 $this->assertTrue($static->isAvailable());
221 $this->assertInstanceOf(ActiveContainer::class,
$container);
223 $this->assertEquals(self::TEST_CONTAINER,
$container->getContainerName());
228 $this->assertEquals(
'test_value',
$container->get(
'test', $to_string));
250 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
254 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
258 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
260 $services->flushAdapter();
262 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
271 $this->assertEquals(self::TEST_CONTAINER,
$container->getContainerName());
273 $apcu =
new APCu($config);
274 if (!$apcu->isAvailable() || !(bool) ini_get(
'apc.enable_cli')) {
275 $this->markTestSkipped(
'APCu is not available or not enabled for CLI');
278 $to_string = $this->
refinery->kindlyTo()->string();
283 $this->assertEquals(
'test_value',
$container->get(
'test', $to_string));
308 $this->assertEquals(self::TEST_CONTAINER,
$container->getContainerName());
311 if (!$apcu->isAvailable()) {
312 $this->markTestSkipped(
'Memcached is not available');
318 $this->assertEquals(
'test_value',
$container->get(
'test'));
338 $first_object = new \stdClass();
339 $first_object->test =
'test';
340 $container->set(
'first_object', serialize($first_object));
342 $this->assertTrue(
$container->has(
'first_object'));
344 $to_string = $this->
refinery->kindlyTo()->string();
347 $first_object_from_cache = unserialize(
$data, [
'allowed_classes' => [\stdClass::class]]);
348 $this->assertInstanceOf(\stdClass::class, $first_object_from_cache);
349 $this->assertEquals($first_object, $first_object_from_cache);
358 $to_string = $this->
refinery->to()->string();
359 $to_int = $this->
refinery->to()->int();
360 $to_array = $this->
refinery->to()->listOf($to_string);
361 $to_bool = $this->
refinery->to()->bool();
367 $string_from_cache =
$container->get(
'string', $to_string);
368 $this->assertEquals($string, $string_from_cache);
372 $this->assertIsString($string_from_cache);
375 $array = [
'test',
'test2',
'test3'];
378 $array_from_cache =
$container->get(
'array', $to_array);
379 $this->assertEquals($array, $array_from_cache);
383 $this->assertIsArray($array_from_cache);
389 $bool_from_cache =
$container->get(
'bool', $to_bool);
390 $this->assertEquals($bool, $bool_from_cache);
394 $this->assertIsBool($bool_from_cache);
397 $array_with_different_values = [
'test' =>
true,
'test2' => 123,
'test3' => [
'test' =>
'test'],
'test4' =>
null];
398 $container->set(
'array_with_different_values', $array_with_different_values);
399 $this->assertTrue(
$container->has(
'array_with_different_values'));
401 $trafo = $this->
refinery->to()->dictOf(
402 $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);
428 $this->assertIsInt($int_from_cache);
438 $this->expectException(\TypeError::class);
448 $array_with_incompatible_type_in_it = [
451 'test3' => [
'test' => new \stdClass()]
453 $this->expectException(\InvalidArgumentException::class);
455 'array_with_incompatible_type_in_it',
456 $array_with_incompatible_type_in_it
465 $array_with_incompatible_type_in_it = [
468 'test3' => [
'test' => new \stdClass()]
470 $this->expectException(\InvalidArgumentException::class);
471 $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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
testActivatedComponents()
getConfig(string $adaptor_name=Config::PHPSTATIC)
ilLanguage $language_mock
testInvalidLockTimes(float|int $time)
testIncomatibleTypeNested()
getDummyRequest(string $container_key)
static getInvalidLockTimes()