diff --git a/src/Symfony/Component/Lock/Store/StoreFactory.php b/src/Symfony/Component/Lock/Store/StoreFactory.php index a7c8168d8d..b702b81b70 100644 --- a/src/Symfony/Component/Lock/Store/StoreFactory.php +++ b/src/Symfony/Component/Lock/Store/StoreFactory.php @@ -58,7 +58,7 @@ class StoreFactory return new FlockStore(substr($connection, 8)); case 'semaphore' === $connection: return new SemaphoreStore(); - case preg_match('#^[a-z]++://#', $connection): + case \class_exists(AbstractAdapter::class) && preg_match('#^[a-z]++://#', $connection): return static::createStore(AbstractAdapter::createConnection($connection)); default: throw new InvalidArgumentException(sprintf('Unsupported Connection: %s.', $connection)); diff --git a/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php b/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php index cd93a8cc9f..4edb4d361a 100644 --- a/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Lock\Tests\Store; use PHPUnit\Framework\TestCase; +use Symfony\Component\Cache\Adapter\AbstractAdapter; use Symfony\Component\Cache\Traits\RedisProxy; use Symfony\Component\Lock\Store\FlockStore; use Symfony\Component\Lock\Store\MemcachedStore; @@ -40,19 +41,24 @@ class StoreFactoryTest extends TestCase if (\class_exists(\Redis::class)) { yield [$this->createMock(\Redis::class), RedisStore::class]; } - yield [$this->createMock(RedisProxy::class), RedisStore::class]; - yield [$this->createMock(\Predis\Client::class), RedisStore::class]; + if (\class_exists(RedisProxy::class)) { + yield [$this->createMock(RedisProxy::class), RedisStore::class]; + } + yield [new \Predis\Client(), RedisStore::class]; if (\class_exists(\Memcached::class)) { - yield [$this->createMock(\Memcached::class), MemcachedStore::class]; + yield [new \Memcached(), MemcachedStore::class]; } if (\class_exists(\Zookeeper::class)) { yield [$this->createMock(\Zookeeper::class), ZookeeperStore::class]; } - yield ['flock', FlockStore::class]; - yield ['flock:///tmp', FlockStore::class]; - yield ['semaphore', SemaphoreStore::class]; - if (\class_exists(\Memcached::class)) { + if (\extension_loaded('sysvsem')) { + yield ['semaphore', SemaphoreStore::class]; + } + if (\class_exists(\Memcached::class) && \class_exists(AbstractAdapter::class)) { yield ['memcached://server.com', MemcachedStore::class]; } + + yield ['flock', FlockStore::class]; + yield ['flock://'.sys_get_temp_dir(), FlockStore::class]; } }