Passed
Push — main ( bce8dd...f4f8ca )
by Sílvio
56s
created

RedisOptionBuilderStoreTest::tearDown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
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));
0 ignored issues
show
Bug introduced by
The method exists() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
    $this->assertTrue((bool)$this->client->/** @scrutinizer ignore-call */ exists('app:' . $key));

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.

Loading history...
55
56
    $read = $cache->getCache($key);
57
    $this->assertEquals($data, $read);
58
  }
59
}
60
61