34 require_once(__DIR__ .
'/../../../../vendor/composer/vendor/autoload.php');
48 protected function setUp(): void
50 $this->language_mock = $this->createMock(\ilLanguage::class);
57 $static_flush->flush();
68 [self::TEST_CONTAINER],
70 public function getNodes(): array
72 return [
new Node(
'127.0.0.1', 11211, 100)];
87 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'one')));
88 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'two')));
89 $this->assertInstanceOf(VoidContainer::class, $services->get($this->getDummyRequest(
'three')));
97 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'one')));
98 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'two')));
99 $this->assertInstanceOf(ActiveContainer::class, $services->get($this->getDummyRequest(
'three')));
116 $this->assertEquals(
'one', $one->getContainerKey());
117 $this->assertEquals(
'two', $two->getContainerKey());
118 $this->assertEquals(
'three', $three->getContainerKey());
120 $container_one = $services->get($one);
121 $container_two = $services->get($two);
122 $container_three = $services->get($three);
124 $this->assertInstanceOf(ActiveContainer::class, $container_one);
125 $this->assertInstanceOf(ActiveContainer::class, $container_two);
126 $this->assertInstanceOf(VoidContainer::class, $container_three);
128 $container_one->set(
'test',
'test_value');
129 $this->assertTrue($container_one->has(
'test'));
130 $this->assertEquals(
'test_value', $container_one->get(
'test', $this->refinery->to()->string()));
132 $container_two->set(
'test',
'test_value');
133 $this->assertTrue($container_two->has(
'test'));
134 $this->assertEquals(
'test_value', $container_two->get(
'test', $this->refinery->to()->string()));
136 $container_three->set(
'test',
'test_value');
137 $this->assertFalse($container_three->has(
'test'));
138 $this->assertNull($container_three->get(
'test', $this->refinery->to()->string()));
149 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
154 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
158 $this->assertEquals(
'test_value',
$container->get(
'test', $this->refinery->to()->string()));
164 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
168 $this->assertNull(
$container->get(
'test', $this->refinery->to()->string()));
184 #[DataProvider('getInvalidLockTimes')] 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);
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);
382 $this->assertIsArray($array_from_cache);
388 $bool_from_cache =
$container->get(
'bool', $to_bool);
389 $this->assertEquals($bool, $bool_from_cache);
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(
406 $array_with_different_values_from_cache =
$container->get(
'array_with_different_values', $trafo);
407 $this->assertEquals($array_with_different_values, $array_with_different_values_from_cache);
408 $this->assertIsArray($array_with_different_values_from_cache);
409 $this->assertIsBool($array_with_different_values_from_cache[
'test']);
410 $this->assertIsInt($array_with_different_values_from_cache[
'test2']);
411 $this->assertIsArray($array_with_different_values_from_cache[
'test3']);
412 $this->assertNull($array_with_different_values_from_cache[
'test4']);
414 $this->assertEquals(
null,
$container->get(
'array_with_different_values', $to_int));
415 $this->assertEquals(
null,
$container->get(
'array_with_different_values', $to_bool));
416 $this->assertEquals(
null,
$container->get(
'array_with_different_values', $to_string));
422 $int_from_cache =
$container->get(
'int', $to_int);
423 $this->assertEquals($int, $int_from_cache);
427 $this->assertIsInt($int_from_cache);
437 $this->expectException(\TypeError::class);
447 $array_with_incompatible_type_in_it = [
450 'test3' => [
'test' => new \stdClass()]
452 $this->expectException(\InvalidArgumentException::class);
454 'array_with_incompatible_type_in_it',
455 $array_with_incompatible_type_in_it
464 $array_with_incompatible_type_in_it = [
467 'test3' => [
'test' => new \stdClass()]
469 $this->expectException(\InvalidArgumentException::class);
470 $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()