Skip to content

[Cache] Added test for ApcuAdapter when using in CLI #23446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Cache\Tests\Adapter;

use Psr\Log\NullLogger;
use Symfony\Component\Cache\Adapter\ApcuAdapter;

class ApcuAdapterTest extends AdapterTestCase
Expand All @@ -23,9 +24,14 @@ class ApcuAdapterTest extends AdapterTestCase

public function createCachePool($defaultLifetime = 0)
{
if (!function_exists('apcu_fetch') || !ini_get('apc.enabled') || ('cli' === PHP_SAPI && !ini_get('apc.enable_cli'))) {
if (!function_exists('apcu_fetch') || !ini_get('apc.enabled')) {
$this->markTestSkipped('APCu extension is required.');
}
if ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
if ('testWithCliSapi' !== $this->getName()) {
$this->markTestSkipped('APCu extension is required.');
}
}
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Fails transiently on Windows.');
}
Expand Down Expand Up @@ -70,4 +76,24 @@ public function testVersion()
$this->assertFalse($item->isHit());
$this->assertNull($item->get());
}

public function testWithCliSapi()
{
try {
// disable PHPUnit error handler to mimic a production environment
$isCalled = false;
set_error_handler(function () use (&$isCalled) {
$isCalled = true;
});
$pool = new ApcuAdapter(str_replace('\\', '.', __CLASS__));
$pool->setLogger(new NullLogger());

$item = $pool->getItem('foo');
$item->isHit();
$pool->save($item->set('bar'));
$this->assertFalse($isCalled);
} finally {
restore_error_handler();
}
}
}