diff --git a/.travis.yml b/.travis.yml index 6ca8106..e90670f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: php php: - - 5.6 + - 7.0 + - 7.1 + - 7.2 script: - composer install diff --git a/CHANGELOG.md b/CHANGELOG.md index 44f2c45..cc8438e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Queue Client Changelog +## v2.0.0 + +- Use new Symfony/Lock component in Filesystem handler + ## v1.0.3 - Use Priority objects instead of string diff --git a/composer.json b/composer.json index fd73bd7..e039a3e 100644 --- a/composer.json +++ b/composer.json @@ -8,12 +8,13 @@ } ], "require": { - "symfony/filesystem": ">=2.7", - "symfony/finder": ">=2.7", + "symfony/filesystem": ">=3.4", + "symfony/finder": ">=3.4", + "symfony/lock": ">=3.4", "aws/aws-sdk-php": ">=2.7" }, "require-dev": { - "atoum/atoum": "~2", + "atoum/atoum": "~3.1", "satooshi/php-coveralls": "dev-master" }, "autoload": { diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile index 9593f4b..1a6b6f2 100644 --- a/docker/test/Dockerfile +++ b/docker/test/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7 +FROM php:7.1 RUN pecl install xdebug RUN docker-php-ext-enable xdebug @@ -9,4 +9,4 @@ RUN apt-get update && apt-get install -y \ COPY ./ssh/ssh_config /etc/ssh/ssh_config -WORKDIR /data \ No newline at end of file +WORKDIR /data diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 5ad6a16..3415369 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -7,12 +7,12 @@ use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; -use ReputationVIP\QueueClient\Utils\LockHandlerFactory; -use ReputationVIP\QueueClient\Utils\LockHandlerFactoryInterface; use Symfony\Component\Filesystem\Exception\IOExceptionInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; +use Symfony\Component\Lock\Factory; +use Symfony\Component\Lock\Store\FlockStore; class FileAdapter extends AbstractAdapter implements AdapterInterface { @@ -31,7 +31,7 @@ class FileAdapter extends AbstractAdapter implements AdapterInterface /** @var Filesystem $fs */ private $fs; - /** @var LockHandlerFactoryInterface $fs */ + /** @var Factory $lockHandlerFactory */ private $lockHandlerFactory; /** @var PriorityHandlerInterface $priorityHandler */ @@ -42,12 +42,12 @@ class FileAdapter extends AbstractAdapter implements AdapterInterface * @param PriorityHandlerInterface $priorityHandler * @param Filesystem $fs * @param Finder $finder - * @param LockHandlerFactoryInterface $lockHandlerFactory + * @param Factory $lockHandlerFactory * * @throws \InvalidArgumentException * @throws QueueAccessException */ - public function __construct($repository, PriorityHandlerInterface $priorityHandler = null, Filesystem $fs = null, Finder $finder = null, LockHandlerFactoryInterface $lockHandlerFactory = null) + public function __construct($repository, PriorityHandlerInterface $priorityHandler = null, Filesystem $fs = null, Finder $finder = null, Factory $lockHandlerFactory = null) { if (empty($repository)) { throw new \InvalidArgumentException('Argument repository empty or not defined.'); @@ -61,15 +61,12 @@ public function __construct($repository, PriorityHandlerInterface $priorityHandl $finder = new Finder(); } - if (null === $lockHandlerFactory) { - $lockHandlerFactory = new LockHandlerFactory(); - } - if (null === $priorityHandler) { $priorityHandler = new StandardPriorityHandler(); } $this->fs = $fs; + if (!$this->fs->exists($repository)) { try { $this->fs->mkdir($repository); @@ -78,6 +75,10 @@ public function __construct($repository, PriorityHandlerInterface $priorityHandl } } + if (null === $lockHandlerFactory) { + $lockHandlerFactory = new Factory(new FlockStore($repository)); + } + $this->priorityHandler = $priorityHandler; $this->repository = $repository; $this->finder = $finder; @@ -126,8 +127,8 @@ private function getQueuePath($queueName, Priority $priority) private function readQueueFromFile($queueName, Priority $priority, $nbTries = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); - $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); - if (!$lockHandler->lock()) { + $lock = $this->lockHandlerFactory->createLock($queueFilePath); + if (!$lock->acquire()) { if ($nbTries >= static::MAX_LOCK_TRIES) { throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } @@ -148,10 +149,10 @@ private function readQueueFromFile($queueName, Priority $priority, $nbTries = 0) } $queue = json_decode($content, true); } catch (\Exception $e) { - $lockHandler->release(); + $lock->release(); throw $e; } - $lockHandler->release(); + $lock->release(); return $queue; } @@ -170,8 +171,8 @@ private function readQueueFromFile($queueName, Priority $priority, $nbTries = 0) private function writeQueueInFile($queueName, Priority $priority, $queue, $nbTries = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); - $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); - if (!$lockHandler->lock()) { + $lock = $this->lockHandlerFactory->createLock($queueFilePath); + if (!$lock->acquire()) { if ($nbTries >= static::MAX_LOCK_TRIES) { throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } @@ -182,10 +183,10 @@ private function writeQueueInFile($queueName, Priority $priority, $queue, $nbTri $queueJson = json_encode($queue); $this->fs->dumpFile($queueFilePath, $queueJson); } catch (\Exception $e) { - $lockHandler->release(); + $lock->release(); throw $e; } - $lockHandler->release(); + $lock->release(); return $this; } @@ -205,8 +206,8 @@ private function writeQueueInFile($queueName, Priority $priority, $queue, $nbTri private function addMessageLock($queueName, $message, Priority $priority, $nbTries = 0, $delaySeconds = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); - $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); - if (!$lockHandler->lock()) { + $lock = $this->lockHandlerFactory->createLock($queueFilePath); + if (!$lock->acquire()) { if ($nbTries >= static::MAX_LOCK_TRIES) { throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } @@ -239,10 +240,10 @@ private function addMessageLock($queueName, $message, Priority $priority, $nbTri $queueJson = json_encode($queue); $this->fs->dumpFile($queueFilePath, $queueJson); } catch (\Exception $e) { - $lockHandler->release(); + $lock->release(); throw $e; } - $lockHandler->release(); + $lock->release(); return $this; } @@ -291,8 +292,8 @@ public function addMessage($queueName, $message, Priority $priority = null, $del private function getMessagesLock($queueName, $nbMsg, Priority $priority, $nbTries = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); - $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); - if (!$lockHandler->lock()) { + $lock = $this->lockHandlerFactory->createLock($queueFilePath); + if (!$lock->acquire()) { if ($nbTries >= static::MAX_LOCK_TRIES) { throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } @@ -335,10 +336,10 @@ private function getMessagesLock($queueName, $nbMsg, Priority $priority, $nbTrie $queueJson = json_encode($queue); $this->fs->dumpFile($queueFilePath, $queueJson); } catch (\Exception $e) { - $lockHandler->release(); + $lock->release(); throw $e; } - $lockHandler->release(); + $lock->release(); return $messages; } @@ -399,8 +400,8 @@ public function getMessages($queueName, $nbMsg = 1, Priority $priority = null) private function deleteMessageLock($queueName, $message, Priority $priority, $nbTries = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); - $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); - if (!$lockHandler->lock()) { + $lock = $this->lockHandlerFactory->createLock($queueFilePath); + if (!$lock->acquire()) { if ($nbTries >= static::MAX_LOCK_TRIES) { throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } @@ -431,10 +432,10 @@ private function deleteMessageLock($queueName, $message, Priority $priority, $nb $queueJson = json_encode($queue); $this->fs->dumpFile($queueFilePath, $queueJson); } catch (\Exception $e) { - $lockHandler->release(); + $lock->release(); throw $e; } - $lockHandler->release(); + $lock->release(); return $this; } @@ -570,8 +571,8 @@ private function deleteQueueLock($queueName, Priority $priority, $nbTries = 0) } $queueFilePath = $this->getQueuePath($queueName, $priority); - $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); - if (!$lockHandler->lock()) { + $lock = $this->lockHandlerFactory->createLock($queueFilePath); + if (!$lock->acquire()) { if ($nbTries >= static::MAX_LOCK_TRIES) { throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } @@ -579,7 +580,7 @@ private function deleteQueueLock($queueName, Priority $priority, $nbTries = 0) return $this->deleteQueueLock($queueName, $priority, ($nbTries + 1)); } $this->fs->remove($queueFilePath); - $lockHandler->release(); + $lock->release(); return $this; } diff --git a/src/Utils/LockHandlerFactory.php b/src/Utils/LockHandlerFactory.php deleted file mode 100644 index a46e84e..0000000 --- a/src/Utils/LockHandlerFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -object(new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/')); } - public function testFileAdapter__constructWithFilesystemError(Filesystem $fs, Finder $finder, LockHandlerFactory $lockHandlerFactory) + public function testFileAdapter__constructWithFilesystemError(Filesystem $fs, Finder $finder) { - $this->exception(function () use ($fs, $finder, $lockHandlerFactory) { - $this->newTestedInstance('', null, $fs, $finder, $lockHandlerFactory); + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; + + $this->exception(function () use ($fs, $finder, $mockLockHandlerFactory) { + $this->newTestedInstance('', null, $fs, $finder, $mockLockHandlerFactory); }); $this->calling($fs)->mkdir->throw = new MockIOExceptionInterface; $this->calling($fs)->exists = false; - $this->exception(function () use ($fs, $finder, $lockHandlerFactory) { - $this->newTestedInstance('/tmp/test/', null, $fs, $finder, $lockHandlerFactory); + $this->exception(function () use ($fs, $finder, $mockLockHandlerFactory) { + $this->newTestedInstance('/tmp/test/', null, $fs, $finder, $mockLockHandlerFactory); }); } @@ -53,12 +53,13 @@ public function testFileAdapterDeleteQueue() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $this->calling($mockFs)->exists = true; - $this->calling($mockLockHandlerFactory)->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $this->calling($mockLockHandlerFactory)->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -72,7 +73,8 @@ public function testFileAdapterDeleteQueueWithEmptyQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $this->calling($mockFs)->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -87,12 +89,13 @@ public function testFileAdapterDeleteQueueWithNoQueueFile() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $this->calling($mockFs)->exists = false; - $this->calling($mockLockHandlerFactory)->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $this->calling($mockLockHandlerFactory)->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -107,12 +110,13 @@ public function testFileAdapterDeleteQueueWithLockFailed() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $this->calling($mockFs)->exists = true; - $this->calling($mockLockHandlerFactory)->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = false; + $this->calling($mockLockHandlerFactory)->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -127,11 +131,12 @@ public function testFileAdapterCreateQueue() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -146,11 +151,12 @@ public function testFileAdapterCreateQueueWithFsException() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFs->getMockController()->exists = false; @@ -169,11 +175,12 @@ public function testFileAdapterCreateQueueWithLockFailed() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = false; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -189,7 +196,8 @@ public function testFileAdapterCreateQueueWithEmptyQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $this->calling($mockFs)->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -204,7 +212,8 @@ public function testFileAdapterCreateQueueWithExistingQueue() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -219,7 +228,8 @@ public function testFileAdapterCreateQueueWithSpaceIngQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -234,13 +244,14 @@ public function testFileAdapterPurgeQueue() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -280,7 +291,8 @@ public function testFileAdapterPurgeQueueWithNoQueueFile() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = false; $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -295,7 +307,8 @@ public function testFileAdapterPurgeQueueWithEmptyQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { @@ -309,12 +322,13 @@ public function testFileAdapterPurgeQueueWithLockFailed() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = false; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -329,13 +343,14 @@ public function testFileAdapterPurgeQueueWithEmptyQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -376,13 +391,14 @@ public function testFileAdapterPurgeQueueWithBadQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -423,13 +439,14 @@ public function testFileAdapterIsEmptyWithEmptyQueue() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -472,13 +489,14 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -512,7 +530,8 @@ public function testFileAdapterIsEmptyWithEmptyQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -527,7 +546,8 @@ public function testFileAdapterIsEmptyWithNoQueueFile() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -542,13 +562,14 @@ public function testFileAdapterIsEmptyWithEmptyQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -589,13 +610,14 @@ public function testFileAdapterIsEmptyWithBadQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -636,7 +658,8 @@ public function testFileAdapterListQueues() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -675,7 +698,8 @@ public function testFileAdapterListQueuesWithPrefix() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -714,7 +738,8 @@ public function testFileAdapterListQueuesWithEmptyQueue() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFinder->getMockController()->getIterator = function () { return new ArrayIterator([]); @@ -732,13 +757,14 @@ public function testFileAdapterAddMessage() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -776,14 +802,15 @@ public function testFileAdapterAddMessageWithDelay() { $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -816,7 +843,8 @@ public function testFileAdapterAddMessageWithEmptyQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { @@ -830,7 +858,8 @@ public function testFileAdapterAddMessageWithNoQueueFile() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -845,12 +874,13 @@ public function testFileAdapterAddMessageWithEmptyMessage() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -865,12 +895,13 @@ public function testFileAdapterAddMessageLockFailed() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = false; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -885,13 +916,14 @@ public function testFileAdapterAddMessageWithEmptyQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -932,13 +964,14 @@ public function testFileAdapterAddMessageWithBadQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -979,7 +1012,8 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { @@ -993,7 +1027,8 @@ public function testFileAdapterGetNumberMessagesWithNoQueueFile() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1008,12 +1043,13 @@ public function testFileAdapterGetNumberMessagesLockFailed() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = false; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1028,13 +1064,14 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1075,13 +1112,14 @@ public function testFileAdapterGetNumberMessagesWithBadQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1122,13 +1160,14 @@ public function testFileAdapterGetNumberMessages() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1160,7 +1199,8 @@ public function testFileAdapterGetMessagesWithEmptyQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { @@ -1174,7 +1214,8 @@ public function testFileAdapterGetMessagesWithNoQueueFile() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1189,12 +1230,13 @@ public function testFileAdapterAddMessagesWithNoNumericNbrMsg() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1209,12 +1251,13 @@ public function testFileAdapterGetMessagesWithNotValidNumericNbrMsg() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1232,12 +1275,13 @@ public function testFileAdapterGetMessagesLockFailed() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = false; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1252,13 +1296,14 @@ public function testFileAdapterGetMessagesWithEmptyQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1299,13 +1344,14 @@ public function testFileAdapterGetMessagesWithBadQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1346,13 +1392,14 @@ public function testFileAdapterGetMessages() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1386,7 +1433,8 @@ public function testFileAdapterDeleteMessageWithEmptyQueueName() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { @@ -1400,7 +1448,8 @@ public function testFileAdapterDeleteMessageWithNoQueueFile() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = false; @@ -1416,7 +1465,8 @@ public function testFileAdapterDeleteMessageWithNoMessage() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1431,7 +1481,8 @@ public function testFileAdapterDeleteMessageWithNoIdField() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; @@ -1447,7 +1498,8 @@ public function testFileAdapterDeleteMessageWithNotPriorityField() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1462,7 +1514,8 @@ public function testFileAdapterDeleteMessageWithBadMessageType() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $mockFs->getMockController()->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1477,13 +1530,14 @@ public function testFileAdapterDeleteMessageLockFailed() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = false; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); @@ -1498,13 +1552,14 @@ public function testFileAdapterDeleteMessageWithEmptyQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1545,13 +1600,14 @@ public function testFileAdapterDeleteMessageWithBadQueueContent() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1592,13 +1648,14 @@ public function testFileAdapterDeleteMessage() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1630,7 +1687,8 @@ public function testFileAdapterRenameQueueWithEmptyParameter() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { @@ -1647,7 +1705,8 @@ public function testFileAdapterRenameQueue() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = function ($queue) { @@ -1656,9 +1715,9 @@ public function testFileAdapterRenameQueue() } return true; }; - $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { - $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); - $mockLockHandler->getMockController()->lock = true; + $mockLockHandlerFactory->getMockController()->createLock = function ($repository) { + $mockLockHandler = new \mock\Symfony\Component\Lock\LockInterface; + $mockLockHandler->getMockController()->acquire = true; return $mockLockHandler; }; $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { @@ -1690,7 +1749,8 @@ public function testFileAdapterGetPriorityHandler() $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; - $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->mockGenerator->orphanize('__construct'); + $mockLockHandlerFactory = new \mock\Symfony\Component\Lock\Factory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->given($fileAdapter)