From fc75eb9bef8375fd0825f229046d987636d1aa07 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Tue, 9 Jul 2019 07:37:24 +0200 Subject: [PATCH] [Lock] rename and deprecate Factory into LockFactory --- .../Console/Command/LockableTrait.php | 4 +-- .../Tests/Command/LockableTraitTest.php | 4 +-- src/Symfony/Component/Lock/Factory.php | 2 ++ src/Symfony/Component/Lock/LockFactory.php | 22 ++++++++++++ .../Component/Lock/Tests/LockFactoryTest.php | 36 +++++++++++++++++++ 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Component/Lock/LockFactory.php create mode 100644 src/Symfony/Component/Lock/Tests/LockFactoryTest.php diff --git a/src/Symfony/Component/Console/Command/LockableTrait.php b/src/Symfony/Component/Console/Command/LockableTrait.php index f4ebe45bf3..f3bc995945 100644 --- a/src/Symfony/Component/Console/Command/LockableTrait.php +++ b/src/Symfony/Component/Console/Command/LockableTrait.php @@ -12,8 +12,8 @@ namespace Symfony\Component\Console\Command; use Symfony\Component\Console\Exception\LogicException; -use Symfony\Component\Lock\Factory; use Symfony\Component\Lock\Lock; +use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\Store\FlockStore; use Symfony\Component\Lock\Store\SemaphoreStore; @@ -48,7 +48,7 @@ trait LockableTrait $store = new FlockStore(); } - $this->lock = (new Factory($store))->createLock($name ?: $this->getName()); + $this->lock = (new LockFactory($store))->createLock($name ?: $this->getName()); if (!$this->lock->acquire($blocking)) { $this->lock = null; diff --git a/src/Symfony/Component/Console/Tests/Command/LockableTraitTest.php b/src/Symfony/Component/Console/Tests/Command/LockableTraitTest.php index 94b0819bbf..76dc0443ec 100644 --- a/src/Symfony/Component/Console/Tests/Command/LockableTraitTest.php +++ b/src/Symfony/Component/Console/Tests/Command/LockableTraitTest.php @@ -13,7 +13,7 @@ namespace Symfony\Component\Console\Tests\Command; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Lock\Factory; +use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\Store\FlockStore; use Symfony\Component\Lock\Store\SemaphoreStore; @@ -47,7 +47,7 @@ class LockableTraitTest extends TestCase $store = new FlockStore(); } - $lock = (new Factory($store))->createLock($command->getName()); + $lock = (new LockFactory($store))->createLock($command->getName()); $lock->acquire(); $tester = new CommandTester($command); diff --git a/src/Symfony/Component/Lock/Factory.php b/src/Symfony/Component/Lock/Factory.php index f35ad6d8ef..2bc7d9304b 100644 --- a/src/Symfony/Component/Lock/Factory.php +++ b/src/Symfony/Component/Lock/Factory.php @@ -19,6 +19,8 @@ use Psr\Log\NullLogger; * Factory provides method to create locks. * * @author Jérémy Derussé + * + * @deprecated "Symfony\Component\Lock\Factory" is deprecated since Symfony 4.4 and will be removed in 5.0 use "Symfony\Component\Lock\LockFactory" instead */ class Factory implements LoggerAwareInterface { diff --git a/src/Symfony/Component/Lock/LockFactory.php b/src/Symfony/Component/Lock/LockFactory.php new file mode 100644 index 0000000000..f054b532b5 --- /dev/null +++ b/src/Symfony/Component/Lock/LockFactory.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Lock; + +/** + * Factory provides method to create locks. + * + * @author Jérémy Derussé + * @author Hamza Amrouche + */ +class LockFactory extends Factory +{ +} diff --git a/src/Symfony/Component/Lock/Tests/LockFactoryTest.php b/src/Symfony/Component/Lock/Tests/LockFactoryTest.php new file mode 100644 index 0000000000..0ec4fd3976 --- /dev/null +++ b/src/Symfony/Component/Lock/Tests/LockFactoryTest.php @@ -0,0 +1,36 @@ + + * + * 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\LoggerInterface; +use Symfony\Component\Lock\LockFactory; +use Symfony\Component\Lock\LockInterface; +use Symfony\Component\Lock\StoreInterface; + +/** + * @author Jérémy Derussé + */ +class LockFactoryTest extends TestCase +{ + public function testCreateLock() + { + $store = $this->getMockBuilder(StoreInterface::class)->getMock(); + $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); + $factory = new LockFactory($store); + $factory->setLogger($logger); + + $lock = $factory->createLock('foo'); + + $this->assertInstanceOf(LockInterface::class, $lock); + } +}