Skip to content

Commit 8bf922d

Browse files
committed
Add tests for ApcuCache
1 parent dd1d40d commit 8bf922d

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

β€Žtests/ApcuCacheTest.phpβ€Ž

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/*
3+
* This file is part of Aplus Framework Cache Library.
4+
*
5+
* (c) Natan Felles <natanfelles@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace Tests\Cache;
11+
12+
use Framework\Cache\ApcuCache;
13+
14+
final class ApcuCacheTest extends TestCase
15+
{
16+
public function setUp() : void
17+
{
18+
$loaded = \extension_loaded('apcu');
19+
if (!$loaded) {
20+
throw new \RuntimeException('APCu extension is not loaded');
21+
}
22+
\var_dump('apcu_cache_info():');
23+
\var_dump(\apcu_cache_info());
24+
if (!\apcu_enabled()) {
25+
// throw new \RuntimeException('APCu extension is not enabled');
26+
}
27+
28+
$this->cache = new ApcuCache(
29+
$this->configs,
30+
$this->prefix,
31+
$this->serializer,
32+
$this->getLogger()
33+
);
34+
}
35+
36+
public function testSerializer() : void
37+
{
38+
$this->cache = new ApcuCache(
39+
$this->configs,
40+
$this->prefix,
41+
$this->serializer->value,
42+
$this->getLogger()
43+
);
44+
$this->expectException(\ValueError::class);
45+
$this->expectExceptionMessage(
46+
'"foo" is not a valid backing value for enum Framework\Cache\Serializer'
47+
);
48+
$this->cache = new ApcuCache(
49+
$this->configs,
50+
$this->prefix,
51+
'foo',
52+
$this->getLogger()
53+
);
54+
}
55+
56+
public function testDefaultConfigs() : void
57+
{
58+
self::assertInstanceOf(ApcuCache::class, new ApcuCache());
59+
}
60+
}

β€Žtests/TestCase.phpβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
namespace Tests\Cache;
1111

12+
use Framework\Cache\ApcuCache;
1213
use Framework\Cache\Cache;
1314
use Framework\Cache\Debug\CacheCollector;
1415
use Framework\Cache\FilesCache;
@@ -245,6 +246,7 @@ public function getHandler() : string
245246
$this->cache->setDebugCollector($collector);
246247
// @phpstan-ignore-next-line
247248
$handler = match ($this->cache::class) {
249+
ApcuCache::class => 'apcu',
248250
FilesCache::class => 'files',
249251
MemcachedCache::class => 'memcached',
250252
RedisCache::class => 'redis',

0 commit comments

Comments
 (0)