ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\Cache\CacheTest Class Reference
+ Inheritance diagram for ILIAS\Cache\CacheTest:
+ Collaboration diagram for ILIAS\Cache\CacheTest:

Public Member Functions

 testActivatedComponents ()
 
 testMultipleContainers ()
 
 testLock ()
 
 testInvalidLockTimes (float|int $time)
 getInvalidLockTimes More...
 
 testDelete ()
 
 testDefaultAdaptor ()
 
 testFlush ()
 
 testAPCAdapter ()
 
 testMemcachedAdapter ()
 
 testObjectStorage ()
 
 testTypes ()
 
 testIncomatibleType ()
 
 testIncomatibleTypeNested ()
 

Data Fields

const TEST_CONTAINER = 'test_container'
 

Protected Member Functions

 setUp ()
 
 getConfig (string $adaptor_name=Config::PHPSTATIC)
 
 getDummyRequest (string $container_key)
 

Private Member Functions

 getInvalidLockTimes ()
 

Private Attributes

ilLanguage $language_mock
 
ILIAS Refinery Factory $refinery
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 37 of file CacheTest.php.

Member Function Documentation

◆ getConfig()

ILIAS\Cache\CacheTest::getConfig ( string  $adaptor_name = Config::PHPSTATIC)
protected
Returns
Config

Definition at line 61 of file CacheTest.php.

Referenced by ILIAS\Cache\CacheTest\setUp(), ILIAS\Cache\CacheTest\testAPCAdapter(), ILIAS\Cache\CacheTest\testDefaultAdaptor(), ILIAS\Cache\CacheTest\testDelete(), ILIAS\Cache\CacheTest\testFlush(), ILIAS\Cache\CacheTest\testIncomatibleType(), ILIAS\Cache\CacheTest\testIncomatibleTypeNested(), ILIAS\Cache\CacheTest\testInvalidLockTimes(), ILIAS\Cache\CacheTest\testLock(), ILIAS\Cache\CacheTest\testMemcachedAdapter(), ILIAS\Cache\CacheTest\testObjectStorage(), and ILIAS\Cache\CacheTest\testTypes().

61  : Config
62  {
63  return new Config(
64  $adaptor_name,
65  true,
66  [self::TEST_CONTAINER],
67  new class () extends NullNodeRepository {
68  public function getNodes(): array
69  {
70  return [new Node('127.0.0.1', 11211, 100)];
71  }
72  }
73  );
74  }
+ Here is the caller graph for this function:

◆ getDummyRequest()

◆ getInvalidLockTimes()

ILIAS\Cache\CacheTest::getInvalidLockTimes ( )
private

Definition at line 172 of file CacheTest.php.

172  : array
173  {
174  return [
175  [-10],
176  [-1],
177  [301],
178  [300.1],
179  ];
180  }

◆ setUp()

ILIAS\Cache\CacheTest::setUp ( )
protected

Definition at line 46 of file CacheTest.php.

References ILIAS\Cache\CacheTest\getConfig(), ILIAS\Cache\Config\PHPSTATIC, and ILIAS\Repository\refinery().

46  : void
47  {
48  $this->language_mock = $this->createMock(\ilLanguage::class);
49  $this->refinery = new \ILIAS\Refinery\Factory(
50  new \ILIAS\Data\Factory(),
51  $this->language_mock
52  );
53  // prevent chached values between tests
54  $static_flush = new PHPStatic($this->getConfig(Config::PHPSTATIC));
55  $static_flush->flush();
56  }
Class ChatMainBarProvider .
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
+ Here is the call graph for this function:

◆ testActivatedComponents()

ILIAS\Cache\CacheTest::testActivatedComponents ( )

Definition at line 76 of file CacheTest.php.

References ILIAS\Cache\Config\PHPSTATIC.

77  {
78  $config = new Config(
80  true,
81  ['one', 'two']
82  );
83 
84  $services = new Services($config);
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')));
88 
89  $config = new Config(
91  true,
92  ['*']
93  );
94  $services = new Services($config);
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')));
98  }

◆ testAPCAdapter()

ILIAS\Cache\CacheTest::testAPCAdapter ( )

Definition at line 264 of file CacheTest.php.

References $container, ILIAS\Cache\Config\APCU, ILIAS\Cache\CacheTest\getConfig(), ILIAS\Cache\CacheTest\getDummyRequest(), and ILIAS\Repository\refinery().

264  : void
265  {
266  $config = $this->getConfig(Config::APCU);
267  $services = new Services($config);
268  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
269  $this->assertEquals(Config::APCU, $container->getAdaptorName());
270  $this->assertEquals(self::TEST_CONTAINER, $container->getContainerName());
271 
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');
275  }
276 
277  $to_string = $this->refinery->kindlyTo()->string();
278 
279  $this->assertFalse($container->has('test'));
280  $container->set('test', 'test_value');
281  $this->assertTrue($container->has('test'));
282  $this->assertEquals('test_value', $container->get('test', $to_string));
283  $container->delete('test');
284  $this->assertFalse($container->has('test'));
285 
286  $container->set('test2', 'test_value2');
287  $container->set('test3', 'test_value3');
288  $this->assertTrue($container->has('test2'));
289  $this->assertTrue($container->has('test3'));
290 
291  $container->flush();
292 
293  $this->assertFalse($container->has('test2'));
294  $this->assertFalse($container->has('test3'));
295  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testDefaultAdaptor()

ILIAS\Cache\CacheTest::testDefaultAdaptor ( )

Definition at line 207 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), ILIAS\Cache\CacheTest\getDummyRequest(), ILIAS\Cache\Config\PHPSTATIC, and ILIAS\Repository\refinery().

207  : void
208  {
209  $request = $this->getDummyRequest(self::TEST_CONTAINER);
210 
211  $to_string = $this->refinery->kindlyTo()->string();
212 
213  $config = $this->getConfig();
214 
215  $static = new PHPStatic($config);
216  $this->assertTrue($static->isAvailable());
217 
218  $services = new Services($config);
219  $container = $services->get($request);
220  $this->assertInstanceOf(ActiveContainer::class, $container);
221  $this->assertEquals(Config::PHPSTATIC, $container->getAdaptorName());
222  $this->assertEquals(self::TEST_CONTAINER, $container->getContainerName());
223 
224  $this->assertFalse($container->has('test'));
225  $container->set('test', 'test_value');
226  $this->assertTrue($container->has('test'));
227  $this->assertEquals('test_value', $container->get('test', $to_string));
228  $container->delete('test');
229  $this->assertFalse($container->has('test'));
230 
231  $container->set('test2', 'test_value2');
232  $container->set('test3', 'test_value3');
233  $this->assertTrue($container->has('test2'));
234  $this->assertTrue($container->has('test3'));
235 
236  $container->flush();
237 
238  $this->assertFalse($container->has('test2'));
239  $this->assertFalse($container->has('test3'));
240  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testDelete()

ILIAS\Cache\CacheTest::testDelete ( )

Definition at line 193 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), and ILIAS\Cache\CacheTest\getDummyRequest().

193  : void
194  {
195  $services = new Services($this->getConfig());
196  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
197 
198  $container->set('test', 'test_value');
199  $this->assertTrue($container->has('test'));
200  $this->assertEquals('test_value', $container->get('test', $this->refinery->to()->string()));
201 
202  $container->delete('test');
203  $this->assertFalse($container->has('test'));
204  $this->assertNull($container->get('test', $this->refinery->to()->string()));
205  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testFlush()

ILIAS\Cache\CacheTest::testFlush ( )

Definition at line 242 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), and ILIAS\Cache\CacheTest\getDummyRequest().

242  : void
243  {
244  $services = new Services($this->getConfig());
245  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
246 
247  $container->set('test', 'test_value');
248  $this->assertTrue($container->has('test'));
249  $this->assertEquals('test_value', $container->get('test', $this->refinery->to()->string()));
250 
251  $container->flush();
252  $this->assertFalse($container->has('test'));
253  $this->assertNull($container->get('test', $this->refinery->to()->string()));
254 
255  $container->set('test', 'test_value');
256  $this->assertTrue($container->has('test'));
257  $this->assertEquals('test_value', $container->get('test', $this->refinery->to()->string()));
258 
259  $services->flushAdapter();
260  $this->assertFalse($container->has('test'));
261  $this->assertNull($container->get('test', $this->refinery->to()->string()));
262  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testIncomatibleType()

ILIAS\Cache\CacheTest::testIncomatibleType ( )

Definition at line 431 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), and ILIAS\Cache\CacheTest\getDummyRequest().

431  : void
432  {
433  $services = new Services($this->getConfig());
434  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
435 
436  $this->expectException(\TypeError::class);
437  $container->set('test', new \stdClass());
438 
439  $array_with_incompatible_type_in_it = [
440  'test' => 'test',
441  'test2' => 'test2',
442  'test3' => ['test' => new \stdClass()]
443  ];
444  $this->expectException(\TypeError::class);
445  $container->set('array_with_incompatible_type_in_it', $array_with_incompatible_type_in_it);
446  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testIncomatibleTypeNested()

ILIAS\Cache\CacheTest::testIncomatibleTypeNested ( )

Definition at line 448 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), and ILIAS\Cache\CacheTest\getDummyRequest().

448  : void
449  {
450  $services = new Services($this->getConfig());
451  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
452 
453  $array_with_incompatible_type_in_it = [
454  'test' => 'test',
455  'test2' => 'test2',
456  'test3' => ['test' => new \stdClass()]
457  ];
458  $this->expectException(\InvalidArgumentException::class);
459  $container->set('array_with_incompatible_type_in_it', $array_with_incompatible_type_in_it);
460  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testInvalidLockTimes()

ILIAS\Cache\CacheTest::testInvalidLockTimes ( float|int  $time)

getInvalidLockTimes

Definition at line 185 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), and ILIAS\Cache\CacheTest\getDummyRequest().

185  : void
186  {
187  $services = new Services($this->getConfig());
188  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
189  $this->expectException(\InvalidArgumentException::class);
190  $container->lock($time);
191  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testLock()

ILIAS\Cache\CacheTest::testLock ( )

Definition at line 139 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), and ILIAS\Cache\CacheTest\getDummyRequest().

139  : void
140  {
141  $services = new Services($this->getConfig());
142  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
143  $container->unlock();
144 
145  $container->set('test', 'test_value');
146  $this->assertTrue($container->has('test'));
147  $this->assertEquals('test_value', $container->get('test', $this->refinery->to()->string()));
148 
149  $container->lock(1 / 1000);
150  $this->assertTrue($container->isLocked());
151  $this->assertFalse($container->has('test'));
152  $this->assertNull($container->get('test', $this->refinery->to()->string()));
153  usleep(1000);
154  $this->assertFalse($container->isLocked());
155  $this->assertTrue($container->has('test'));
156  $this->assertEquals('test_value', $container->get('test', $this->refinery->to()->string()));
157 
158  // Second Run
159  $container->lock(1 / 1000);
160  $this->assertTrue($container->isLocked());
161  $this->assertFalse($container->has('test'));
162  $this->assertNull($container->get('test', $this->refinery->to()->string()));
163  usleep(100);
164  $this->assertTrue($container->isLocked());
165  $this->assertFalse($container->has('test'));
166  $this->assertNull($container->get('test', $this->refinery->to()->string()));
167 
168  usleep(5000); // to avoid problems with the next test
169  $this->assertFalse($container->isLocked());
170  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testMemcachedAdapter()

ILIAS\Cache\CacheTest::testMemcachedAdapter ( )

Definition at line 297 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), ILIAS\Cache\CacheTest\getDummyRequest(), and ILIAS\Cache\Config\MEMCACHED.

297  : void
298  {
299  $config = $this->getConfig(Config::MEMCACHED);
300  $services = new Services($config);
301  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
302  $this->assertEquals(Config::MEMCACHED, $container->getAdaptorName());
303  $this->assertEquals(self::TEST_CONTAINER, $container->getContainerName());
304 
305  $apcu = new Memcached($config);
306  if (!$apcu->isAvailable()) {
307  $this->markTestSkipped('Memcached is not available');
308  }
309 
310  $this->assertFalse($container->has('test'));
311  $container->set('test', 'test_value');
312  $this->assertTrue($container->has('test'));
313  $this->assertEquals('test_value', $container->get('test'));
314  $container->delete('test');
315  $this->assertFalse($container->has('test'));
316 
317  $container->set('test2', 'test_value2');
318  $container->set('test3', 'test_value3');
319  $this->assertTrue($container->has('test2'));
320  $this->assertTrue($container->has('test3'));
321 
322  $container->flush();
323 
324  $this->assertFalse($container->has('test2'));
325  $this->assertFalse($container->has('test3'));
326  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testMultipleContainers()

ILIAS\Cache\CacheTest::testMultipleContainers ( )

Definition at line 100 of file CacheTest.php.

References ILIAS\Cache\CacheTest\getDummyRequest(), and ILIAS\Cache\Config\PHPSTATIC.

100  : void
101  {
102  $config = new Config(
104  true,
105  ['one', 'two']
106  );
107 
108  $services = new Services($config);
109 
110  $one = $this->getDummyRequest('one');
111  $two = $this->getDummyRequest('two');
112  $three = $this->getDummyRequest('three');
113 
114  $this->assertEquals('one', $one->getContainerKey());
115  $this->assertEquals('two', $two->getContainerKey());
116  $this->assertEquals('three', $three->getContainerKey());
117 
118  $container_one = $services->get($one);
119  $container_two = $services->get($two);
120  $container_three = $services->get($three);
121 
122  $this->assertInstanceOf(ActiveContainer::class, $container_one);
123  $this->assertInstanceOf(ActiveContainer::class, $container_two);
124  $this->assertInstanceOf(VoidContainer::class, $container_three);
125 
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()));
129 
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()));
133 
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()));
137  }
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testObjectStorage()

ILIAS\Cache\CacheTest::testObjectStorage ( )

Definition at line 328 of file CacheTest.php.

References $container, $data, ILIAS\Cache\CacheTest\getConfig(), ILIAS\Cache\CacheTest\getDummyRequest(), and ILIAS\Repository\refinery().

328  : void
329  {
330  $services = new Services($this->getConfig());
331  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
332 
333  $first_object = new \stdClass();
334  $first_object->test = 'test';
335  $container->set('first_object', serialize($first_object));
336 
337  $this->assertTrue($container->has('first_object'));
338 
339  $to_string = $this->refinery->kindlyTo()->string();
340 
341  $data = $container->get('first_object', $to_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);
345  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

◆ testTypes()

ILIAS\Cache\CacheTest::testTypes ( )

Definition at line 347 of file CacheTest.php.

References $container, ILIAS\Cache\CacheTest\getConfig(), ILIAS\Cache\CacheTest\getDummyRequest(), and ILIAS\Repository\refinery().

347  : void
348  {
349  $services = new Services($this->getConfig());
350  $container = $services->get($this->getDummyRequest(self::TEST_CONTAINER));
351 
352  // TRANSFORMATION
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();
357 
358  // STRING
359  $string = 'test';
360  $container->set('string', $string);
361  $this->assertTrue($container->has('string'));
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);
368 
369  // ARRAY
370  $array = ['test', 'test2', 'test3'];
371  $container->set('array', $array);
372  $this->assertTrue($container->has('array'));
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);
379 
380  // BOOL
381  $bool = true;
382  $container->set('bool', $bool);
383  $this->assertTrue($container->has('bool'));
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);
390 
391  // ARRAY Different values
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'));
395 
396  $trafo = $this->refinery->to()->dictOf(
397  $this->refinery->custom()->transformation(
398  function ($value) {
399  return $value;
400  },
401  function ($value) {
402  return $value;
403  }
404  )
405  );
406 
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']);
414 
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));
418 
419  // INT
420  $int = 123;
421  $container->set('int', $int);
422  $this->assertTrue($container->has('int'));
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);
429  }
$container
Definition: wac.php:14
getConfig(string $adaptor_name=Config::PHPSTATIC)
Definition: CacheTest.php:61
getDummyRequest(string $container_key)
Definition: CacheTest.php:462
+ Here is the call graph for this function:

Field Documentation

◆ $language_mock

ilLanguage ILIAS\Cache\CacheTest::$language_mock
private

Definition at line 43 of file CacheTest.php.

◆ $refinery

ILIAS Refinery Factory ILIAS\Cache\CacheTest::$refinery
private

Definition at line 44 of file CacheTest.php.

◆ TEST_CONTAINER

const ILIAS\Cache\CacheTest::TEST_CONTAINER = 'test_container'

Definition at line 39 of file CacheTest.php.


The documentation for this class was generated from the following file: