|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AbterPhp\Framework\Bootstrappers\Template; |
|
4
|
|
|
|
|
5
|
|
|
use AbterPhp\Framework\Template\CacheManager; |
|
6
|
|
|
use Opulence\Cache\ArrayBridge; |
|
7
|
|
|
use Opulence\Cache\MemcachedBridge; |
|
8
|
|
|
use Opulence\Cache\RedisBridge; |
|
9
|
|
|
use Opulence\Framework\Configuration\Config; |
|
10
|
|
|
use Opulence\Ioc\Container; |
|
11
|
|
|
use Opulence\Memcached\Memcached; |
|
12
|
|
|
use Opulence\Redis\Redis; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
class CacheManagerBootstrapperTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var CacheManagerBootstrapper */ |
|
18
|
|
|
protected CacheManagerBootstrapper $sut; |
|
19
|
|
|
|
|
20
|
|
|
public function setUp(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->sut = new CacheManagerBootstrapper(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testRegisterBindingsFileBridge() |
|
26
|
|
|
{ |
|
27
|
|
|
Config::set('templates', 'file.path', '/tmp'); |
|
28
|
|
|
|
|
29
|
|
|
$container = new Container(); |
|
30
|
|
|
|
|
31
|
|
|
$this->sut->registerBindings($container); |
|
32
|
|
|
|
|
33
|
|
|
$actual = $container->resolve(CacheManager::class); |
|
34
|
|
|
$this->assertInstanceOf(CacheManager::class, $actual); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testRegisterBindingsArrayBridge() |
|
38
|
|
|
{ |
|
39
|
|
|
Config::set('templates', 'cache.bridge', ArrayBridge::class); |
|
40
|
|
|
|
|
41
|
|
|
$container = new Container(); |
|
42
|
|
|
|
|
43
|
|
|
$this->sut->registerBindings($container); |
|
44
|
|
|
|
|
45
|
|
|
$actual = $container->resolve(CacheManager::class); |
|
46
|
|
|
$this->assertInstanceOf(CacheManager::class, $actual); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testRegisterBindingsMemcachedBridge() |
|
50
|
|
|
{ |
|
51
|
|
|
Config::set('templates', 'cache.bridge', MemcachedBridge::class); |
|
52
|
|
|
Config::set('templates', 'cache.clientName', 'foo'); |
|
53
|
|
|
Config::set('templates', 'cache.keyPrefix', 'bar'); |
|
54
|
|
|
|
|
55
|
|
|
$mockMemcached = $this->getMockBuilder(Memcached::class)->disableOriginalConstructor()->getMock(); |
|
56
|
|
|
|
|
57
|
|
|
$container = new Container(); |
|
58
|
|
|
$container->bindInstance(Memcached::class, $mockMemcached); |
|
59
|
|
|
|
|
60
|
|
|
$this->sut->registerBindings($container); |
|
61
|
|
|
|
|
62
|
|
|
$actual = $container->resolve(CacheManager::class); |
|
63
|
|
|
$this->assertInstanceOf(CacheManager::class, $actual); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testRegisterBindingsRedisBridge() |
|
67
|
|
|
{ |
|
68
|
|
|
Config::set('templates', 'cache.bridge', RedisBridge::class); |
|
69
|
|
|
Config::set('templates', 'cache.clientName', 'foo'); |
|
70
|
|
|
Config::set('templates', 'cache.keyPrefix', 'bar'); |
|
71
|
|
|
|
|
72
|
|
|
$mockRedis = $this->getMockBuilder(Redis::class)->disableOriginalConstructor()->getMock(); |
|
73
|
|
|
|
|
74
|
|
|
$container = new Container(); |
|
75
|
|
|
$container->bindInstance(Redis::class, $mockRedis); |
|
76
|
|
|
|
|
77
|
|
|
$this->sut->registerBindings($container); |
|
78
|
|
|
|
|
79
|
|
|
$actual = $container->resolve(CacheManager::class); |
|
80
|
|
|
$this->assertInstanceOf(CacheManager::class, $actual); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|