/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Lock/Tests/LockFactoryTest.php
81 строка
2 KB
Nicolas Grekas
Merge branch '8.0' into 8.1
17 фев 2026, 16:08
17 фев 2026, 16:08
675cb3a
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Lock\Tests; use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\PersistingStoreInterface; /** * @author Jérémy Derussé <jeremy@derusse.com> */ class LockFactoryTest extends TestCase { public function testCreateLock() { $store = $this->createMock(PersistingStoreInterface::class); $store->method('exists')->willReturn(false); $keys = []; $store ->expects($this->exactly(2)) ->method('save') ->with($this->callback(static function ($key) use (&$keys) { $keys[] = $key; return true; })); $factory = new LockFactory($store); $factory->setLogger(new NullLogger()); $lock1 = $factory->createLock('foo'); $lock2 = $factory->createLock('foo'); // assert lock1 and lock2 don't share the same state $lock1->acquire(); $lock2->acquire(); $this->assertNotSame($keys[0], $keys[1]); } public function testCreateLockFromKey() { $store = $this->createMock(PersistingStoreInterface::class); $store->method('exists')->willReturn(false); $keys = []; $store ->expects($this->exactly(2)) ->method('save') ->with($this->callback(static function ($key) use (&$keys) { $keys[] = $key; return true; })); $factory = new LockFactory($store); $factory->setLogger(new NullLogger()); $key = new Key('foo'); $lock1 = $factory->createLockFromKey($key); $lock2 = $factory->createLockFromKey($key); // assert lock1 and lock2 share the same state $lock1->acquire(); $lock2->acquire(); $this->assertSame($keys[0], $keys[1]); } }