Permalink
Browse files

minor #23446 [Cache] Added test for ApcuAdapter when using in CLI (ly…

…rixx)

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 | #23344
| License       | MIT
| Doc PR        | -

---

I also hit #23344 and I did not notice it was already fixed (#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
  • Loading branch information...
nicolas-grekas committed Jul 11, 2017
2 parents 195d949 + 64d196a commit 2fc9bd2f99431cd5a38f18d10fec6dc82efa5b32
Showing with 27 additions and 1 deletion.
  1. +27 −1 src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php
@@ -11,6 +11,7 @@
namespace Symfony\Component\Cache\Tests\Adapter;
use Psr\Log\NullLogger;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
class ApcuAdapterTest extends AdapterTestCase
@@ -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.');
}
@@ -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();
}
}
}

0 comments on commit 2fc9bd2

Please sign in to comment.