Skip to content

Commit 6594e49

Browse files
authored
tests: add sanity checks to some Redis tests (codeigniter4#9894)
1 parent 04e12d1 commit 6594e49

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

tests/system/Cache/Handlers/AbstractHandlerTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public function testGetMetaData(): void
3838
$this->handler->save(self::$key1, 'value');
3939

4040
$actual = $this->handler->getMetaData(self::$key1);
41+
$this->assertIsArray($actual);
4142

4243
// This test is time-dependent, and depending on the timing,
4344
// seconds in `$time` (e.g. 12:00:00.9999) and seconds of
4445
// `$this->memcachedHandler->save()` (e.g. 12:00:01.0000)
4546
// may be off by one second. In that case, the following calculation
4647
// will result in maximum of (60 + 1).
4748
$this->assertLessThanOrEqual(60 + 1, $actual['expire'] - $time);
48-
4949
$this->assertLessThanOrEqual(1, $actual['mtime'] - $time);
5050
$this->assertSame('value', $actual['data']);
5151
}

tests/system/Cache/Handlers/PredisHandlerTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@ public function testSave(): void
107107
public function testSavePermanent(): void
108108
{
109109
$this->assertTrue($this->handler->save(self::$key1, 'value', 0));
110-
$metaData = $this->handler->getMetaData(self::$key1);
111110

112-
$this->assertNull($metaData['expire']);
113-
$this->assertLessThanOrEqual(1, $metaData['mtime'] - Time::now()->getTimestamp());
114-
$this->assertSame('value', $metaData['data']);
111+
$metadata = $this->handler->getMetaData(self::$key1);
112+
$this->assertIsArray($metadata);
113+
$this->assertNull($metadata['expire']);
114+
$this->assertLessThanOrEqual(1, $metadata['mtime'] - Time::now()->getTimestamp());
115+
$this->assertSame('value', $metadata['data']);
115116

116117
$this->assertTrue($this->handler->delete(self::$key1));
117118
}
@@ -131,8 +132,11 @@ public function testDeleteMatchingPrefix(): void
131132
$this->handler->save('key_' . $i, 'value' . $i);
132133
}
133134

135+
$cacheInfo = $this->handler->getCacheInfo();
136+
$this->assertIsArray($cacheInfo);
137+
134138
// check that there are 101 items is cache store
135-
$this->assertSame('101', $this->handler->getCacheInfo()['Keyspace']['db0']['keys']);
139+
$this->assertSame('101', $cacheInfo['Keyspace']['db0']['keys']);
136140

137141
// Checking that given the prefix "key_1", deleteMatching deletes 13 keys:
138142
// (key_1, key_10, key_11, key_12, key_13, key_14, key_15, key_16, key_17, key_18, key_19, key_100, key_101)
@@ -149,8 +153,11 @@ public function testDeleteMatchingSuffix(): void
149153
$this->handler->save('key_' . $i, 'value' . $i);
150154
}
151155

156+
$cacheInfo = $this->handler->getCacheInfo();
157+
$this->assertIsArray($cacheInfo);
158+
152159
// check that there are 101 items is cache store
153-
$this->assertSame('101', $this->handler->getCacheInfo()['Keyspace']['db0']['keys']);
160+
$this->assertSame('101', $cacheInfo['Keyspace']['db0']['keys']);
154161

155162
// Checking that given the suffix "1", deleteMatching deletes 11 keys:
156163
// (key_1, key_11, key_21, key_31, key_41, key_51, key_61, key_71, key_81, key_91, key_101)

0 commit comments

Comments
 (0)