Repository navigation
Expand file tree
/
Copy pathFileLocatorCachedTest.php
More file actions
101 lines (81 loc) · 2.83 KB
/
Copy pathFileLocatorCachedTest.php
File metadata and controls
101 lines (81 loc) · 2.83 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
<?php
declare(strict_types=1);
/**
* 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\Autoloader;
use CodeIgniter\Cache\FactoriesCache\FileVarExportHandler;
use Config\Autoload;
use Config\Modules;
use PHPUnit\Framework\Attributes\Group;
/**
* @internal
*/
#[Group('Others')]
final class FileLocatorCachedTest extends FileLocatorTest
{
private FileVarExportHandler $handler;
public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
// Delete cache file.
$autoloader = new Autoloader();
$handler = new FileVarExportHandler();
$fileLocator = new FileLocator($autoloader);
$locator = new FileLocatorCached($fileLocator, $handler);
$locator->deleteCache();
}
protected function setUp(): void
{
parent::setUp();
$autoloader = new Autoloader();
$autoloader->initialize(new Autoload(), new Modules());
$autoloader->addNamespace([
'Unknown' => '/i/do/not/exist',
'Tests/Support' => TESTPATH . '_support/',
'App' => APPPATH,
'CodeIgniter' => [
TESTPATH,
SYSTEMPATH,
],
'Errors' => APPPATH . 'Views/errors',
'System' => SUPPORTPATH . 'Autoloader/system',
'CodeIgniter\\Devkit' => [
TESTPATH . '_support/',
],
'Acme\SampleProject' => TESTPATH . '_support',
'Acme\Sample' => TESTPATH . '_support/does/not/exists',
]);
$this->handler = new FileVarExportHandler();
$fileLocator = new FileLocator($autoloader);
$this->locator = new FileLocatorCached($fileLocator, $this->handler);
}
protected function tearDown(): void
{
$this->locator->__destruct();
parent::tearDown();
}
public function testDeleteCache(): void
{
$this->locator->search('Config/App');
$this->locator->__destruct();
$this->assertIsArray($this->handler->get('FileLocatorCache'));
$this->locator->deleteCache();
$this->assertFalse($this->handler->get('FileLocatorCache'));
}
public function testDeleteCacheDiscardsDataHeldInMemory(): void
{
$this->locator->getClassname(SYSTEMPATH . 'CodeIgniter.php');
$this->locator->deleteCache();
$this->locator->search('Config/App');
$this->locator->__destruct();
$cached = $this->handler->get('FileLocatorCache');
$this->assertArrayHasKey('search', $cached);
$this->assertArrayNotHasKey('getClassname', $cached);
}
}