forked from TruCopilot/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomDriver.test.php
More file actions
73 lines (62 loc) · 2.86 KB
/
CustomDriver.test.php
File metadata and controls
73 lines (62 loc) · 2.86 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
<?php
/**
*
* This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
*
* @author Georges.L (Geolim4) <contact@geolim4.com>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
use Phpfastcache\CacheManager;
use Phpfastcache\Drivers\Fakefiles\Config;
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
use Phpfastcache\Tests\Helper\TestHelper;
chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/mock/Autoload.php';
$testHelper = new TestHelper('Custom driver');
if (!class_exists(Phpfastcache\Drivers\Fakefiles\Item::class)
|| !class_exists(Phpfastcache\Drivers\Fakefiles\Driver::class)
|| !class_exists(Phpfastcache\Drivers\Fakefiles\Config::class)
) {
$testHelper->assertFail('The php classes of driver "Fakefiles" does not exists');
$testHelper->terminateTest();
} else {
$testHelper->assertPass('The php classes of driver "Fakefiles" were found');
}
try {
CacheManager::addCustomDriver('Fakefiles', \Phpfastcache\Drivers\Fakefiles\Driver::class);
$testHelper->assertPass('No exception thrown while trying to add a custom driver');
} catch (\Throwable $e) {
$testHelper->assertFail('An exception has been thrown while trying to add a custom driver');
}
try {
CacheManager::addCustomDriver('Fakefiles', \Phpfastcache\Drivers\Fakefiles\Driver::class);
$testHelper->assertFail('No exception thrown while trying to re-add a the same custom driver');
} catch (\Throwable $e) {
$testHelper->assertPass('An exception has been thrown while trying to re-add a the same custom driver');
}
try {
CacheManager::addCustomDriver('', \Phpfastcache\Drivers\Fakefiles\Driver::class);
$testHelper->assertFail('No exception thrown while trying to override an empty driver');
} catch (PhpfastcacheInvalidArgumentException $e) {
$testHelper->assertPass('An exception has been thrown while trying to override an empty driver');
}
try {
$cacheInstance = CacheManager::getInstance('Fakefiles', new Config(['customOption' => true]));
$testHelper->assertPass('The custom driver is unavailable at the moment and no exception has been thrown.');
} catch (PhpfastcacheDriverCheckException $e) {
$testHelper->assertPass('The custom driver is unavailable at the moment and the exception has been catch.');
}
CacheManager::removeCustomDriver('Fakefiles');
try {
$cacheInstance = CacheManager::getInstance('Fakefiles');
$testHelper->assertPass('The custom driver has been removed but is still active.');
} catch (PhpfastcacheDriverCheckException $e) {
$testHelper->assertPass('The custom driver is unavailable at the moment and the exception has been catch.');
}
$testHelper->terminateTest();