-
-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathVoidCacheTest.php
More file actions
93 lines (74 loc) · 2.28 KB
/
VoidCacheTest.php
File metadata and controls
93 lines (74 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types=1);
/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <david.cole1340@gmail.com>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/
use Discord\Helpers\VoidCache;
use PHPUnit\Framework\TestCase;
final class VoidCacheTest extends TestCase
{
private VoidCache $cache;
protected function setUp(): void
{
$this->cache = new VoidCache();
}
public function testGetReturnsNullByDefault(): void
{
$this->assertNull($this->cache->get('key'));
}
public function testGetReturnsProvidedDefault(): void
{
$this->assertSame('default', $this->cache->get('key', 'default'));
$this->assertSame(42, $this->cache->get('key', 42));
}
public function testSetReturnsTrue(): void
{
$this->assertTrue($this->cache->set('key', 'value'));
}
public function testDeleteReturnsTrue(): void
{
$this->assertTrue($this->cache->delete('key'));
}
public function testClearReturnsTrue(): void
{
$this->assertTrue($this->cache->clear());
}
public function testHasReturnsFalse(): void
{
$this->assertFalse($this->cache->has('key'));
}
public function testGetMultipleReturnsDefaultForAllKeys(): void
{
$keys = ['a', 'b', 'c'];
$result = $this->cache->getMultiple($keys, 'default');
$this->assertSame([
'a' => 'default',
'b' => 'default',
'c' => 'default',
], $result);
}
public function testGetMultipleReturnsNullDefaultWhenNotSpecified(): void
{
$result = $this->cache->getMultiple(['x', 'y']);
$this->assertSame(['x' => null, 'y' => null], $result);
}
public function testSetMultipleReturnsTrue(): void
{
$this->assertTrue($this->cache->setMultiple(['a' => 1, 'b' => 2]));
}
public function testDeleteMultipleReturnsTrue(): void
{
$this->assertTrue($this->cache->deleteMultiple(['a', 'b']));
}
public function testSetDoesNotPersistValue(): void
{
$this->cache->set('key', 'value');
$this->assertNull($this->cache->get('key'));
$this->assertFalse($this->cache->has('key'));
}
}