forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheFactoryTest.php
More file actions
107 lines (84 loc) · 2.91 KB
/
Copy pathCacheFactoryTest.php
File metadata and controls
107 lines (84 loc) · 2.91 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Cache;
use CodeIgniter\Cache\Exceptions\CacheException;
use CodeIgniter\Cache\Handlers\DummyHandler;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Cache;
/**
* @internal
*
* @group Others
*/
final class CacheFactoryTest extends CIUnitTestCase
{
private static string $directory = 'CacheFactory';
private CacheFactory $cacheFactory;
private Cache $config;
protected function setUp(): void
{
parent::setUp();
$this->cacheFactory = new CacheFactory();
// Initialize path
$this->config = new Cache();
$this->config->storePath .= self::$directory;
}
protected function tearDown(): void
{
if (is_dir($this->config->storePath)) {
chmod($this->config->storePath, 0777);
rmdir($this->config->storePath);
}
}
public function testNew()
{
$this->assertInstanceOf(CacheFactory::class, $this->cacheFactory);
}
public function testGetHandlerExceptionCacheInvalidHandlers()
{
$this->expectException(CacheException::class);
$this->expectExceptionMessage('Cache config must have an array of $validHandlers.');
$this->config->validHandlers = [];
$this->cacheFactory->getHandler($this->config);
}
public function testGetHandlerExceptionCacheHandlerNotFound()
{
$this->expectException(CacheException::class);
$this->expectExceptionMessage('Cache config has an invalid handler or backup handler specified.');
unset($this->config->validHandlers[$this->config->handler]);
$this->cacheFactory->getHandler($this->config);
}
public function testGetDummyHandler()
{
if (! is_dir($this->config->storePath)) {
mkdir($this->config->storePath, 0555, true);
}
$this->config->handler = 'dummy';
$this->assertInstanceOf(DummyHandler::class, $this->cacheFactory->getHandler($this->config));
// Initialize path
$this->config = new Cache();
$this->config->storePath .= self::$directory;
}
public function testHandlesBadHandler()
{
if (! is_dir($this->config->storePath)) {
mkdir($this->config->storePath, 0555, true);
}
$this->config->handler = 'dummy';
if (stripos('win', php_uname()) === 0) {
$this->assertTrue(true); // can't test properly if we are on Windows
} else {
$this->assertInstanceOf(DummyHandler::class, $this->cacheFactory->getHandler($this->config, 'wincache', 'wincache'));
}
// Initialize path
$this->config = new Cache();
$this->config->storePath .= self::$directory;
}
}