Skip to content

Commit

Permalink
minor #23446 [Cache] Added test for ApcuAdapter when using in CLI (ly…
Browse files Browse the repository at this point in the history
…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 2fc9bd2
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php
Expand Up @@ -11,6 +11,7 @@


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


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


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


public function createCachePool($defaultLifetime = 0) 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.'); $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) { if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Fails transiently on Windows.'); $this->markTestSkipped('Fails transiently on Windows.');
} }
Expand Down Expand Up @@ -70,4 +76,24 @@ public function testVersion()
$this->assertFalse($item->isHit()); $this->assertFalse($item->isHit());
$this->assertNull($item->get()); $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.