|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
|
4
|
|
|
use Silviooosilva\CacheerPhp\Cacheer; |
|
5
|
|
|
use Silviooosilva\CacheerPhp\Config\Option\Builder\OptionBuilder; |
|
6
|
|
|
use Predis\Client as PredisClient; |
|
7
|
|
|
use Predis\Autoloader as PredisAutoloader; |
|
8
|
|
|
|
|
9
|
|
|
class RedisOptionBuilderStoreTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
private ?PredisClient $client = null; |
|
12
|
|
|
|
|
13
|
|
|
protected function setUp(): void |
|
14
|
|
|
{ |
|
15
|
|
|
// Try to connect to Redis; skip if not available |
|
16
|
|
|
try { |
|
17
|
|
|
PredisAutoloader::register(); |
|
18
|
|
|
$this->client = new PredisClient([ |
|
19
|
|
|
'scheme' => 'tcp', |
|
20
|
|
|
'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'] ?? '127.0.0.1', |
|
21
|
|
|
'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'] ?? 6379, |
|
22
|
|
|
]); |
|
23
|
|
|
$this->client->connect(); |
|
24
|
|
|
// simple call to verify |
|
25
|
|
|
$this->client->ping(); |
|
26
|
|
|
} catch (\Throwable $e) { |
|
27
|
|
|
$this->markTestSkipped('Redis not available: ' . $e->getMessage()); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function tearDown(): void |
|
32
|
|
|
{ |
|
33
|
|
|
if ($this->client) { |
|
34
|
|
|
$this->client->disconnect(); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function test_redis_store_uses_namespace_from_option_builder() |
|
39
|
|
|
{ |
|
40
|
|
|
$options = OptionBuilder::forRedis() |
|
41
|
|
|
->setNamespace('app:') |
|
42
|
|
|
->build(); |
|
43
|
|
|
|
|
44
|
|
|
$cache = new Cacheer($options); |
|
45
|
|
|
$cache->setDriver()->useRedisDriver(); |
|
46
|
|
|
|
|
47
|
|
|
$key = 'rb_key'; |
|
48
|
|
|
$data = ['v' => 1]; |
|
49
|
|
|
|
|
50
|
|
|
$cache->putCache($key, $data); |
|
51
|
|
|
$this->assertTrue($cache->isSuccess()); |
|
52
|
|
|
|
|
53
|
|
|
// Should be stored with prefix 'app:' |
|
54
|
|
|
$this->assertTrue((bool)$this->client->exists('app:' . $key)); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$read = $cache->getCache($key); |
|
57
|
|
|
$this->assertEquals($data, $read); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.