Skip to content

Commit 2fc9bd2

Browse files
minor symfony#23446 [Cache] Added test for ApcuAdapter when using in CLI (lyrixx)
This PR was merged into the 3.2 branch. Discussion ---------- [Cache] Added test for ApcuAdapter when using in CLI | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#23344 | License | MIT | Doc PR | - --- I also hit symfony#23344 and I did not notice it was already fixed (symfony#23390) and released (2 days ago, I updated the vendors 4 days ago :trollface: ). But as I have written test for it ... Let's contribute anyway Commits ------- 64d196a [Cache] Added test for ApcuAdapter when using in CLI
2 parents 195d949 + 64d196a commit 2fc9bd2

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use Psr\Log\NullLogger;
1415
use Symfony\Component\Cache\Adapter\ApcuAdapter;
1516

1617
class ApcuAdapterTest extends AdapterTestCase
@@ -23,9 +24,14 @@ class ApcuAdapterTest extends AdapterTestCase
2324

2425
public function createCachePool($defaultLifetime = 0)
2526
{
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')) {
2728
$this->markTestSkipped('APCu extension is required.');
2829
}
30+
if ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
31+
if ('testWithCliSapi' !== $this->getName()) {
32+
$this->markTestSkipped('APCu extension is required.');
33+
}
34+
}
2935
if ('\\' === DIRECTORY_SEPARATOR) {
3036
$this->markTestSkipped('Fails transiently on Windows.');
3137
}
@@ -70,4 +76,24 @@ public function testVersion()
7076
$this->assertFalse($item->isHit());
7177
$this->assertNull($item->get());
7278
}
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+
}
7399
}

0 commit comments

Comments
 (0)