11
11
12
12
namespace Symfony \Component \Cache \Tests \Adapter ;
13
13
14
+ use Psr \Log \NullLogger ;
14
15
use Symfony \Component \Cache \Adapter \ApcuAdapter ;
15
16
16
17
class ApcuAdapterTest extends AdapterTestCase
@@ -23,9 +24,14 @@ class ApcuAdapterTest extends AdapterTestCase
23
24
24
25
public function createCachePool ($ defaultLifetime = 0 )
25
26
{
26
- if (!function_exists ('apcu_fetch ' ) || !ini_get ('apc.enabled ' ) || ( ' cli ' === PHP_SAPI && ! ini_get ( ' apc.enable_cli ' )) ) {
27
+ if (!function_exists ('apcu_fetch ' ) || !ini_get ('apc.enabled ' )) {
27
28
$ this ->markTestSkipped ('APCu extension is required. ' );
28
29
}
30
+ if ('cli ' === PHP_SAPI && !ini_get ('apc.enable_cli ' )) {
31
+ if ('testWithCliSapi ' !== $ this ->getName ()) {
32
+ $ this ->markTestSkipped ('APCu extension is required. ' );
33
+ }
34
+ }
29
35
if ('\\' === DIRECTORY_SEPARATOR ) {
30
36
$ this ->markTestSkipped ('Fails transiently on Windows. ' );
31
37
}
@@ -70,4 +76,24 @@ public function testVersion()
70
76
$ this ->assertFalse ($ item ->isHit ());
71
77
$ this ->assertNull ($ item ->get ());
72
78
}
79
+
80
+ public function testWithCliSapi ()
81
+ {
82
+ try {
83
+ // disable PHPUnit error handler to mimic a production environment
84
+ $ isCalled = false ;
85
+ set_error_handler (function () use (&$ isCalled ) {
86
+ $ isCalled = true ;
87
+ });
88
+ $ pool = new ApcuAdapter (str_replace ('\\' , '. ' , __CLASS__ ));
89
+ $ pool ->setLogger (new NullLogger ());
90
+
91
+ $ item = $ pool ->getItem ('foo ' );
92
+ $ item ->isHit ();
93
+ $ pool ->save ($ item ->set ('bar ' ));
94
+ $ this ->assertFalse ($ isCalled );
95
+ } finally {
96
+ restore_error_handler ();
97
+ }
98
+ }
73
99
}
0 commit comments