1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Cache\Tests\Legacy; |
4
|
|
|
|
5
|
|
|
use Nip\Cache\Manager; |
6
|
|
|
use Nip\Cache\Tests\AbstractTest; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ManagerTest |
10
|
|
|
* @package Nip\Cache\Tests |
11
|
|
|
*/ |
12
|
|
|
class ManagerTest extends AbstractTest |
13
|
|
|
{ |
14
|
|
|
public function test_cachePath() |
15
|
|
|
{ |
16
|
|
|
$manager = new Manager(); |
17
|
|
|
self::assertSame(CACHE_PATH, $manager->cachePath()); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function test_filePath() |
21
|
|
|
{ |
22
|
|
|
$manager = new Manager(); |
23
|
|
|
$manager->cachePath(); |
24
|
|
|
self::assertSame(CACHE_PATH . DIRECTORY_SEPARATOR . 'test.php', $manager->filePath('test')); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function test_put() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$manager = new Manager(); |
30
|
|
|
$data = [1, 2]; |
31
|
|
|
$manager->put('test-save', $data); |
32
|
|
|
self::assertFileExists(CACHE_PATH . DIRECTORY_SEPARATOR . 'test-save.php'); |
33
|
|
|
|
34
|
|
|
$manager = new Manager(); |
35
|
|
|
$manager->setActive(true); |
36
|
|
|
self::assertSame($data, $manager->get('test-save')); |
37
|
|
|
|
38
|
|
|
unlink(CACHE_PATH . DIRECTORY_SEPARATOR . 'test-save.php'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function test_saveData() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$manager = new Manager(); |
44
|
|
|
$data = [1, 2]; |
45
|
|
|
$manager->saveData('test-save', $data); |
46
|
|
|
self::assertFileExists(CACHE_PATH . DIRECTORY_SEPARATOR . 'test-save.php'); |
47
|
|
|
|
48
|
|
|
$manager = new Manager(); |
49
|
|
|
$manager->setActive(true); |
50
|
|
|
self::assertSame($data, $manager->get('test-save')); |
51
|
|
|
|
52
|
|
|
unlink(CACHE_PATH . DIRECTORY_SEPARATOR . 'test-save.php'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.