Skip to content

Commit 7ca2cde

Browse files
committed
test(adapter-bundle): cover custom factories and Memcached options
1 parent dbfd906 commit 7ca2cde

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

tests/Unit/DependencyInjection/CacheAdapterExtensionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Cache\Adapter\PHPArray\ArrayCachePool;
1717
use Cache\AdapterBundle\CacheAdapterBundle;
1818
use Cache\AdapterBundle\DependencyInjection\CacheAdapterExtension;
19+
use Cache\AdapterBundle\DependencyInjection\CompilerPass\AdapterFactoryCompilerPass;
1920
use Cache\AdapterBundle\DummyAdapter;
2021
use Cache\AdapterBundle\Exception\ConfigurationException;
2122
use Cache\AdapterBundle\Factory\AbstractAdapterFactory;
@@ -63,6 +64,15 @@ public function testItResolvesApplicationDefinedFactoryServicesAfterExtensionsMe
6364
self::assertInstanceOf(ArrayCachePool::class, $container->get('cache.provider.custom'));
6465
}
6566

67+
public function testFactoryCompilerPassIgnoresContainersWithoutFactoryConfiguration()
68+
{
69+
$container = new ContainerBuilder();
70+
71+
(new AdapterFactoryCompilerPass())->process($container);
72+
73+
self::assertFalse($container->hasParameter('cache_adapter.factory_configurations'));
74+
}
75+
6676
public function testAliasProvidersExists()
6777
{
6878
$providers = ['foo' => ['factory' => 'cache.factory.array', 'aliases' => ['alias_http']]];

tests/Unit/Factory/FactoryBehaviorTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,18 @@ public function testMemcachedFactoryPreservesTagSupportWhenNamespaced()
154154
public function testMemcachedDriverOptionsOverridePoolDefaults()
155155
{
156156
if (class_exists(\Memcached::class)) {
157-
$this->markTestSkipped('This test uses a local Memcached stub.');
157+
$defaultId = 'adapter-bundle-default-'.bin2hex(random_bytes(8));
158+
(new MemcachedFactory())->createAdapter(['persistent_id' => $defaultId]);
159+
self::assertTrue((bool) (new \Memcached($defaultId))->getOption(\Memcached::OPT_BINARY_PROTOCOL));
160+
161+
$configuredId = 'adapter-bundle-configured-'.bin2hex(random_bytes(8));
162+
(new MemcachedFactory())->createAdapter([
163+
'persistent_id' => $configuredId,
164+
'driver_options' => ['Memcached::OPT_BINARY_PROTOCOL' => false],
165+
]);
166+
self::assertFalse((bool) (new \Memcached($configuredId))->getOption(\Memcached::OPT_BINARY_PROTOCOL));
167+
168+
return;
158169
}
159170

160171
eval('namespace { class Memcached { public const OPT_BINARY_PROTOCOL = 18; private array $servers = []; public function __construct(?string $persistentId = null) {} public function getServerList(): array { return $this->servers; } public function addServer(mixed $host, mixed $port, mixed $weight = 0): bool { $this->servers[] = ["host" => $host, "port" => $port]; return true; } public function setOption(int $option, mixed $value): bool { \\Cache\\AdapterBundle\\Tests\\Unit\\Factory\\MemcachedOptionRecorder::$options[$option] = $value; return true; } } }');

0 commit comments

Comments
 (0)