@@ -22,6 +22,7 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
22
22
public function setUp ()
23
23
{
24
24
CacheStore \Factory::clearOptions ();
25
+ CacheStore \Factory::enableCaching ();
25
26
}
26
27
27
28
public function testOptions ()
@@ -36,10 +37,10 @@ public function testOptions()
36
37
37
38
public function testOption ()
38
39
{
39
- $ set_apc_option = array (" storage " => 'apc ' , 'default_ttl ' => 10 );
40
+ $ set_apc_option = array (' storage ' => 'apc ' , 'default_ttl ' => 10 );
40
41
CacheStore \Factory::setOption ($ set_apc_option );
41
42
42
- $ set_memcached_option = array (" storage " => 'memcached ' , 'option1 ' => 20 );
43
+ $ set_memcached_option = array (' storage ' => 'memcached ' , 'option1 ' => 20 );
43
44
CacheStore \Factory::setOption ($ set_memcached_option );
44
45
45
46
$ get_apc_option = CacheStore \Factory::getOption ('apc ' );
@@ -60,6 +61,10 @@ public function testFactoryApc()
60
61
61
62
public function testFactoryMemcached ()
62
63
{
64
+ if (!extension_loaded ('memcached ' )) {
65
+ $ this ->markTestSkipped ('Memcached extension is not loaded ' );
66
+ }
67
+
63
68
$ memcached_option = array ('storage ' => 'memcached ' , 'default_ttl ' => 10 , 'prefix ' => '_md ' , 'servers ' => array ());
64
69
CacheStore \Factory::setOption ($ memcached_option );
65
70
@@ -69,6 +74,10 @@ public function testFactoryMemcached()
69
74
70
75
public function testFactoryMemcache ()
71
76
{
77
+ if (!extension_loaded ('memcache ' )) {
78
+ $ this ->markTestSkipped ('Memcache extension is not loaded ' );
79
+ }
80
+
72
81
$ memcached_option = array ('storage ' => 'memcache ' , 'default_ttl ' => 10 , 'prefix ' => '_md ' , 'servers ' => array ());
73
82
CacheStore \Factory::setOption ($ memcached_option );
74
83
@@ -93,7 +102,7 @@ public function testRegisterStorage()
93
102
// register custom storage
94
103
$ customStorage = $ this ->getMock ('Domino\CacheStore\Storage\StorageInterface ' );
95
104
CacheStore \Factory::registerStorage ('custom ' , get_class ($ customStorage ));
96
- $ cacheStore = CacheStore \Factory::factory ('custom ' , get_class ( $ customStorage ) );
105
+ $ cacheStore = CacheStore \Factory::factory ('custom ' );
97
106
$ this ->assertInstanceOf (get_class ($ customStorage ), $ cacheStore );
98
107
99
108
// try to register custom storage with bad interface
@@ -124,4 +133,33 @@ public function testClearConnectionCache()
124
133
125
134
$ this ->assertNotSame ($ store1 , $ store2 );
126
135
}
136
+
137
+ public function testDisableCache ()
138
+ {
139
+ CacheStore \Factory::disableCaching ();
140
+ $ storage = CacheStore \Factory::factory ('apc ' );
141
+
142
+ $ this ->assertInstanceOf ('\Domino\CacheStore\Storage\NoCache ' , $ storage );
143
+ }
144
+
145
+ public function testDisableAndEnableCache ()
146
+ {
147
+ //begin of setup
148
+ $ name = 'custom ' ;
149
+ /** @var CacheStore\Storage\StorageInterface $storageMock */
150
+ $ storageMock = $ this ->getMock ('Domino\CacheStore\Storage\StorageInterface ' );
151
+ CacheStore \Factory::registerStorage ($ name , get_class ($ storageMock ));
152
+ //end of setup
153
+
154
+ //begin of assertions
155
+ $ customStorage = CacheStore \Factory::factory ($ name );
156
+ CacheStore \Factory::disableCaching ();
157
+ $ noCacheStorage = CacheStore \Factory::factory ($ name );
158
+
159
+ $ this ->assertInstanceOf ('\Domino\CacheStore\Storage\NoCache ' , $ noCacheStorage );
160
+ CacheStore \Factory::enableCaching ();
161
+
162
+ $ this ->assertSame ($ customStorage , CacheStore \Factory::factory ($ name ));
163
+ //end of assertions
164
+ }
127
165
}
0 commit comments