Skip to content

Commit 807f806

Browse files
committed
Reorganize tests
1 parent 1b72964 commit 807f806

File tree

2 files changed

+87
-7
lines changed

2 files changed

+87
-7
lines changed

tests/RedisClusterTest.php

+35-3
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,46 @@ public function testClient() {
251251
public function testGetWithMeta() {
252252
$this->redis->del('key');
253253
$this->assertFalse($this->redis->get('key'));
254-
$this->assertEquals([false, ['length' => -1]], $this->redis->getWithMeta('key'));
255254

256-
$this->assertEquals([true, ['value', ['length' => strlen('value')]]], $this->redis->multi()->set('key', 'value')->getWithMeta('key')->exec());
255+
$result = $this->redis->getWithMeta('key');
256+
$this->assertIsArray($result, 2);
257+
$this->assertArrayKeyEquals($result, 0, false);
258+
$this->assertArrayKey($result, 1, function ($metadata) {
259+
$this->assertIsArray($metadata);
260+
$this->assertArrayKeyEquals($metadata, 'length', -1);
261+
return true;
262+
});
263+
264+
$batch = $this->redis->multi()
265+
->set('key', 'value')
266+
->getWithMeta('key')
267+
->exec();
268+
$this->assertIsArray($batch, 2);
269+
$this->assertArrayKeyEquals($batch, 0, true);
270+
$this->assertArrayKey($batch, 1, function ($result) {
271+
$this->assertIsArray($result, 2);
272+
$this->assertArrayKeyEquals($result, 0, 'value');
273+
$this->assertArrayKey($result, 1, function ($metadata) {
274+
$this->assertIsArray($metadata);
275+
$this->assertArrayKeyEquals($metadata, 'length', strlen('value'));
276+
return true;
277+
});
278+
return true;
279+
});
257280

258281
$serializer = $this->redis->getOption(Redis::OPT_SERIALIZER);
259282
$this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
260283
$this->assertTrue($this->redis->set('key', false));
261-
$this->assertEquals([false, ['length' => strlen(serialize(false))]], $this->redis->getWithMeta('key'));
284+
285+
$result = $this->redis->getWithMeta('key');
286+
$this->assertIsArray($result, 2);
287+
$this->assertArrayKeyEquals($result, 0, false);
288+
$this->assertArrayKey($result, 1, function ($metadata) {
289+
$this->assertIsArray($metadata);
290+
$this->assertArrayKeyEquals($metadata, 'length', strlen(serialize(false)));
291+
return true;
292+
});
293+
262294
$this->assertFalse($this->redis->get('key'));
263295
$this->redis->setOption(Redis::OPT_SERIALIZER, $serializer);
264296
}

tests/RedisTest.php

+52-4
Original file line numberDiff line numberDiff line change
@@ -5803,15 +5803,63 @@ public function testPackHelpers() {
58035803
public function testGetWithMeta() {
58045804
$this->redis->del('key');
58055805
$this->assertFalse($this->redis->get('key'));
5806-
$this->assertEquals([false, ['length' => -1]], $this->redis->getWithMeta('key'));
58075806

5808-
$this->assertEquals([false, [false, ['length' => -1]]], $this->redis->pipeline()->get('key')->getWithMeta('key')->exec());
5809-
$this->assertEquals([true, ['value', ['length' => strlen('value')]]], $this->redis->multi()->set('key', 'value')->getWithMeta('key')->exec());
5807+
$result = $this->redis->getWithMeta('key');
5808+
$this->assertIsArray($result, 2);
5809+
$this->assertArrayKeyEquals($result, 0, false);
5810+
$this->assertArrayKey($result, 1, function ($metadata) {
5811+
$this->assertIsArray($metadata);
5812+
$this->assertArrayKeyEquals($metadata, 'length', -1);
5813+
return true;
5814+
});
5815+
5816+
$batch = $this->redis->pipeline()
5817+
->get('key')
5818+
->getWithMeta('key')
5819+
->exec();
5820+
$this->assertIsArray($batch, 2);
5821+
$this->assertArrayKeyEquals($batch, 0, false);
5822+
$this->assertArrayKey($batch, 1, function ($result) {
5823+
$this->assertIsArray($result, 2);
5824+
$this->assertArrayKeyEquals($result, 0, false);
5825+
$this->assertArrayKey($result, 1, function ($metadata) {
5826+
$this->assertIsArray($metadata);
5827+
$this->assertArrayKeyEquals($metadata, 'length', -1);
5828+
return true;
5829+
});
5830+
return true;
5831+
});
5832+
5833+
$batch = $this->redis->multi()
5834+
->set('key', 'value')
5835+
->getWithMeta('key')
5836+
->exec();
5837+
$this->assertIsArray($batch, 2);
5838+
$this->assertArrayKeyEquals($batch, 0, true);
5839+
$this->assertArrayKey($batch, 1, function ($result) {
5840+
$this->assertIsArray($result, 2);
5841+
$this->assertArrayKeyEquals($result, 0, 'value');
5842+
$this->assertArrayKey($result, 1, function ($metadata) {
5843+
$this->assertIsArray($metadata);
5844+
$this->assertArrayKeyEquals($metadata, 'length', strlen('value'));
5845+
return true;
5846+
});
5847+
return true;
5848+
});
58105849

58115850
$serializer = $this->redis->getOption(Redis::OPT_SERIALIZER);
58125851
$this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
58135852
$this->assertTrue($this->redis->set('key', false));
5814-
$this->assertEquals([false, ['length' => strlen(serialize(false))]], $this->redis->getWithMeta('key'));
5853+
5854+
$result = $this->redis->getWithMeta('key');
5855+
$this->assertIsArray($result, 2);
5856+
$this->assertArrayKeyEquals($result, 0, false);
5857+
$this->assertArrayKey($result, 1, function ($metadata) {
5858+
$this->assertIsArray($metadata);
5859+
$this->assertArrayKeyEquals($metadata, 'length', strlen(serialize(false)));
5860+
return true;
5861+
});
5862+
58155863
$this->assertFalse($this->redis->get('key'));
58165864
$this->redis->setOption(Redis::OPT_SERIALIZER, $serializer);
58175865
}

0 commit comments

Comments
 (0)