3 namespace Friendica\Test\Util;
5 trait DbaCacheMockTrait
12 public function __construct()
16 protected function mockDelete($key, $return = true, $times = null)
18 $this->mockDBADelete('cache', ['k' => $key], $return, $times);
21 protected function mockGet($key, $return = null, $time = null, $times = null)
27 $value = @serialize($return);
29 $this->mockSelectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, $time], ['v' => $value], $times);
30 $this->mockIsResult(['v' => $value], isset($return), $times);
33 protected function mockSet($key, $value, $ttl = Cache::FIVE_MINUTES, $time = null, $return = true, $times = null)
40 $this->mockUtc('now + ' . $ttl . 'seconds', $time + $ttl, $times);
42 'v' => serialize($value),
43 'expires' => $time + $ttl,
48 'v' => serialize($value),
54 $this->mockDBAUpdate('cache', $fields, ['k' => $key], true, $return, $times);
57 protected function mockClear($outdated = true, $return = true, $times = null)
60 $this->mockDBADelete('cache', ['`expires` < NOW()'], $return, $times);
62 $this->mockDBADelete('cache', ['`k` IS NOT NULL '], $return, $times);
66 protected function mockGetAllKeys($prefix = null, $return = [], $time = null, $times = null)
73 $where = ['`expires` >= ?', $time];
75 $where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', $time, $prefix];
78 $this->mockSelect('cache', ['k'], $where, $return, $times);
79 $this->mockFetchLoop($return, $times);
80 $this->mockDbaClose(true, $times);