3 namespace Friendica\Test\Util;
5 trait DbaCacheMockTrait
8 use DateTimeFormatMockTrait;
10 protected function mockDelete($key, $return = true, $times = null)
12 $this->mockDBADelete('cache', ['k' => $key], $return, $times);
15 protected function mockGet($key, $return = null, $time = null, $times = null)
21 $value = @serialize($return);
23 $this->mockSelectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, $time], ['v' => $value], $times);
24 $this->mockIsResult(['v' => $value], isset($return), $times);
27 protected function mockSet($key, $value, $ttl = Cache::FIVE_MINUTES, $time = null, $return = true, $times = null)
34 $this->mockUtc('now + ' . $ttl . 'seconds', $time + $ttl, $times);
36 'v' => serialize($value),
37 'expires' => $time + $ttl,
42 'v' => serialize($value),
48 $this->mockDBAUpdate('cache', $fields, ['k' => $key], true, $return, $times);
51 protected function mockClear($outdated = true, $return = true, $times = null)
54 $this->mockDBADelete('cache', ['`expires` < NOW()'], $return, $times);
56 $this->mockDBADelete('cache', ['`k` IS NOT NULL '], $return, $times);
60 protected function mockGetAllKeys($prefix = null, $return = [], $time = null, $times = null)
67 $where = ['`expires` >= ?', $time];
69 $where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', $time, $prefix];
72 $this->mockSelect('cache', ['k'], $where, $return, $times);
73 $this->mockFetchLoop($return, $times);
74 $this->mockDbaClose(true, $times);