From 044e3e7c6ee5eeaf69a7efe94c156bb8aab4762b Mon Sep 17 00:00:00 2001 From: tommyclark Date: Thu, 3 Mar 2016 21:13:08 +0000 Subject: [PATCH 01/51] Add the ability to set a delay on items when adding to a queue --- src/Adapter/AbstractAdapter.php | 3 ++- src/Adapter/AdapterInterface.php | 3 ++- src/Adapter/FileAdapter.php | 12 ++++++++---- src/Adapter/MemoryAdapter.php | 7 +++++-- src/Adapter/SQSAdapter.php | 3 ++- src/QueueClient.php | 4 ++-- src/QueueClientInterface.php | 3 ++- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index fc67bb0..33fd5b4 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -27,10 +27,11 @@ public function addMessages($queueName, $messages, $priority = null) * @param string $queueName * @param mixed $message * @param string $priority + * @param int $delay * * @return AdapterInterface */ - public function addMessage($queueName, $message, $priority = null) + public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { return $this; } diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index bb014b5..ef6beae 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -10,11 +10,12 @@ interface AdapterInterface * @param string $queueName * @param mixed $message * @param string $priority + * @param int $delaySeconds * @throw InvalidArgumentException * * @return AdapterInterface */ - public function addMessage($queueName, $message, $priority = null); + public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0); /** * @param string $queueName diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 3d6f9e3..2713e55 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -186,11 +186,12 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) * @param string $message * @param string $priority * @param int $nbTries + * @param int $delaySeconds * * @return AdapterInterface * @throws \Exception */ - private function addMessageLock($queueName, $message, $priority, $nbTries = 0) + private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $delaySeconds = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); @@ -200,7 +201,7 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0) } usleep(10); - return $this->addMessageLock($queueName, $message, $priority, ($nbTries + 1)); + return $this->addMessageLock($queueName, $message, $priority, ($nbTries + 1), $delaySeconds); } try { $content = ''; @@ -220,6 +221,7 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0) $new_message = [ 'id' => uniqid($queueName . $priority, true), 'time-in-flight' => null, + 'delayed-until' => time() + $delaySeconds, 'Body' => serialize($message), ]; array_push($queue['queue'], $new_message); @@ -236,7 +238,7 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0) /** * @inheritdoc */ - public function addMessage($queueName, $message, $priority = null) + public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { if (null === $priority) { $priority = $this->priorityHandler->getDefault(); @@ -297,7 +299,9 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) } foreach ($queue['queue'] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; - if (null === $message['time-in-flight'] || $timeDiff > static::MAX_TIME_IN_FLIGHT) { + if ((null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) + && $message['delayedUntil'] < time() + ) { $queue['queue'][$key]['time-in-flight'] = time(); $message['time-in-flight'] = time(); $message['Body'] = unserialize($message['Body']); diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index de72d3e..357b94b 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -42,7 +42,7 @@ private function startsWith($haystack, $needle) /** * @inheritdoc */ - public function addMessage($queueName, $message, $priority = null) + public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { if (null === $priority) { $priority = $this->priorityHandler->getDefault(); @@ -62,6 +62,7 @@ public function addMessage($queueName, $message, $priority = null) $new_message = [ 'id' => uniqid($queueName . $priority, true), 'time-in-flight' => null, + 'delayed-until' => time() + $delaySeconds, 'Body' => serialize($message), ]; /** @var SplQueue $splQueue */ @@ -141,7 +142,9 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) if (isset($this->queues[$queueName][$priority])) { foreach ($this->queues[$queueName][$priority] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; - if (null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) { + if ((null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) + && $message['delayedUntil'] < time() + ) { $splQueueContent = $this->queues[$queueName][$priority][$key]; $splQueueContent['time-in-flight'] = time(); $this->queues[$queueName][$priority][$key] = $splQueueContent; diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index b2a6fbb..f8cbb39 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -102,7 +102,7 @@ public function addMessages($queueName, $messages, $priority = null) * * @throws SqsException */ - public function addMessage($queueName, $message, $priority = null) + public function addMessage($queueName, $message, $priority = null, $delaySeconds = null) { if (null === $priority) { $priority = $this->priorityHandler->getDefault(); @@ -120,6 +120,7 @@ public function addMessage($queueName, $message, $priority = null) $this->sqsClient->sendMessage([ 'QueueUrl' => $queueUrl, 'MessageBody' => $message, + 'delaySeconds' => $delaySeconds ]); return $this; diff --git a/src/QueueClient.php b/src/QueueClient.php index 9c38f6f..58e6534 100644 --- a/src/QueueClient.php +++ b/src/QueueClient.php @@ -51,12 +51,12 @@ public function __construct(AdapterInterface $adapter = null) /** * @inheritdoc */ - public function addMessage($queueName, $message, $priority = null) + public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { $queues = (array) $this->resolveAliasQueueName($queueName); foreach ($queues as $queue) { - $this->adapter->addMessage($queue, $message, $priority); + $this->adapter->addMessage($queue, $message, $priority, $delaySeconds); } return $this; diff --git a/src/QueueClientInterface.php b/src/QueueClientInterface.php index 78c29c1..f094864 100644 --- a/src/QueueClientInterface.php +++ b/src/QueueClientInterface.php @@ -10,11 +10,12 @@ interface QueueClientInterface * @param string $queueName * @param mixed $message * @param string $priority + * @param int $delaySeconds * @throw InvalidArgumentException * * @return QueueClientInterface */ - public function addMessage($queueName, $message, $priority = null); + public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0); /** * @param string $queueName From bf0672925322d04cab81189831f4980185700107 Mon Sep 17 00:00:00 2001 From: tommyclark Date: Thu, 3 Mar 2016 21:38:22 +0000 Subject: [PATCH 02/51] Fixed unit test failures --- src/Adapter/AbstractAdapter.php | 2 +- src/Adapter/FileAdapter.php | 2 +- src/Adapter/MemoryAdapter.php | 2 +- src/Adapter/SQSAdapter.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 33fd5b4..5af26a3 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -27,7 +27,7 @@ public function addMessages($queueName, $messages, $priority = null) * @param string $queueName * @param mixed $message * @param string $priority - * @param int $delay + * @param int $delaySeconds * * @return AdapterInterface */ diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 2713e55..5b69213 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -300,7 +300,7 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) foreach ($queue['queue'] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; if ((null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) - && $message['delayedUntil'] < time() + && $message['delayed-until'] < time() ) { $queue['queue'][$key]['time-in-flight'] = time(); $message['time-in-flight'] = time(); diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index 357b94b..b26a0a6 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -143,7 +143,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) foreach ($this->queues[$queueName][$priority] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; if ((null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) - && $message['delayedUntil'] < time() + && $message['delayed-until'] < time() ) { $splQueueContent = $this->queues[$queueName][$priority][$key]; $splQueueContent['time-in-flight'] = time(); diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index f8cbb39..73345b1 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -102,7 +102,7 @@ public function addMessages($queueName, $messages, $priority = null) * * @throws SqsException */ - public function addMessage($queueName, $message, $priority = null, $delaySeconds = null) + public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { if (null === $priority) { $priority = $this->priorityHandler->getDefault(); From d840d287419384b74d14cb7ea9df1f819ffd5186 Mon Sep 17 00:00:00 2001 From: tommyclark Date: Thu, 3 Mar 2016 21:58:32 +0000 Subject: [PATCH 03/51] Add delayed-until to mocked message contents --- tests/units/Adapter/FileAdapter.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index a5c7aa5..792df3f 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -418,7 +418,7 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null,"Body":"s:12:\"Test message\";"}]}'; }; + $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null, "delayed-until":null,"time-in-flight":null, "delayed-until":null,"Body":"s:12:\"Test message\";"}]}'; }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -918,7 +918,7 @@ public function testFileAdapterGetNumberMessages() { $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null,"Body":"s:12:\"Test message\";"},{"id":"testQueue-HIGH559f9a97733a01.98514574","time-in-flight":null,"Body":"s:16:\"test message two\";"}]}'; }; + $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null, "delayed-until":null,"delayed-until":null,"Body":"s:12:\"Test message\";"},{"id":"testQueue-HIGH559f9a97733a01.98514574","time-in-flight":null, "delayed-until":null,"Body":"s:16:\"test message two\";"}]}'; }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -1106,7 +1106,7 @@ public function testFileAdapterGetMessages() { $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null,"Body":"s:12:\"Test message\";"},{"id":"testQueue-HIGH559f9a97733a01.98514574","time-in-flight":null,"Body":"s:16:\"test message two\";"}]}'; }; + $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null, "delayed-until":null,"Body":"s:12:\"Test message\";"},{"id":"testQueue-HIGH559f9a97733a01.98514574","time-in-flight":null, "delayed-until":null,"Body":"s:16:\"test message two\";"}]}'; }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -1316,7 +1316,7 @@ public function testFileAdapterDeleteMessage() $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null,"Body":"s:12:\"Test message\";"},{"id":"testQueue-HIGH559f9a97733a01.98514574","time-in-flight":null,"Body":"s:16:\"test message two\";"}]}'; }; + $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null, "delayed-until":null,"Body":"s:12:\"Test message\";"},{"id":"testQueue-HIGH559f9a97733a01.98514574","time-in-flight":null, "delayed-until":null,"Body":"s:16:\"test message two\";"}]}'; }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -1374,7 +1374,7 @@ public function testFileAdapterRenameQueue() $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null,"Body":"s:12:\"Test message\";"},{"id":"testQueue-HIGH559f9a97733a01.98514574","time-in-flight":null,"Body":"s:16:\"test message two\";"}]}'; }; + $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[{"id":"testQueue-HIGH559f77704e87c5.40358915","time-in-flight":null, "delayed-until":null,"Body":"s:12:\"Test message\";"},{"id":"testQueue-HIGH559f9a97733a01.98514574","time-in-flight":null, "delayed-until":null,"Body":"s:16:\"test message two\";"}]}'; }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); From c8aca5ab414b9d1515ace9baab2cb81fd9144a1b Mon Sep 17 00:00:00 2001 From: tommyclark Date: Fri, 4 Mar 2016 11:32:45 +0000 Subject: [PATCH 04/51] Extra tests with 1 second delay --- tests/units/Adapter/FileAdapter.php | 38 +++++++++++++++++++++++++++ tests/units/Adapter/MemoryAdapter.php | 11 ++++++++ 2 files changed, 49 insertions(+) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index 792df3f..12f1afb 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -646,6 +646,44 @@ public function testFileAdapterAddMessage() ->class($FileAdapter->addMessage('testQueue', 'test Message one'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } + public function testFileAdapterAddMessageWithDelay() + { + $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $mockFinder = new \mock\Symfony\Component\Finder\Finder; + $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + + $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; + return $mockLockHandler; + }; + $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { + $files = []; + $priorities = $priorityHandler->getAll(); + foreach ($priorities as $priority) { + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + } + $mocksSplFileInfo = []; + foreach ($files as $file) { + $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); + + $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; + $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; + $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[]}'; }; + $mocksSplFileInfo[] = $mockSplFileInfo; + } + return new ArrayIterator($mocksSplFileInfo); + }; + $FileAdapter = $FileAdapter->addMessage('testQueue', 'test Message one', null, 1); + sleep(1); + $this->given($FileAdapter) + ->class($FileAdapter)->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + } + public function testFileAdapterAddMessageWithEmptyQueueName() { $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; diff --git a/tests/units/Adapter/MemoryAdapter.php b/tests/units/Adapter/MemoryAdapter.php index 7b8ca10..c6caa01 100644 --- a/tests/units/Adapter/MemoryAdapter.php +++ b/tests/units/Adapter/MemoryAdapter.php @@ -171,6 +171,17 @@ public function testMemoryAdapterAddMessage() ->class($MemoryAdapter->AddMessage('testQueue', 'test message'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } + public function testMemoryAdapterAddMessageWithDelay() + { + $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + + $MemoryAdapter->createQueue('testQueue'); + $MemoryAdapter = $MemoryAdapter->AddMessage('testQueue', 'test message', null, 1); + sleep(1); + $this->given($MemoryAdapter) + ->class($MemoryAdapter)->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + } + public function testMemoryAdapterAddMessageWithEmptyQueueName() { $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); From 3d28de421d5b7e467f3e5597b67bc8e7d64160db Mon Sep 17 00:00:00 2001 From: tommyclark Date: Fri, 4 Mar 2016 12:26:45 +0000 Subject: [PATCH 05/51] Fix bug for 0 second delays in memory and file queues --- src/Adapter/FileAdapter.php | 2 +- src/Adapter/MemoryAdapter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 5b69213..3254518 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -300,7 +300,7 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) foreach ($queue['queue'] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; if ((null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) - && $message['delayed-until'] < time() + && $message['delayed-until'] <= time() ) { $queue['queue'][$key]['time-in-flight'] = time(); $message['time-in-flight'] = time(); diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index b26a0a6..a877036 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -143,7 +143,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) foreach ($this->queues[$queueName][$priority] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; if ((null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) - && $message['delayed-until'] < time() + && $message['delayed-until'] <= time() ) { $splQueueContent = $this->queues[$queueName][$priority][$key]; $splQueueContent['time-in-flight'] = time(); From eb6b172f89796801de88cb9c3739d704ca865dfc Mon Sep 17 00:00:00 2001 From: tommyclark Date: Mon, 7 Mar 2016 10:04:57 +0000 Subject: [PATCH 06/51] Nothing to delete from mock --- tests/units/Adapter/FileAdapter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index 12f1afb..f5e8c4a 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -51,6 +51,8 @@ public function testFileAdapterDeleteQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $this->calling($mockFs)->exists = true; + $this->calling($mockFs)->remove = function($repository) {}; + $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); From 2a517ac347fcc8ae3775cf432b05f66822fa6aa3 Mon Sep 17 00:00:00 2001 From: tommyclark Date: Mon, 7 Mar 2016 13:50:21 +0000 Subject: [PATCH 07/51] Tests actually work fine without this locally. Travis seems to still be having trouble for some reason. --- tests/units/Adapter/FileAdapter.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index f5e8c4a..12f1afb 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -51,8 +51,6 @@ public function testFileAdapterDeleteQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $this->calling($mockFs)->exists = true; - $this->calling($mockFs)->remove = function($repository) {}; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); From fa611d1b1fdd027505c27c5a9150104cb36cf062 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Fri, 11 Mar 2016 09:30:46 +0100 Subject: [PATCH 08/51] Fix case in test files --- tests/units/Adapter/FileAdapter.php | 354 ++++++++++++------------- tests/units/Adapter/MemoryAdapter.php | 356 +++++++++++++------------- tests/units/Adapter/NullAdapter.php | 48 ++-- tests/units/Adapter/SQSAdapter.php | 212 +++++++-------- 4 files changed, 485 insertions(+), 485 deletions(-) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index 12f1afb..d071485 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -51,14 +51,14 @@ public function testFileAdapterDeleteQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $this->calling($mockFs)->exists = true; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; - $this->given($FileAdapter) - ->class($FileAdapter->deleteQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($fileAdapter) + ->class($fileAdapter->deleteQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testFileAdapterDeleteQueueWithEmptyQueueName() @@ -67,9 +67,9 @@ public function testFileAdapterDeleteQueueWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->deleteQueue(''); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->deleteQueue(''); }); } @@ -80,14 +80,14 @@ public function testFileAdapterDeleteQueueWithNoQueueFile() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $this->calling($mockFs)->exists = false; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->deleteQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->deleteQueue('testQueue'); }); } @@ -97,15 +97,15 @@ public function testFileAdapterDeleteQueueWithLockFailed() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->calling($mockFs)->exists = true; $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->deleteQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->deleteQueue('testQueue'); }); } @@ -115,15 +115,15 @@ public function testFileAdapterCreateQueue() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; $mockFs->getMockController()->exists = false; - $this->given($FileAdapter) - ->class($FileAdapter->createQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($fileAdapter) + ->class($fileAdapter->createQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testFileAdapterCreateQueueWithFsException() @@ -132,7 +132,7 @@ public function testFileAdapterCreateQueueWithFsException() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; @@ -142,8 +142,8 @@ public function testFileAdapterCreateQueueWithFsException() $mockFs->getMockController()->dumpFile = function($repository) { throw new \Exception('test exception'); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->createQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->createQueue('testQueue'); }); } @@ -153,15 +153,15 @@ public function testFileAdapterCreateQueueWithLockFailed() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; $mockFs->getMockController()->exists = false; - $this->exception(function() use($FileAdapter) { - $FileAdapter->createQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->createQueue('testQueue'); }); } @@ -171,9 +171,9 @@ public function testFileAdapterCreateQueueWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->createQueue(''); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->createQueue(''); }); } @@ -183,10 +183,10 @@ public function testFileAdapterCreateQueueWithExistingQueue() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; - $this->exception(function() use($FileAdapter) { - $FileAdapter->createQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->createQueue('testQueue'); }); } @@ -196,10 +196,10 @@ public function testFileAdapterCreateQueueWithSpaceIngQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; - $this->exception(function() use($FileAdapter) { - $FileAdapter->createQueue('test Queue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->createQueue('test Queue'); }); } @@ -210,7 +210,7 @@ public function testFileAdapterPurgeQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -235,8 +235,8 @@ public function testFileAdapterPurgeQueue() } return new ArrayIterator($mocksSplFileInfo); }; - $this->given($FileAdapter) - ->class($FileAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($fileAdapter) + ->class($fileAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testFileAdapterPurgeQueueWithNoQueueFile() @@ -245,10 +245,10 @@ public function testFileAdapterPurgeQueueWithNoQueueFile() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; - $this->exception(function() use($FileAdapter) { - $FileAdapter->purgeQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->purgeQueue('testQueue'); }); } @@ -258,9 +258,9 @@ public function testFileAdapterPurgeQueueWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->purgeQueue(''); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->purgeQueue(''); }); } @@ -269,15 +269,15 @@ public function testFileAdapterPurgeQueueWithLockFailed() { $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->purgeQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->purgeQueue('testQueue'); }); } @@ -287,7 +287,7 @@ public function testFileAdapterPurgeQueueWithEmptyQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -312,8 +312,8 @@ public function testFileAdapterPurgeQueueWithEmptyQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->purgeQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->purgeQueue('testQueue'); }); } @@ -323,7 +323,7 @@ public function testFileAdapterPurgeQueueWithBadQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -348,8 +348,8 @@ public function testFileAdapterPurgeQueueWithBadQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->purgeQueue('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->purgeQueue('testQueue'); }); } @@ -360,7 +360,7 @@ public function testFileAdapterIsEmptyWithEmptyQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -386,8 +386,8 @@ public function testFileAdapterIsEmptyWithEmptyQueue() return new ArrayIterator($mocksSplFileInfo); }; $this - ->given($FileAdapter) - ->boolean($FileAdapter->isEmpty('testQueue')) + ->given($fileAdapter) + ->boolean($fileAdapter->isEmpty('testQueue')) ->isTrue(); } @@ -398,7 +398,7 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -424,8 +424,8 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() return new ArrayIterator($mocksSplFileInfo); }; $this - ->given($FileAdapter) - ->boolean($FileAdapter->isEmpty('testQueue')) + ->given($fileAdapter) + ->boolean($fileAdapter->isEmpty('testQueue')) ->isFalse(); } @@ -435,9 +435,9 @@ public function testFileAdapterIsEmptyWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->isEmpty(''); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->isEmpty(''); }); } @@ -447,10 +447,10 @@ public function testFileAdapterIsEmptyWithNoQueueFile() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; - $this->exception(function() use($FileAdapter) { - $FileAdapter->isEmpty('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->isEmpty('testQueue'); }); } @@ -461,7 +461,7 @@ public function testFileAdapterIsEmptyWithEmptyQueueContent() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -486,8 +486,8 @@ public function testFileAdapterIsEmptyWithEmptyQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->isEmpty('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->isEmpty('testQueue'); }); } @@ -498,7 +498,7 @@ public function testFileAdapterIsEmptyWithBadQueueContent() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -523,8 +523,8 @@ public function testFileAdapterIsEmptyWithBadQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->isEmpty('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->isEmpty('testQueue'); }); } @@ -535,7 +535,7 @@ public function testFileAdapterListQueues() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { $files = []; $priorities = $priorityHandler->getAll(); @@ -556,8 +556,8 @@ public function testFileAdapterListQueues() return new ArrayIterator($mocksSplFileInfo); }; $this - ->given($FileAdapter) - ->array($FileAdapter->listQueues()) + ->given($fileAdapter) + ->array($fileAdapter->listQueues()) ->containsValues(['testOneQueue', 'testTwoQueue', 'testThreeQueue']); } @@ -568,7 +568,7 @@ public function testFileAdapterListQueuesWithPrefix() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { $files = []; $priorities = $priorityHandler->getAll(); @@ -589,8 +589,8 @@ public function testFileAdapterListQueuesWithPrefix() return new ArrayIterator($mocksSplFileInfo); }; $this - ->given($FileAdapter) - ->array($FileAdapter->listQueues('prefix')) + ->given($fileAdapter) + ->array($fileAdapter->listQueues('prefix')) ->containsValues(['prefixTestOneQueue', 'prefixTestTwoQueue']); } @@ -600,13 +600,13 @@ public function testFileAdapterListQueuesWithEmptyQueue() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFinder->getMockController()->getIterator = function () { return new ArrayIterator([]); }; $this - ->given($FileAdapter) - ->array($FileAdapter->listQueues()) + ->given($fileAdapter) + ->array($fileAdapter->listQueues()) ->isEmpty(); } @@ -690,9 +690,9 @@ public function testFileAdapterAddMessageWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->addMessage('', ''); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->addMessage('', ''); }); } @@ -703,9 +703,9 @@ public function testFileAdapterAddMessageWithNoQueueFile() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->addMessage('testQueue', ''); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->addMessage('testQueue', ''); }); } @@ -721,9 +721,9 @@ public function testFileAdapterAddMessageWithEmptyMessage() $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->addMessage('testQueue', ''); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->addMessage('testQueue', ''); }); } @@ -732,15 +732,15 @@ public function testFileAdapterAddMessageLockFailed() { $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->addMessage('testQueue', 'test message'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->addMessage('testQueue', 'test message'); }); } @@ -750,7 +750,7 @@ public function testFileAdapterAddMessageWithEmptyQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -775,8 +775,8 @@ public function testFileAdapterAddMessageWithEmptyQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->addMessage('testQueue', 'test message'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->addMessage('testQueue', 'test message'); }); } @@ -786,7 +786,7 @@ public function testFileAdapterAddMessageWithBadQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -811,8 +811,8 @@ public function testFileAdapterAddMessageWithBadQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->addMessage('testQueue', 'test message'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->addMessage('testQueue', 'test message'); }); } @@ -822,9 +822,9 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->getNumberMessages(''); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getNumberMessages(''); }); } @@ -835,9 +835,9 @@ public function testFileAdapterGetNumberMessagesWithNoQueueFile() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->getNumberMessages('testQueue'); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getNumberMessages('testQueue'); }); } @@ -846,15 +846,15 @@ public function testFileAdapterGetNumberMessagesLockFailed() { $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->getNumberMessages('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getNumberMessages('testQueue'); }); } @@ -864,7 +864,7 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -889,8 +889,8 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->getNumberMessages('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getNumberMessages('testQueue'); }); } @@ -900,7 +900,7 @@ public function testFileAdapterGetNumberMessagesWithBadQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -925,8 +925,8 @@ public function testFileAdapterGetNumberMessagesWithBadQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->getNumberMessages('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getNumberMessages('testQueue'); }); } @@ -936,7 +936,7 @@ public function testFileAdapterGetNumberMessages() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -961,8 +961,8 @@ public function testFileAdapterGetNumberMessages() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->given($FileAdapter) - ->integer($FileAdapter->getNumberMessages('testQueue'))->isEqualTo(6); + $this->given($fileAdapter) + ->integer($fileAdapter->getNumberMessages('testQueue'))->isEqualTo(6); } public function testFileAdapterGetMessagesWithEmptyQueueName() @@ -971,9 +971,9 @@ public function testFileAdapterGetMessagesWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->getMessages('', 1); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getMessages('', 1); }); } @@ -984,9 +984,9 @@ public function testFileAdapterGetMessagesWithNoQueueFile() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->getMessages('testQueue', 1); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getMessages('testQueue', 1); }); } @@ -1002,9 +1002,9 @@ public function testFileAdapterAddMessagesWithNoNumericNbrMsg() $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->getMessages('testQueue', 'toto'); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getMessages('testQueue', 'toto'); }); } @@ -1020,12 +1020,12 @@ public function testFileAdapterGetMessagesWithNotValidNumericNbrMsg() $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->getMessages('testQueue', -5); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getMessages('testQueue', -5); }); - $this->exception(function() use($FileAdapter) { - $FileAdapter->getMessages('testQueue', (\ReputationVIP\QueueClient\Adapter\FileAdapter::MAX_NB_MESSAGES + 1)); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getMessages('testQueue', (\ReputationVIP\QueueClient\Adapter\FileAdapter::MAX_NB_MESSAGES + 1)); }); } @@ -1034,15 +1034,15 @@ public function testFileAdapterGetMessagesLockFailed() { $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->getMessages('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getMessages('testQueue'); }); } @@ -1052,7 +1052,7 @@ public function testFileAdapterGetMessagesWithEmptyQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -1077,8 +1077,8 @@ public function testFileAdapterGetMessagesWithEmptyQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->getMessages('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getMessages('testQueue'); }); } @@ -1088,7 +1088,7 @@ public function testFileAdapterGetMessagesWithBadQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -1113,8 +1113,8 @@ public function testFileAdapterGetMessagesWithBadQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter) { - $FileAdapter->getMessages('testQueue'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->getMessages('testQueue'); }); } @@ -1124,7 +1124,7 @@ public function testFileAdapterGetMessages() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -1149,10 +1149,10 @@ public function testFileAdapterGetMessages() { } return new ArrayIterator($mocksSplFileInfo); }; - $this->given($FileAdapter) - ->array($FileAdapter->GetMessages('testQueue', 6)); - $this->given($FileAdapter) - ->array($FileAdapter->GetMessages('testQueue', 8)); + $this->given($fileAdapter) + ->array($fileAdapter->getMessages('testQueue', 6)); + $this->given($fileAdapter) + ->array($fileAdapter->getMessages('testQueue', 8)); } public function testFileAdapterDeleteMessageWithEmptyQueueName() @@ -1161,9 +1161,9 @@ public function testFileAdapterDeleteMessageWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->deleteMessage('', []); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->deleteMessage('', []); }); } @@ -1174,10 +1174,10 @@ public function testFileAdapterDeleteMessageWithNoQueueFile() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; - $this->exception(function() use($FileAdapter, $priorityHandler) { - $FileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); + $this->exception(function() use($fileAdapter, $priorityHandler) { + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); }); } @@ -1187,10 +1187,10 @@ public function testFileAdapterDeleteMessageWithNoMessage() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; - $this->exception(function() use($FileAdapter) { - $FileAdapter->deleteMessage('testQueue', []); + $this->exception(function() use($fileAdapter) { + $fileAdapter->deleteMessage('testQueue', []); }); } @@ -1214,10 +1214,10 @@ public function testFileAdapterDeleteMessageWithNotPriorityField() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; - $this->exception(function() use($FileAdapter) { - $FileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915']); + $this->exception(function() use($fileAdapter) { + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915']); }); } @@ -1227,10 +1227,10 @@ public function testFileAdapterDeleteMessageWithBadMessageType() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; - $this->exception(function() use($FileAdapter) { - $FileAdapter->deleteMessage('testQueue', 'message'); + $this->exception(function() use($fileAdapter) { + $fileAdapter->deleteMessage('testQueue', 'message'); }); } @@ -1241,15 +1241,15 @@ public function testFileAdapterDeleteMessageLockFailed() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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 = false; return $mockLockHandler; }; - $this->exception(function() use($FileAdapter, $priorityHandler) { - $FileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); + $this->exception(function() use($fileAdapter, $priorityHandler) { + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); }); } @@ -1260,7 +1260,7 @@ public function testFileAdapterDeleteMessageWithEmptyQueueContent() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -1285,8 +1285,8 @@ public function testFileAdapterDeleteMessageWithEmptyQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter, $priorityHandler) { - $FileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); + $this->exception(function() use($fileAdapter, $priorityHandler) { + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); }); } @@ -1297,7 +1297,7 @@ public function testFileAdapterDeleteMessageWithBadQueueContent() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -1322,8 +1322,8 @@ public function testFileAdapterDeleteMessageWithBadQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($FileAdapter, $priorityHandler) { - $FileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); + $this->exception(function() use($fileAdapter, $priorityHandler) { + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); }); } @@ -1334,7 +1334,7 @@ public function testFileAdapterDeleteMessage() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -1359,8 +1359,8 @@ public function testFileAdapterDeleteMessage() } return new ArrayIterator($mocksSplFileInfo); }; - $this->given($FileAdapter) - ->class($FileAdapter->deleteMessage('testQueue', array('id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest())))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($fileAdapter) + ->class($fileAdapter->deleteMessage('testQueue', array('id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest())))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testFileAdapterRenameQueueWithEmptyParameter() @@ -1369,12 +1369,12 @@ public function testFileAdapterRenameQueueWithEmptyParameter() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { - $FileAdapter->renameQueue('', 'newTestQueue'); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter) { + $fileAdapter->renameQueue('', 'newTestQueue'); }); - $this->exception(function() use($FileAdapter) { - $FileAdapter->renameQueue('testQueue', ''); + $this->exception(function() use($fileAdapter) { + $fileAdapter->renameQueue('testQueue', ''); }); } @@ -1385,7 +1385,7 @@ public function testFileAdapterRenameQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = function ($queue) { static $i = 0; if ($i < 3) { @@ -1417,8 +1417,8 @@ public function testFileAdapterRenameQueue() } return new ArrayIterator($mocksSplFileInfo); }; - $this->given($FileAdapter) - ->class($FileAdapter->renameQueue('testQueue', 'newTestQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($fileAdapter) + ->class($fileAdapter->renameQueue('testQueue', 'newTestQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testFileAdapterGetPriorityHandler() @@ -1427,8 +1427,8 @@ public function testFileAdapterGetPriorityHandler() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->given($FileAdapter) - ->class($FileAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->given($fileAdapter) + ->class($fileAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); } } diff --git a/tests/units/Adapter/MemoryAdapter.php b/tests/units/Adapter/MemoryAdapter.php index c6caa01..1355aa9 100644 --- a/tests/units/Adapter/MemoryAdapter.php +++ b/tests/units/Adapter/MemoryAdapter.php @@ -16,19 +16,19 @@ public function testMemoryAdapterCreateQueue() public function testMemoryAdapterCreateQueueWithEmptyQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->createQueue(''); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->createQueue(''); }); } public function testMemoryAdapterCreateQueueWithQueueNameSpace() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->createQueue('test Queue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->createQueue('test Queue'); }); } @@ -78,97 +78,97 @@ public function testMemoryAdapterDeleteQueueWithQueueDoesNotExists() public function testMemoryAdapterRenameQueue() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->given($MemoryAdapter) - ->class($MemoryAdapter->renameQueue('testQueue', 'newTestQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $memoryAdapter->createQueue('testQueue'); + $this->given($memoryAdapter) + ->class($memoryAdapter->renameQueue('testQueue', 'newTestQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testMemoryAdapterRenameQueueWithEmptyTargetQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->renameQueue('testQueue', ''); + $memoryAdapter->createQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->renameQueue('testQueue', ''); }); } public function testMemoryAdapterRenameQueueWithTargetQueueExists() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter->createQueue('newTestQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->renameQueue('testQueue', 'newTestQueue'); + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter->createQueue('newTestQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->renameQueue('testQueue', 'newTestQueue'); }); } public function testMemoryAdapterRenameQueueWithEmptySourceQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->renameQueue('', 'newTestQueue'); + $memoryAdapter->createQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->renameQueue('', 'newTestQueue'); }); } public function testMemoryAdapterRenameQueueWithSourceQueueDoesNotExists() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->renameQueue('testQueue', 'newTestQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->renameQueue('testQueue', 'newTestQueue'); }); } public function testMemoryAdapterPurgeQueue() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->given($MemoryAdapter) - ->class($MemoryAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $memoryAdapter->createQueue('testQueue'); + $this->given($memoryAdapter) + ->class($memoryAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testMemoryAdapterPurgeQueueWithEmptyQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->purgeQueue(''); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->purgeQueue(''); }); } public function testMemoryAdapterPurgeQueueWithQueueDoesNotExists() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->purgeQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->purgeQueue('testQueue'); }); } public function testMemoryAdapterPurgeQueueWithBadPriority() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->purgeQueue('testQueue', 'BAD_PRIORITY'); + $memoryAdapter->createQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->purgeQueue('testQueue', 'BAD_PRIORITY'); }); } public function testMemoryAdapterAddMessage() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->given($MemoryAdapter) - ->class($MemoryAdapter->AddMessage('testQueue', 'test message'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $memoryAdapter->createQueue('testQueue'); + $this->given($memoryAdapter) + ->class($memoryAdapter->addMessage('testQueue', 'test message'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testMemoryAdapterAddMessageWithDelay() @@ -184,80 +184,80 @@ public function testMemoryAdapterAddMessageWithDelay() public function testMemoryAdapterAddMessageWithEmptyQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->AddMessage('', 'test message'); + $memoryAdapter->createQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->addMessage('', 'test message'); }); } public function testMemoryAdapterAddMessageWithNoQueue() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->AddMessage('testQueue', 'test message'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->addMessage('testQueue', 'test message'); }); } public function testMemoryAdapterAddMessageWithEmptyMessage() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->AddMessage('testQueue', ''); + $memoryAdapter->createQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->addMessage('testQueue', ''); }); } public function testMemoryAdapterAddMessageWithBadPriority() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->AddMessage('testQueue', 'test message', 'BAD_PRIORITY'); + $memoryAdapter->createQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->addMessage('testQueue', 'test message', 'BAD_PRIORITY'); }); } public function testMemoryAdapterIsEmpty() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->given($MemoryAdapter) - ->boolean($MemoryAdapter->isEmpty('testQueue'))->isTrue(); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $this->given($MemoryAdapter) - ->boolean($MemoryAdapter->isEmpty('testQueue'))->isFalse(); + $memoryAdapter->createQueue('testQueue'); + $this->given($memoryAdapter) + ->boolean($memoryAdapter->isEmpty('testQueue'))->isTrue(); + $memoryAdapter->addMessage('testQueue', 'test message'); + $this->given($memoryAdapter) + ->boolean($memoryAdapter->isEmpty('testQueue'))->isFalse(); } public function testMemoryAdapterIsEmptyWithEmptyQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->isEmpty(''); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->isEmpty(''); }); } public function testMemoryAdapterIsEmptyWithQueueDoesNotExists() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->isEmpty('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->isEmpty('testQueue'); }); } public function testMemoryAdapterIsEmptyWithBadPriority() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->isEmpty('testQueue', 'BAD_PRIORITY'); + $memoryAdapter->createQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->isEmpty('testQueue', 'BAD_PRIORITY'); }); } @@ -266,21 +266,21 @@ public function testMemoryAdapterIsEmptyWithBadPriority() */ public function testMemoryAdapterListQueues() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueueOne'); - $MemoryAdapter->createQueue('testQueueTwo'); - $MemoryAdapter->createQueue('testQueueThree'); - $this->given($MemoryAdapter) - ->array($MemoryAdapter->listQueues())->containsValues(['testQueueOne', 'testQueueTwo', 'testQueueThree']); + $memoryAdapter->createQueue('testQueueOne'); + $memoryAdapter->createQueue('testQueueTwo'); + $memoryAdapter->createQueue('testQueueThree'); + $this->given($memoryAdapter) + ->array($memoryAdapter->listQueues())->containsValues(['testQueueOne', 'testQueueTwo', 'testQueueThree']); } public function testMemoryAdapterListQueuesEmpty() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->given($MemoryAdapter) - ->array($MemoryAdapter->listQueues())->isEmpty(); + $this->given($memoryAdapter) + ->array($memoryAdapter->listQueues())->isEmpty(); } /** @@ -288,201 +288,201 @@ public function testMemoryAdapterListQueuesEmpty() */ public function testMemoryAdapterListQueuesWithPrefix() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueueOne'); - $MemoryAdapter->createQueue('prefixTestQueueOne'); - $MemoryAdapter->createQueue('testQueueTwo'); - $MemoryAdapter->createQueue('prefixTestQueueTwo'); - $MemoryAdapter->createQueue('testQueueThree'); - $this->given($MemoryAdapter) - ->array($MemoryAdapter->listQueues('prefix'))->containsValues(['prefixTestQueueOne', 'prefixTestQueueTwo']); + $memoryAdapter->createQueue('testQueueOne'); + $memoryAdapter->createQueue('prefixTestQueueOne'); + $memoryAdapter->createQueue('testQueueTwo'); + $memoryAdapter->createQueue('prefixTestQueueTwo'); + $memoryAdapter->createQueue('testQueueThree'); + $this->given($memoryAdapter) + ->array($memoryAdapter->listQueues('prefix'))->containsValues(['prefixTestQueueOne', 'prefixTestQueueTwo']); } public function testMemoryAdapterGetNumberMessagesWithEmptyQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->getNumberMessages(''); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->getNumberMessages(''); }); } public function testMemoryAdapterGetNumberMessagesWithQueueDoesNotExists() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->getNumberMessages('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->getNumberMessages('testQueue'); }); } public function testMemoryAdapterGetNumberMessagesWithBadPriority() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->getNumberMessages('testQueue', 'BAD_PRIORITY'); + $memoryAdapter->createQueue('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->getNumberMessages('testQueue', 'BAD_PRIORITY'); }); } public function testMemoryAdapterGetNumberMessages() { $priorityHandler = new ThreeLevelPriorityHandler(); - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter($priorityHandler); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter($priorityHandler); - $MemoryAdapter->createQueue('testQueue'); - $this->given($MemoryAdapter) - ->integer($MemoryAdapter->getNumberMessages('testQueue'))->isEqualTo(0); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $MemoryAdapter->addMessage('testQueue', 'test message high one', $priorityHandler->getHighest()); - $MemoryAdapter->addMessage('testQueue', 'test message high two', $priorityHandler->getHighest()); - $MemoryAdapter->addMessage('testQueue', 'test message low', $priorityHandler->getLowest()); - $this->given($MemoryAdapter) - ->integer($MemoryAdapter->getNumberMessages('testQueue'))->isEqualTo(4); + $memoryAdapter->createQueue('testQueue'); + $this->given($memoryAdapter) + ->integer($memoryAdapter->getNumberMessages('testQueue'))->isEqualTo(0); + $memoryAdapter->addMessage('testQueue', 'test message'); + $memoryAdapter->addMessage('testQueue', 'test message high one', $priorityHandler->getHighest()); + $memoryAdapter->addMessage('testQueue', 'test message high two', $priorityHandler->getHighest()); + $memoryAdapter->addMessage('testQueue', 'test message low', $priorityHandler->getLowest()); + $this->given($memoryAdapter) + ->integer($memoryAdapter->getNumberMessages('testQueue'))->isEqualTo(4); } public function testMemoryAdapterDeleteMessageWithEmptyQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->deleteMessage('', []); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->deleteMessage('', []); }); } public function testMemoryAdapterDeleteMessageWithEmptyMessage() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->deleteMessage('testQueue', []); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->deleteMessage('testQueue', []); }); } public function testMemoryAdapterDeleteMessageWithNoMessageId() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $message = $MemoryAdapter->getMessages('testQueue'); + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter->addMessage('testQueue', 'test message'); + $message = $memoryAdapter->getMessages('testQueue'); $message = $message[0]; unset($message['id']); - $this->exception(function() use($MemoryAdapter, $message) { - $MemoryAdapter->deleteMessage('testQueue', $message); + $this->exception(function() use($memoryAdapter, $message) { + $memoryAdapter->deleteMessage('testQueue', $message); }); } public function testMemoryAdapterDeleteMessageWithNoMessagePriority() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $message = $MemoryAdapter->getMessages('testQueue'); + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter->addMessage('testQueue', 'test message'); + $message = $memoryAdapter->getMessages('testQueue'); $message = $message[0]; unset($message['priority']); - $this->exception(function() use($MemoryAdapter, $message) { - $MemoryAdapter->deleteMessage('testQueue', $message); + $this->exception(function() use($memoryAdapter, $message) { + $memoryAdapter->deleteMessage('testQueue', $message); }); } public function testMemoryAdapterDeleteMessageWithBadMessage() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter->addMessage('testQueue', 'test message'); + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter->addMessage('testQueue', 'test message'); $message = 'test message'; - $this->exception(function() use($MemoryAdapter, $message) { - $MemoryAdapter->deleteMessage('testQueue', $message); + $this->exception(function() use($memoryAdapter, $message) { + $memoryAdapter->deleteMessage('testQueue', $message); }); } public function testMemoryAdapterDeleteMessageWithBadPriority() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $message = $MemoryAdapter->getMessages('testQueue'); + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter->addMessage('testQueue', 'test message'); + $message = $memoryAdapter->getMessages('testQueue'); $message = $message[0]; $message['priority'] = 'BAD_PRIORITY'; - $this->exception(function() use($MemoryAdapter, $message) { - $MemoryAdapter->deleteMessage('testQueue', $message); + $this->exception(function() use($memoryAdapter, $message) { + $memoryAdapter->deleteMessage('testQueue', $message); }); } public function testMemoryAdapterDeleteMessage() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $message = $MemoryAdapter->getMessages('testQueue'); + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter->addMessage('testQueue', 'test message'); + $message = $memoryAdapter->getMessages('testQueue'); $message = $message[0]; - $this->given($MemoryAdapter) - ->class($MemoryAdapter->deleteMessage('testQueue', $message))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($memoryAdapter) + ->class($memoryAdapter->deleteMessage('testQueue', $message))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testMemoryAdapterGetMessagesWithEmptyQueueName() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->getMessages(''); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->getMessages(''); }); } public function testMemoryAdapterGetMessagesWithQueueDoesNotExists() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->getMessages('testQueue'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->getMessages('testQueue'); }); } public function testMemoryAdapterGetMessagesWithBadPriority() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $this->exception(function() use($MemoryAdapter) { - $MemoryAdapter->getMessages('testQueue', 1, 'BAD_PRIORITY'); + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter->addMessage('testQueue', 'test message'); + $this->exception(function() use($memoryAdapter) { + $memoryAdapter->getMessages('testQueue', 1, 'BAD_PRIORITY'); }); } public function testMemoryAdapterGetMessages() { $priorityHandler = new ThreeLevelPriorityHandler(); - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter($priorityHandler); - - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $MemoryAdapter->addMessage('testQueue', 'test message high one', $priorityHandler->getHighest()); - $MemoryAdapter->addMessage('testQueue', 'test message high two', $priorityHandler->getHighest()); - $MemoryAdapter->addMessage('testQueue', 'test message low', $priorityHandler->getLowest()); - $this->given($MemoryAdapter) - ->array($MemoryAdapter->getMessages('testQueue', 4))->hasSize(4); - $MemoryAdapter->purgeQueue('testQueue'); - $MemoryAdapter->addMessage('testQueue', 'test message'); - $MemoryAdapter->addMessage('testQueue', 'test message high one', $priorityHandler->getHighest()); - $MemoryAdapter->addMessage('testQueue', 'test message high two', $priorityHandler->getHighest()); - $MemoryAdapter->addMessage('testQueue', 'test message low', $priorityHandler->getLowest()); - $this->given($MemoryAdapter) - ->array($MemoryAdapter->getMessages('testQueue', 6))->hasSize(4); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter($priorityHandler); + + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter->addMessage('testQueue', 'test message'); + $memoryAdapter->addMessage('testQueue', 'test message high one', $priorityHandler->getHighest()); + $memoryAdapter->addMessage('testQueue', 'test message high two', $priorityHandler->getHighest()); + $memoryAdapter->addMessage('testQueue', 'test message low', $priorityHandler->getLowest()); + $this->given($memoryAdapter) + ->array($memoryAdapter->getMessages('testQueue', 4))->hasSize(4); + $memoryAdapter->purgeQueue('testQueue'); + $memoryAdapter->addMessage('testQueue', 'test message'); + $memoryAdapter->addMessage('testQueue', 'test message high one', $priorityHandler->getHighest()); + $memoryAdapter->addMessage('testQueue', 'test message high two', $priorityHandler->getHighest()); + $memoryAdapter->addMessage('testQueue', 'test message low', $priorityHandler->getLowest()); + $this->given($memoryAdapter) + ->array($memoryAdapter->getMessages('testQueue', 6))->hasSize(4); } public function testMemoryAdapterGetPriorityHandler() { $priorityHandler = new ThreeLevelPriorityHandler(); - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter($priorityHandler); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter($priorityHandler); - $this->given($MemoryAdapter) - ->class($MemoryAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $this->given($memoryAdapter) + ->class($memoryAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); } } diff --git a/tests/units/Adapter/NullAdapter.php b/tests/units/Adapter/NullAdapter.php index 20d7070..29d5ac2 100644 --- a/tests/units/Adapter/NullAdapter.php +++ b/tests/units/Adapter/NullAdapter.php @@ -9,73 +9,73 @@ class NullAdapter extends atoum\test public function testNullAdapterAddMessage() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->class($NullAdapter->addMessage('testQueue', 'test Message one'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->class($nullAdapter->addMessage('testQueue', 'test Message one'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testNullAdapterAddMessages() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->class($NullAdapter->addMessages('testQueue', ['test Message one']))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->class($nullAdapter->addMessages('testQueue', ['test Message one']))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testNullAdapterGetMessages() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->array($NullAdapter->getMessages('testQueue'))->isEmpty(); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->array($nullAdapter->getMessages('testQueue'))->isEmpty(); } public function testNullAdapterDeleteMessage() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->class($NullAdapter->deleteMessage('testQueue', []))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->class($nullAdapter->deleteMessage('testQueue', []))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testNullAdapterIsEmpty() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->boolean($NullAdapter->isEmpty('testQueue'))->isTrue(); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->boolean($nullAdapter->isEmpty('testQueue'))->isTrue(); } public function testNullAdapterGetNumberMessages() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->integer($NullAdapter->getNumberMessages('testQueue'))->isEqualTo(0); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->integer($nullAdapter->getNumberMessages('testQueue'))->isEqualTo(0); } public function testNullAdapterDeleteQueue() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->class($NullAdapter->deleteQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->class($nullAdapter->deleteQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testNullAdapterCreateQueue() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->class($NullAdapter->createQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->class($nullAdapter->createQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testNullAdapterRenameQueue() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->class($NullAdapter->renameQueue('testQueue', 'newTestQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->class($nullAdapter->renameQueue('testQueue', 'newTestQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testNullAdapterPurgeQueue() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->class($NullAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->class($nullAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testNullAdapterListQueues() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->array($NullAdapter->listQueues())->isEmpty(); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->array($nullAdapter->listQueues())->isEmpty(); } public function testNullAdapterGetPriorityHandler() { - $NullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); - $this->given($NullAdapter)->class($NullAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $nullAdapter = new \ReputationVIP\QueueClient\Adapter\NullAdapter(); + $this->given($nullAdapter)->class($nullAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); } } diff --git a/tests/units/Adapter/SQSAdapter.php b/tests/units/Adapter/SQSAdapter.php index 569224d..9ae14a4 100644 --- a/tests/units/Adapter/SQSAdapter.php +++ b/tests/units/Adapter/SQSAdapter.php @@ -12,10 +12,10 @@ public function testSQSAdapterAddMessageWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->addMessage('', ''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->addMessage('', ''); }); } @@ -24,10 +24,10 @@ public function testSQSAdapterAddMessageWithEmptyMessage() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->addMessage('testQueue', ''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->addMessage('testQueue', ''); }); } @@ -37,15 +37,15 @@ public function testSQSAdapterAddMessage() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; }; $mockSqsClient->getMockController()->sendMessage = function () { }; - $this->given($SQSAdapter) - ->class($SQSAdapter->addMessage('testQueue', 'test message'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($sqsAdapter) + ->class($sqsAdapter->addMessage('testQueue', 'test message'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testSQSAdapterAddMessages() @@ -54,15 +54,15 @@ public function testSQSAdapterAddMessages() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; }; $mockSqsClient->getMockController()->sendMessageBatch = function () { }; - $this->given($SQSAdapter) - ->class($SQSAdapter->addMessages('testQueue', array_fill(0, 11, 'test message')))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($sqsAdapter) + ->class($sqsAdapter->addMessages('testQueue', array_fill(0, 11, 'test message')))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testSQSAdapterAddMessagesWithEmptyMessage() @@ -70,10 +70,10 @@ public function testSQSAdapterAddMessagesWithEmptyMessage() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->addMessages('testQueue', ['test message', '']); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->addMessages('testQueue', ['test message', '']); }); } @@ -82,10 +82,10 @@ public function testSQSAdapterAddMessagesWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->addMessages('', ['']); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->addMessages('', ['']); }); } @@ -94,10 +94,10 @@ public function testSQSAdapterGetMessagesWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->getMessages(''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->getMessages(''); }); } @@ -106,18 +106,18 @@ public function testSQSAdapterGetMessagesWithBadMessageNumber() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->getMessages('testQueue', 'BadNumber'); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->getMessages('testQueue', 'BadNumber'); }); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->getMessages('testQueue', 0); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->getMessages('testQueue', 0); }); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->getMessages('testQueue', \ReputationVIP\QueueClient\Adapter\SQSAdapter::MAX_NB_MESSAGES + 1); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->getMessages('testQueue', \ReputationVIP\QueueClient\Adapter\SQSAdapter::MAX_NB_MESSAGES + 1); }); } @@ -127,7 +127,7 @@ public function testSQSAdapterGetMessagesWithNoMessage() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -138,8 +138,8 @@ public function testSQSAdapterGetMessagesWithNoMessage() $mockSqsClient->getMockController()->receiveMessage = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->array($SQSAdapter->getMessages('testQueue', 5))->isEmpty(); + $this->given($sqsAdapter) + ->array($sqsAdapter->getMessages('testQueue', 5))->isEmpty(); } public function testSQSAdapterGetMessages() @@ -149,7 +149,7 @@ public function testSQSAdapterGetMessages() $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; $priorityHandler = new ThreeLevelPriorityHandler(); - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -160,8 +160,8 @@ public function testSQSAdapterGetMessages() $mockSqsClient->getMockController()->receiveMessage = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->array($SQSAdapter->getMessages('testQueue', 6))->hasSize(6); + $this->given($sqsAdapter) + ->array($sqsAdapter->getMessages('testQueue', 6))->hasSize(6); } public function testSQSAdapterDeleteMessageWithEmptyQueueName() @@ -169,10 +169,10 @@ public function testSQSAdapterDeleteMessageWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->deleteMessage('', []); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->deleteMessage('', []); }); } @@ -181,10 +181,10 @@ public function testSQSAdapterDeleteMessageWithEmptyMessage() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->deleteMessage('testQueue', []); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->deleteMessage('testQueue', []); }); } @@ -193,10 +193,10 @@ public function testSQSAdapterDeleteMessageWithBadMessage() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->deleteMessage('testQueue', 'Bad message'); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->deleteMessage('testQueue', 'Bad message'); }); } @@ -206,10 +206,10 @@ public function testSQSAdapterDeleteMessageWithNoMessageReceiptHandle() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $priorityHandler = new ThreeLevelPriorityHandler(); - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); - $this->exception(function() use($SQSAdapter, $priorityHandler) { - $SQSAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest()]); + $this->exception(function() use($sqsAdapter, $priorityHandler) { + $sqsAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest()]); }); } @@ -218,10 +218,10 @@ public function testSQSAdapterDeleteMessageWithNoMessagePriority() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->deleteMessage('testQueue', ['ReceiptHandle' => 'testReceiptHandle']); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->deleteMessage('testQueue', ['ReceiptHandle' => 'testReceiptHandle']); }); } @@ -232,7 +232,7 @@ public function testSQSAdapterDeleteMessage() $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; $priorityHandler = new ThreeLevelPriorityHandler(); - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -243,8 +243,8 @@ public function testSQSAdapterDeleteMessage() $mockSqsClient->getMockController()->deleteMessage = function () use($mockQueueUrlModel) { return null; }; - $this->given($SQSAdapter) - ->class($SQSAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest(), 'ReceiptHandle' => 'testReceiptHandle']))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($sqsAdapter) + ->class($sqsAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest(), 'ReceiptHandle' => 'testReceiptHandle']))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testSQSAdapterIsEmptyWithEmptyQueueName() @@ -252,10 +252,10 @@ public function testSQSAdapterIsEmptyWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->isEmpty(''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->isEmpty(''); }); } @@ -265,7 +265,7 @@ public function testSQSAdapterIsEmptyWithEmptyQueue() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -277,8 +277,8 @@ public function testSQSAdapterIsEmptyWithEmptyQueue() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->boolean($SQSAdapter->isEmpty('testQueue'))->IsTrue(); + $this->given($sqsAdapter) + ->boolean($sqsAdapter->isEmpty('testQueue'))->IsTrue(); } public function testSQSAdapterIsEmpty() @@ -287,7 +287,7 @@ public function testSQSAdapterIsEmpty() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -299,8 +299,8 @@ public function testSQSAdapterIsEmpty() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->boolean($SQSAdapter->isEmpty('testQueue'))->IsFalse(); + $this->given($sqsAdapter) + ->boolean($sqsAdapter->isEmpty('testQueue'))->IsFalse(); } public function testSQSAdapterGetNumberMessagesWithEmptyQueueName() @@ -308,10 +308,10 @@ public function testSQSAdapterGetNumberMessagesWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->getNumberMessages(''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->getNumberMessages(''); }); } @@ -321,7 +321,7 @@ public function testSQSAdapterGetNumberMessagesWithEmptyQueue() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -333,8 +333,8 @@ public function testSQSAdapterGetNumberMessagesWithEmptyQueue() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->integer($SQSAdapter->getNumberMessages('testQueue'))->IsEqualTo(0); + $this->given($sqsAdapter) + ->integer($sqsAdapter->getNumberMessages('testQueue'))->IsEqualTo(0); } public function testSQSAdapterGetNumberMessages() @@ -344,7 +344,7 @@ public function testSQSAdapterGetNumberMessages() $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; $priorityHandler =new ThreeLevelPriorityHandler(); - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -356,8 +356,8 @@ public function testSQSAdapterGetNumberMessages() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->integer($SQSAdapter->getNumberMessages('testQueue'))->IsEqualTo(18); + $this->given($sqsAdapter) + ->integer($sqsAdapter->getNumberMessages('testQueue'))->IsEqualTo(18); } public function testSQSAdapterDeleteQueueWithEmptyQueueName() @@ -365,10 +365,10 @@ public function testSQSAdapterDeleteQueueWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->deleteQueue(''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->deleteQueue(''); }); } @@ -378,7 +378,7 @@ public function testSQSAdapterDeleteQueue() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -390,8 +390,8 @@ public function testSQSAdapterDeleteQueue() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->class($SQSAdapter->deleteQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($sqsAdapter) + ->class($sqsAdapter->deleteQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testSQSAdapterCreateQueueWithEmptyQueueName() @@ -399,10 +399,10 @@ public function testSQSAdapterCreateQueueWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->createQueue(''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->createQueue(''); }); } @@ -412,7 +412,7 @@ public function testSQSAdapterCreateQueue() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -424,8 +424,8 @@ public function testSQSAdapterCreateQueue() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->class($SQSAdapter->createQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($sqsAdapter) + ->class($sqsAdapter->createQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testSQSAdapterPurgeQueueWithEmptyQueueName() @@ -433,10 +433,10 @@ public function testSQSAdapterPurgeQueueWithEmptyQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->purgeQueue(''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->purgeQueue(''); }); } @@ -446,7 +446,7 @@ public function testSQSAdapterPurgeQueue() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -458,8 +458,8 @@ public function testSQSAdapterPurgeQueue() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->class($SQSAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($sqsAdapter) + ->class($sqsAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testSQSAdapterListQueuesWithPrefix() @@ -469,7 +469,7 @@ public function testSQSAdapterListQueuesWithPrefix() $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; $priorityHandler = new ThreeLevelPriorityHandler(); - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -481,8 +481,8 @@ public function testSQSAdapterListQueuesWithPrefix() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->array($SQSAdapter->listQueues('prefix'))->containsValues(['prefixTestQueueOne', 'prefixTestQueueTwo']); + $this->given($sqsAdapter) + ->array($sqsAdapter->listQueues('prefix'))->containsValues(['prefixTestQueueOne', 'prefixTestQueueTwo']); } public function testSQSAdapterListQueues() @@ -492,7 +492,7 @@ public function testSQSAdapterListQueues() $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; $priorityHandler = new ThreeLevelPriorityHandler(); - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -504,8 +504,8 @@ public function testSQSAdapterListQueues() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->array($SQSAdapter->listQueues())->containsValues(['testQueueOne', 'prefixTestQueueOne', 'prefixTestQueueTwo']); + $this->given($sqsAdapter) + ->array($sqsAdapter->listQueues())->containsValues(['testQueueOne', 'prefixTestQueueOne', 'prefixTestQueueTwo']); } public function testSQSAdapterRenameQueueWithEmptySourceQueueName() @@ -513,10 +513,10 @@ public function testSQSAdapterRenameQueueWithEmptySourceQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->renameQueue('', 'targetQueue'); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->renameQueue('', 'targetQueue'); }); } @@ -525,10 +525,10 @@ public function testSQSAdapterRenameQueueWithEmptyTargetQueueName() $this->mockGenerator->orphanize('__construct'); $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); - $this->exception(function() use($SQSAdapter) { - $SQSAdapter->renameQueue('sourceQueue', ''); + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->renameQueue('sourceQueue', ''); }); } @@ -539,7 +539,7 @@ public function testSQSAdapterRenameQueue() $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; $priorityHandler = new ThreeLevelPriorityHandler(); - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -574,8 +574,8 @@ public function testSQSAdapterRenameQueue() }; $mockSqsClient->getMockController()->deleteQueue = function () use($mockQueueUrlModel) { }; - $this->given($SQSAdapter) - ->class($SQSAdapter->renameQueue('sourceQueue', 'targetQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($sqsAdapter) + ->class($sqsAdapter->renameQueue('sourceQueue', 'targetQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testSQSAdapterGetPrioritiesHandler() @@ -584,7 +584,7 @@ public function testSQSAdapterGetPrioritiesHandler() $this->mockGenerator->shuntParentClassCalls(); $mockSqsClient = new \mock\Aws\Sqs\SqsClient; $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; - $SQSAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { return $mockQueueUrlModel; @@ -596,7 +596,7 @@ public function testSQSAdapterGetPrioritiesHandler() return $mockQueueUrlModel; }; - $this->given($SQSAdapter) - ->class($SQSAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $this->given($sqsAdapter) + ->class($sqsAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); } } From 9f13af0a64e5fda14271d2d6e0698c7b83560dc5 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Mon, 14 Mar 2016 09:34:07 +0100 Subject: [PATCH 09/51] Clean variable case after rebase --- tests/units/Adapter/FileAdapter.php | 8 ++++---- tests/units/Adapter/MemoryAdapter.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index d071485..a8abc21 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -653,7 +653,7 @@ public function testFileAdapterAddMessageWithDelay() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $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); @@ -678,10 +678,10 @@ public function testFileAdapterAddMessageWithDelay() } return new ArrayIterator($mocksSplFileInfo); }; - $FileAdapter = $FileAdapter->addMessage('testQueue', 'test Message one', null, 1); + $fileAdapter = $fileAdapter->addMessage('testQueue', 'test Message one', null, 1); sleep(1); - $this->given($FileAdapter) - ->class($FileAdapter)->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($fileAdapter) + ->class($fileAdapter)->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testFileAdapterAddMessageWithEmptyQueueName() diff --git a/tests/units/Adapter/MemoryAdapter.php b/tests/units/Adapter/MemoryAdapter.php index 1355aa9..e184717 100644 --- a/tests/units/Adapter/MemoryAdapter.php +++ b/tests/units/Adapter/MemoryAdapter.php @@ -173,13 +173,13 @@ public function testMemoryAdapterAddMessage() public function testMemoryAdapterAddMessageWithDelay() { - $MemoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); + $memoryAdapter = new \ReputationVIP\QueueClient\Adapter\MemoryAdapter(); - $MemoryAdapter->createQueue('testQueue'); - $MemoryAdapter = $MemoryAdapter->AddMessage('testQueue', 'test message', null, 1); + $memoryAdapter->createQueue('testQueue'); + $memoryAdapter = $memoryAdapter->addMessage('testQueue', 'test message', null, 1); sleep(1); - $this->given($MemoryAdapter) - ->class($MemoryAdapter)->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + $this->given($memoryAdapter) + ->class($memoryAdapter)->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testMemoryAdapterAddMessageWithEmptyQueueName() From df28620debb36fd7e1d069e2ae2d0ca58df88a19 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Wed, 9 Mar 2016 10:50:36 +0100 Subject: [PATCH 10/51] Enhance exception messages --- src/Adapter/FileAdapter.php | 49 +++++++++---------- src/Adapter/MemoryAdapter.php | 46 ++++++++--------- src/Adapter/SQSAdapter.php | 34 ++++++------- .../StandardPriorityHandler.php | 22 ++++----- src/QueueClient.php | 12 ++--- 5 files changed, 81 insertions(+), 82 deletions(-) diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 3254518..f3d5a86 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -244,14 +244,14 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds $priority = $this->priorityHandler->getDefault(); } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (empty($message)) { - throw new InvalidArgumentException('Parameter message empty or not defined.'); + throw new InvalidArgumentException('Message empty or not defined.'); } $this->addMessageLock($queueName, $message, $priority); @@ -344,17 +344,17 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!is_numeric($nbMsg)) { - throw new InvalidArgumentException('Parameter number is not a number.'); + throw new InvalidArgumentException('Number of messages must be numeric.'); } if ($nbMsg <= 0 || $nbMsg > static::MAX_NB_MESSAGES) { - throw new InvalidArgumentException('Parameter number is not valid.'); + throw new InvalidArgumentException('Number of messages is not valid.'); } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } return $this->getMessagesLock($queueName, $nbMsg, $priority); } @@ -417,14 +417,14 @@ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0 public function deleteMessage($queueName, $message) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { - throw new InvalidArgumentException('Parameter message empty or not defined.'); + throw new InvalidArgumentException('Message empty or not defined.'); } if (!is_array($message)) { - throw new InvalidArgumentException('message must be an array.'); + throw new InvalidArgumentException('Message must be an array.'); } if (!isset($message['id'])) { throw new InvalidArgumentException('Message id not found in message.'); @@ -433,7 +433,7 @@ public function deleteMessage($queueName, $message) throw new InvalidArgumentException('Message priority not found in message.'); } if (!$this->fs->exists($this->getQueuePath($queueName, $message['priority']))) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $this->deleteMessageLock($queueName, $message, $message['priority']); @@ -456,11 +456,11 @@ public function isEmpty($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); @@ -488,11 +488,11 @@ public function getNumberMessages($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); @@ -520,7 +520,7 @@ public function getNumberMessages($queueName, $priority = null) private function deleteQueueLock($queueName, $priority, $nbTries = 0) { if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queueFilePath = $this->getQueuePath($queueName, $priority); @@ -543,7 +543,7 @@ private function deleteQueueLock($queueName, $priority, $nbTries = 0) public function deleteQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); @@ -563,10 +563,10 @@ public function deleteQueue($queueName) private function createQueueLock($queueName, $priority) { if ($this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new \Exception('Queue with name ' . $queueName . ' already exist.'); + throw new \Exception('A queue named ' . $queueName . ' already exist.'); } if (strpos($queueName, ' ') !== false) { - throw new \Exception('QueueName must not contain any space.'); + throw new \Exception('Queue name must not contain white spaces.'); } $queue = [ @@ -581,7 +581,7 @@ private function createQueueLock($queueName, $priority) public function createQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); @@ -598,11 +598,11 @@ public function createQueue($queueName) public function renameQueue($sourceQueueName, $targetQueueName) { if (empty($sourceQueueName)) { - throw new InvalidArgumentException('Parameter sourceQueueName empty or not defined.'); + throw new InvalidArgumentException('Source queue name empty or not defined.'); } if (empty($targetQueueName)) { - throw new InvalidArgumentException('Parameter targetQueueName empty or not defined.'); + throw new InvalidArgumentException('Target queue name empty or not defined.'); } $this->createQueue($targetQueueName); @@ -633,12 +633,11 @@ public function purgeQueue($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } - if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index a877036..a9d499f 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -49,14 +49,14 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (empty($message)) { - throw new InvalidArgumentException('Parameter message empty or not defined.'); + throw new InvalidArgumentException('Message empty or not defined.'); } if (isset($this->queues[$queueName][$priority])) { $new_message = [ @@ -81,14 +81,14 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds public function deleteMessage($queueName, $message) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { - throw new InvalidArgumentException('Parameter message empty or not defined.'); + throw new InvalidArgumentException('Message empty or not defined.'); } if (!is_array($message)) { - throw new InvalidArgumentException('message must be an array.'); + throw new InvalidArgumentException('Message must be an array.'); } if (!isset($message['id'])) { throw new InvalidArgumentException('Message id not found in message.'); @@ -132,11 +132,11 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (isset($this->queues[$queueName][$priority])) { @@ -180,11 +180,11 @@ public function isEmpty($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new \Exception('Unknown priority: ' . $priority); @@ -212,11 +212,11 @@ public function getNumberMessages($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new \Exception('Unknown priority: ' . $priority); @@ -238,11 +238,11 @@ public function getNumberMessages($queueName, $priority = null) public function deleteQueue($queueName, $nb_try = 0) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } unset($this->queues[$queueName]); @@ -256,14 +256,14 @@ public function deleteQueue($queueName, $nb_try = 0) public function createQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (isset($this->queues[$queueName])) { - throw new \Exception('Queue with name ' . $queueName . ' already exist.'); + throw new \Exception('A queue named ' . $queueName . ' already exist.'); } if (strpos($queueName, ' ') !== false) { - throw new \Exception('QueueName must not contain any space.'); + throw new \Exception('Queue name must not contain white spaces.'); } $priorities = $this->priorityHandler->getAll(); @@ -280,18 +280,18 @@ public function createQueue($queueName) public function renameQueue($sourceQueueName, $targetQueueName) { if (empty($sourceQueueName)) { - throw new InvalidArgumentException('Parameter sourceQueueName empty or not defined.'); + throw new InvalidArgumentException('Source queue name empty or not defined.'); } if (!isset($this->queues[$sourceQueueName])) { - throw new InvalidArgumentException('Queue ' . $sourceQueueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $sourceQueueName . " doesn't exist, please create it before using it."); } if (empty($targetQueueName)) { - throw new InvalidArgumentException('Parameter targetQueueName empty or not defined.'); + throw new InvalidArgumentException('Target queue name empty or not defined.'); } if (isset($this->queues[$targetQueueName])) { - throw new InvalidArgumentException('Queue ' . $targetQueueName . ' already exist.'); + throw new InvalidArgumentException("Queue " . $targetQueueName . ' already exist.'); } $this->createQueue($targetQueueName); @@ -316,11 +316,11 @@ public function purgeQueue($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); + throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new \Exception('Unknown priority: ' . $priority); diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index 73345b1..bdaee56 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -62,7 +62,7 @@ public function addMessages($queueName, $messages, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } $batchMessages = []; @@ -71,7 +71,7 @@ public function addMessages($queueName, $messages, $priority = null) foreach ($messages as $index => $message) { if (empty($message)) { - throw new InvalidArgumentException('Parameter message empty or not defined.'); + throw new InvalidArgumentException('Message empty or not defined.'); } $messageData = [ 'Id' => (string) $index, @@ -109,11 +109,11 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { - throw new InvalidArgumentException('Parameter message empty or not defined.'); + throw new InvalidArgumentException('Message empty or not defined.'); } $message = serialize($message); $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); @@ -148,14 +148,14 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (!is_numeric($nbMsg)) { - throw new InvalidArgumentException('Parameter number is not a number.'); + throw new InvalidArgumentException('Number of messages must be numeric.'); } if ($nbMsg <= 0 || $nbMsg > self::MAX_NB_MESSAGES) { - throw new InvalidArgumentException('Parameter number is not valid.'); + throw new InvalidArgumentException('Number of messages not valid.'); } $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); @@ -184,14 +184,14 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) public function deleteMessage($queueName, $message) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { - throw new InvalidArgumentException('Parameter message empty or not defined.'); + throw new InvalidArgumentException('Message empty or not defined.'); } if (!is_array($message)) { - throw new InvalidArgumentException('message must be an array.'); + throw new InvalidArgumentException('Message must be an array.'); } if (!isset($message['ReceiptHandle'])) { throw new InvalidArgumentException('ReceiptHandle not found in message.'); @@ -225,7 +225,7 @@ public function isEmpty($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); @@ -260,7 +260,7 @@ public function getNumberMessages($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); @@ -284,7 +284,7 @@ public function getNumberMessages($queueName, $priority = null) public function deleteQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); @@ -307,7 +307,7 @@ public function deleteQueue($queueName) public function createQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); @@ -330,10 +330,10 @@ public function createQueue($queueName) public function renameQueue($sourceQueueName, $targetQueueName) { if (empty($sourceQueueName)) { - throw new InvalidArgumentException('Parameter sourceQueueName empty or not defined.'); + throw new InvalidArgumentException('Source queue name empty or not defined.'); } if (empty($targetQueueName)) { - throw new InvalidArgumentException('Parameter targetQueueName empty or not defined.'); + throw new InvalidArgumentException('Target queue name empty or not defined.'); } $this->createQueue($targetQueueName); @@ -372,7 +372,7 @@ public function purgeQueue($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Parameter queueName empty or not defined.'); + throw new InvalidArgumentException('Queue name empty or not defined.'); } $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); diff --git a/src/PriorityHandler/StandardPriorityHandler.php b/src/PriorityHandler/StandardPriorityHandler.php index fcb57a7..dda1293 100644 --- a/src/PriorityHandler/StandardPriorityHandler.php +++ b/src/PriorityHandler/StandardPriorityHandler.php @@ -20,7 +20,7 @@ class StandardPriorityHandler implements PriorityHandlerInterface public function add($name) { if (in_array($name, $this->priorities)) { - throw new \InvalidArgumentException('Level ' . $name . ' already exist.'); + throw new \InvalidArgumentException('Level ' . $name . ' already exists.'); } $this->priorities[] = $name; return $this; @@ -33,7 +33,7 @@ public function remove($name) { $key = array_search($name, $this->priorities); if (false === $key) { - throw new \InvalidArgumentException('Level ' . $name . ' doesn\'t exist.'); + throw new \InvalidArgumentException("Level " . $name . " doesn't exist."); } $default = $this->getDefault(); unset($this->priorities[$key]); @@ -54,7 +54,7 @@ public function addBefore($addName, $beforeName) $key = array_search($beforeName, $this->priorities); if (false !== $key) { if (in_array($addName, $this->priorities)) { - throw new \InvalidArgumentException('Level ' . $addName . ' already exist.'); + throw new \InvalidArgumentException('Level ' . $addName . ' already exists.'); } $default = $this->getDefault(); if (0 === $key) { @@ -67,7 +67,7 @@ public function addBefore($addName, $beforeName) } $this->setDefault($default); } else { - throw new \InvalidArgumentException('Level ' . $beforeName . ' doesn\'t exist.'); + throw new \InvalidArgumentException("Level " . $beforeName . " doesn't exist."); } return $this; } @@ -91,7 +91,7 @@ public function removeBefore($beforeName) } } } else { - throw new \InvalidArgumentException('Level ' . $beforeName . ' doesn\'t exist.'); + throw new \InvalidArgumentException("Level " . $beforeName . " doesn't exist."); } return $this; } @@ -104,7 +104,7 @@ public function addAfter($addName, $afterName) $key = array_search($afterName, $this->priorities); if (false !== $key) { if (in_array($addName, $this->priorities)) { - throw new \InvalidArgumentException('Level ' . $addName . ' already exist.'); + throw new \InvalidArgumentException('Level ' . $addName . ' already exists.'); } $default = $this->getDefault(); if ($key === (count($this->priorities) - 1)) { @@ -117,7 +117,7 @@ public function addAfter($addName, $afterName) } $this->setDefault($default); } else { - throw new \InvalidArgumentException('Level ' . $afterName . ' doesn\'t exist.'); + throw new \InvalidArgumentException("Level " . $afterName . " doesn't exist."); } return $this; } @@ -141,7 +141,7 @@ public function removeAfter($afterName) } } } else { - throw new \InvalidArgumentException('Level ' . $afterName . ' doesn\'t exist.'); + throw new \InvalidArgumentException("Level " . $afterName . " doesn't exist."); } return $this; } @@ -203,7 +203,7 @@ public function setDefault($newDefault) if (false !== $key) { $this->defaultIndex = $key; } else { - throw new \InvalidArgumentException('Level ' . $newDefault . ' doesn\'t exist.'); + throw new \InvalidArgumentException("Level " . $newDefault . " doesn't exist."); } return $this; @@ -239,7 +239,7 @@ public function getBefore($beforeName) $key = array_search($beforeName, $this->priorities); if (false === $key) { - throw new \InvalidArgumentException('Level ' . $beforeName . ' doesn\'t exist.'); + throw new \InvalidArgumentException("Level " . $beforeName . " doesn't exist."); } if (0 === $key) { @@ -257,7 +257,7 @@ public function getAfter($afterName) $key = array_search($afterName, $this->priorities); if (false === $key) { - throw new \InvalidArgumentException('Level ' . $afterName . ' doesn\'t exist.'); + throw new \InvalidArgumentException("Level " . $afterName . " doesn't exist."); } if (count($this->priorities) - 1 === $key) { diff --git a/src/QueueClient.php b/src/QueueClient.php index 58e6534..f5f33b3 100644 --- a/src/QueueClient.php +++ b/src/QueueClient.php @@ -83,7 +83,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) { $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' as multiple queue link : ' . implode(' , ', $queues)); + throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->getMessages($queues, $nbMsg, $priority); } @@ -96,7 +96,7 @@ public function deleteMessage($queueName, $message) { $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' as multiple queue link : ' . implode(' , ', $queues)); + throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { $this->adapter->deleteMessage($queues, $message); } @@ -124,7 +124,7 @@ public function isEmpty($queueName, $priority = null) $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' as multiple queue link : ' . implode(' , ', $queues)); + throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->isEmpty($queues, $priority); } @@ -138,7 +138,7 @@ public function getNumberMessages($queueName, $priority = null) $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' as multiple queue link : ' . implode(' , ', $queues)); + throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->getNumberMessages($queues, $priority); } @@ -199,7 +199,7 @@ public function purgeQueue($queueName, $priority = null) $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' as multiple queue link : ' . implode(' , ', $queues)); + throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { $this->adapter->purgeQueue($queues, $priority); } @@ -233,7 +233,7 @@ public function addAlias($queueName, $alias) $listQueues = $this->listQueues(); if (empty($queueName)) { - throw new InvalidArgumentException('QueueName is empty.'); + throw new InvalidArgumentException('Queue name is empty.'); } if (empty($alias)) { From b5c3fda2f6f1e18feeb4ae341ff34993992ebc6b Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Wed, 9 Mar 2016 11:16:22 +0100 Subject: [PATCH 11/51] Add LogicException --- src/Adapter/FileAdapter.php | 15 ++++++++------- src/Adapter/MemoryAdapter.php | 17 +++++++++-------- src/Exception/IOException.php | 0 src/Exception/LogicException.php | 7 +++++++ 4 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 src/Exception/IOException.php create mode 100644 src/Exception/LogicException.php diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index f3d5a86..ce8733c 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -3,6 +3,7 @@ namespace ReputationVIP\QueueClient\Adapter; use InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\LogicException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use ReputationVIP\QueueClient\Utils\LockHandlerFactory; @@ -248,7 +249,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (empty($message)) { throw new InvalidArgumentException('Message empty or not defined.'); @@ -354,7 +355,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) throw new InvalidArgumentException('Number of messages is not valid.'); } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } return $this->getMessagesLock($queueName, $nbMsg, $priority); } @@ -433,7 +434,7 @@ public function deleteMessage($queueName, $message) throw new InvalidArgumentException('Message priority not found in message.'); } if (!$this->fs->exists($this->getQueuePath($queueName, $message['priority']))) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $this->deleteMessageLock($queueName, $message, $message['priority']); @@ -460,7 +461,7 @@ public function isEmpty($queueName, $priority = null) } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); @@ -492,7 +493,7 @@ public function getNumberMessages($queueName, $priority = null) } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); @@ -520,7 +521,7 @@ public function getNumberMessages($queueName, $priority = null) private function deleteQueueLock($queueName, $priority, $nbTries = 0) { if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queueFilePath = $this->getQueuePath($queueName, $priority); @@ -637,7 +638,7 @@ public function purgeQueue($queueName, $priority = null) } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index a9d499f..535fde5 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -3,6 +3,7 @@ namespace ReputationVIP\QueueClient\Adapter; use InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\LogicException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use SplQueue; @@ -53,7 +54,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (empty($message)) { throw new InvalidArgumentException('Message empty or not defined.'); @@ -136,7 +137,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (isset($this->queues[$queueName][$priority])) { @@ -184,7 +185,7 @@ public function isEmpty($queueName, $priority = null) } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new \Exception('Unknown priority: ' . $priority); @@ -216,7 +217,7 @@ public function getNumberMessages($queueName, $priority = null) } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new \Exception('Unknown priority: ' . $priority); @@ -242,7 +243,7 @@ public function deleteQueue($queueName, $nb_try = 0) } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } unset($this->queues[$queueName]); @@ -284,14 +285,14 @@ public function renameQueue($sourceQueueName, $targetQueueName) } if (!isset($this->queues[$sourceQueueName])) { - throw new InvalidArgumentException("Queue " . $sourceQueueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $sourceQueueName . " doesn't exist, please create it before using it."); } if (empty($targetQueueName)) { throw new InvalidArgumentException('Target queue name empty or not defined.'); } if (isset($this->queues[$targetQueueName])) { - throw new InvalidArgumentException("Queue " . $targetQueueName . ' already exist.'); + throw new LogicException("Queue " . $targetQueueName . ' already exist.'); } $this->createQueue($targetQueueName); @@ -320,7 +321,7 @@ public function purgeQueue($queueName, $priority = null) } if (!isset($this->queues[$queueName])) { - throw new InvalidArgumentException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new \Exception('Unknown priority: ' . $priority); diff --git a/src/Exception/IOException.php b/src/Exception/IOException.php new file mode 100644 index 0000000..e69de29 diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php new file mode 100644 index 0000000..fc889c3 --- /dev/null +++ b/src/Exception/LogicException.php @@ -0,0 +1,7 @@ + Date: Wed, 9 Mar 2016 11:16:41 +0100 Subject: [PATCH 12/51] Add IOException --- src/Adapter/FileAdapter.php | 3 ++- src/Exception/IOException.php | 7 +++++++ src/QueueClient.php | 11 ++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index ce8733c..f1d2ded 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -3,6 +3,7 @@ namespace ReputationVIP\QueueClient\Adapter; use InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\IOException; use ReputationVIP\QueueClient\Exception\LogicException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -70,7 +71,7 @@ public function __construct($repository, PriorityHandlerInterface $priorityHandl try { $this->fs->mkdir($repository); } catch (IOExceptionInterface $e) { - throw new InvalidArgumentException('An error occurred while creating your directory at ' . $e->getPath()); + throw new IOException('An error occurred while creating your directory at ' . $e->getPath()); } } diff --git a/src/Exception/IOException.php b/src/Exception/IOException.php index e69de29..41cee36 100644 --- a/src/Exception/IOException.php +++ b/src/Exception/IOException.php @@ -0,0 +1,7 @@ +resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->getMessages($queues, $nbMsg, $priority); } @@ -96,7 +97,7 @@ public function deleteMessage($queueName, $message) { $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { $this->adapter->deleteMessage($queues, $message); } @@ -124,7 +125,7 @@ public function isEmpty($queueName, $priority = null) $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->isEmpty($queues, $priority); } @@ -138,7 +139,7 @@ public function getNumberMessages($queueName, $priority = null) $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->getNumberMessages($queues, $priority); } @@ -199,7 +200,7 @@ public function purgeQueue($queueName, $priority = null) $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new ErrorException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { $this->adapter->purgeQueue($queues, $priority); } From e86b2a2ea6753e08a1a042deb3f9fcd26a139805 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 09:43:55 +0100 Subject: [PATCH 13/51] Add DomainException in QueueClient --- src/Exception/DomainException.php | 7 +++++++ src/QueueClient.php | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/Exception/DomainException.php diff --git a/src/Exception/DomainException.php b/src/Exception/DomainException.php new file mode 100644 index 0000000..bc3245f --- /dev/null +++ b/src/Exception/DomainException.php @@ -0,0 +1,7 @@ +aliases[$alias])) { @@ -266,7 +267,7 @@ public function removeAlias($alias) unset($this->aliases[$alias]); } } else { - throw new WarningException('No alias found.'); + throw new DomainException('No alias found.'); } return $this; } From 6f006fbb54d13d69f10f6dee8b1fb7025117fdb6 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 10:06:11 +0100 Subject: [PATCH 14/51] Adjust exceptions types in FileAdapter --- src/Adapter/FileAdapter.php | 61 ++++++++++++++-------- src/Exception/InvalidArgumentException.php | 7 +++ src/Exception/UnexpectedValueException.php | 7 +++ 3 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 src/Exception/InvalidArgumentException.php create mode 100644 src/Exception/UnexpectedValueException.php diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index f1d2ded..8cc52ea 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -2,9 +2,10 @@ namespace ReputationVIP\QueueClient\Adapter; -use InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\Exception\IOException; use ReputationVIP\QueueClient\Exception\LogicException; +use ReputationVIP\QueueClient\Exception\UnexpectedValueException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use ReputationVIP\QueueClient\Utils\LockHandlerFactory; @@ -43,6 +44,9 @@ class FileAdapter extends AbstractAdapter implements AdapterInterface * @param Filesystem $fs * @param Finder $finder * @param LockHandlerFactoryInterface $lockHandlerFactory + * + * @throws InvalidArgumentException + * @throws IOException */ public function __construct($repository, PriorityHandlerInterface $priorityHandler = null, Filesystem $fs = null, Finder $finder = null, LockHandlerFactoryInterface $lockHandlerFactory = null) { @@ -117,6 +121,8 @@ private function getQueuePath($queueName, $priority) * * @return array * + * @throws IOException + * @throws UnexpectedValueException * @throws \Exception */ private function readQueueFromFile($queueName, $priority, $nbTries = 0) @@ -125,7 +131,7 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new \Exception('Lock timeout for file ' . $queueFilePath); + throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); @@ -140,7 +146,7 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) } } if (empty($content)) { - throw new \Exception('Fail to get content from file ' . $queueFilePath); + throw new UnexpectedValueException('Fail to get content from file ' . $queueFilePath); } $queue = json_decode($content, true); } catch (\Exception $e) { @@ -159,6 +165,8 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) * @param int $nbTries * * @return AdapterInterface + * + * @throws IOException * @throws \Exception */ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) @@ -167,7 +175,7 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new \Exception('Lock timeout for file ' . $queueFilePath); + throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(100); return $this->writeQueueInFile($queueName, $priority, $queue, ($nbTries + 1)); @@ -191,6 +199,9 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) * @param int $delaySeconds * * @return AdapterInterface + * + * @throws IOException + * @throws UnexpectedValueException * @throws \Exception */ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $delaySeconds = 0) @@ -199,7 +210,7 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new \Exception('Lock timeout for file ' . $queueFilePath); + throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); @@ -214,11 +225,11 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ } } if (empty($content)) { - throw new \Exception('Fail to get content from file ' . $queueFilePath); + throw new UnexpectedValueException('Fail to get content from file ' . $queueFilePath); } $queue = json_decode($content, true); if (!(isset($queue['queue']))) { - throw new \Exception('Queue content bad format.'); + throw new UnexpectedValueException('Queue content bad format.'); } $new_message = [ 'id' => uniqid($queueName . $priority, true), @@ -269,6 +280,8 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * * @return array * + * @throws IOException + * @throws UnexpectedValueException * @throws \Exception */ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) @@ -277,7 +290,7 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new \Exception('Lock timeout for file ' . $queueFilePath); + throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); @@ -293,11 +306,11 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) } } if (empty($content)) { - throw new \Exception('Fail to get content from file ' . $queueFilePath); + throw new UnexpectedValueException('Fail to get content from file ' . $queueFilePath); } $queue = json_decode($content, true); if (!isset($queue['queue'])) { - throw new \Exception('Queue content bad format.'); + throw new UnexpectedValueException('Queue content bad format.'); } foreach ($queue['queue'] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; @@ -368,6 +381,9 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * @param int $nbTries * * @return AdapterInterface + * + * @throws IOException + * @throws UnexpectedValueException * @throws \Exception */ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0) @@ -376,7 +392,7 @@ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0 $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new \Exception('Lock timeout for file ' . $queueFilePath); + throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); return $this->deleteMessageLock($queueName, $message, $priority, ($nbTries + 1)); @@ -390,11 +406,11 @@ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0 } } if (empty($content)) { - throw new \Exception('Fail to get content from file ' . $queueFilePath); + throw new UnexpectedValueException('Fail to get content from file ' . $queueFilePath); } $queue = json_decode($content, true); if (!isset($queue['queue'])) { - throw new \Exception('Queue content bad format.'); + throw new UnexpectedValueException('Queue content bad format.'); } foreach ($queue['queue'] as $key => $messageIterator) { if ($messageIterator['id'] === $message['id']) { @@ -467,7 +483,7 @@ public function isEmpty($queueName, $priority = null) $queue = $this->readQueueFromFile($queueName, $priority); if (!(isset($queue['queue']))) { - throw new \Exception('Queue content bad format.'); + throw new UnexpectedValueException('Queue content bad format.'); } return count($queue['queue']) > 0 ? false : true; @@ -499,7 +515,7 @@ public function getNumberMessages($queueName, $priority = null) $queue = $this->readQueueFromFile($queueName, $priority); if (!(isset($queue['queue']))) { - throw new \Exception('Queue content bad format.'); + throw new UnexpectedValueException('Queue content bad format.'); } foreach ($queue['queue'] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; @@ -517,7 +533,9 @@ public function getNumberMessages($queueName, $priority = null) * @param int $nbTries * * @return AdapterInterface - * @throws \Exception + * + * @throws LogicException + * @throws IOException */ private function deleteQueueLock($queueName, $priority, $nbTries = 0) { @@ -529,7 +547,7 @@ private function deleteQueueLock($queueName, $priority, $nbTries = 0) $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new \Exception('Lock timeout for file ' . $queueFilePath); + throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); return $this->deleteQueueLock($queueName, $priority, ($nbTries + 1)); @@ -560,15 +578,16 @@ public function deleteQueue($queueName) * @param string $queueName * @param string $priority * - * @throws \Exception + * @throws LogicException + * @throws InvalidArgumentException */ private function createQueueLock($queueName, $priority) { if ($this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new \Exception('A queue named ' . $queueName . ' already exist.'); + throw new LogicException('A queue named ' . $queueName . ' already exist.'); } if (strpos($queueName, ' ') !== false) { - throw new \Exception('Queue name must not contain white spaces.'); + throw new InvalidArgumentException('Queue name must not contain white spaces.'); } $queue = [ @@ -644,7 +663,7 @@ public function purgeQueue($queueName, $priority = null) $queue = $this->readQueueFromFile($queueName, $priority); if (!isset($queue['queue'])) { - throw new \Exception('Queue content bad format.'); + throw new UnexpectedValueException('Queue content bad format.'); } $queue['queue'] = []; $this->writeQueueInFile($queueName, $priority, $queue); diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..ce53a87 --- /dev/null +++ b/src/Exception/InvalidArgumentException.php @@ -0,0 +1,7 @@ + Date: Thu, 10 Mar 2016 10:09:40 +0100 Subject: [PATCH 15/51] Adjust exceptions types in MemoryAdapter --- src/Adapter/MemoryAdapter.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index 535fde5..ba31064 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -2,7 +2,8 @@ namespace ReputationVIP\QueueClient\Adapter; -use InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\DomainException; +use ReputationVIP\QueueClient\Exception\InvalidArgumentException use ReputationVIP\QueueClient\Exception\LogicException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -70,7 +71,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds $splQueue = $this->queues[$queueName][$priority]; $splQueue->enqueue($new_message); } else { - throw new \Exception('priority ' . $priority . ' unknown.'); + throw new DomainException('Priority ' . $priority . ' unknown.'); } return $this; @@ -106,7 +107,7 @@ public function deleteMessage($queueName, $message) } } } else { - throw new \Exception('priority ' . $message['priority'] . ' unknown.'); + throw new DomainException('priority ' . $message['priority'] . ' unknown.'); } return $this; @@ -160,7 +161,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } } } else { - throw new \Exception('Unknown priority: ' . $priority); + throw new DomainException('Unknown priority: ' . $priority); } return $messages; @@ -188,7 +189,7 @@ public function isEmpty($queueName, $priority = null) throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { - throw new \Exception('Unknown priority: ' . $priority); + throw new DomainException('Unknown priority: ' . $priority); } /** @var SplQueue $splQueue */ @@ -220,7 +221,7 @@ public function getNumberMessages($queueName, $priority = null) throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { - throw new \Exception('Unknown priority: ' . $priority); + throw new DomainException('Unknown priority: ' . $priority); } foreach ($this->queues[$queueName][$priority] as $key => $message) { @@ -261,10 +262,10 @@ public function createQueue($queueName) } if (isset($this->queues[$queueName])) { - throw new \Exception('A queue named ' . $queueName . ' already exist.'); + throw new LogicException('A queue named ' . $queueName . ' already exist.'); } if (strpos($queueName, ' ') !== false) { - throw new \Exception('Queue name must not contain white spaces.'); + throw new InvalidArgumentException('Queue name must not contain white spaces.'); } $priorities = $this->priorityHandler->getAll(); @@ -324,7 +325,7 @@ public function purgeQueue($queueName, $priority = null) throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { - throw new \Exception('Unknown priority: ' . $priority); + throw new DomainException('Unknown priority: ' . $priority); } $this->queues[$queueName][$priority] = new SplQueue(); From 7f1d0094bec69e9520cd0d098a1d890ca488c147 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 10:11:14 +0100 Subject: [PATCH 16/51] Standardize unknown priority exception message --- src/Adapter/MemoryAdapter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index ba31064..bbd78b4 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -3,7 +3,7 @@ namespace ReputationVIP\QueueClient\Adapter; use ReputationVIP\QueueClient\Exception\DomainException; -use ReputationVIP\QueueClient\Exception\InvalidArgumentException +use ReputationVIP\QueueClient\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\Exception\LogicException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -71,7 +71,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds $splQueue = $this->queues[$queueName][$priority]; $splQueue->enqueue($new_message); } else { - throw new DomainException('Priority ' . $priority . ' unknown.'); + throw new DomainException('Unknown priority: ' . $priority); } return $this; @@ -107,7 +107,7 @@ public function deleteMessage($queueName, $message) } } } else { - throw new DomainException('priority ' . $message['priority'] . ' unknown.'); + throw new DomainException('Unknown priority: ' . $message['priority']); } return $this; From feb6dc648b816c8a7b18520fc2330af1b447d348 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 10:39:05 +0100 Subject: [PATCH 17/51] Enhance PHPDoc SQSAdapter --- src/Adapter/SQSAdapter.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index bdaee56..bf85fbf 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -4,7 +4,7 @@ use Aws\Sqs\Exception\SqsException; use Aws\Sqs\SqsClient; -use InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -100,6 +100,7 @@ public function addMessages($queueName, $messages, $priority = null) /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) @@ -129,6 +130,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) @@ -179,6 +181,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function deleteMessage($queueName, $message) @@ -211,6 +214,7 @@ public function deleteMessage($queueName, $message) /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function isEmpty($queueName, $priority = null) @@ -244,6 +248,7 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function getNumberMessages($queueName, $priority = null) @@ -279,6 +284,7 @@ public function getNumberMessages($queueName, $priority = null) /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function deleteQueue($queueName) @@ -302,6 +308,7 @@ public function deleteQueue($queueName) /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function createQueue($queueName) @@ -325,6 +332,7 @@ public function createQueue($queueName) /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function renameQueue($sourceQueueName, $targetQueueName) @@ -357,6 +365,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc * + * @throws InvalidArgumentException * @throws SqsException */ public function purgeQueue($queueName, $priority = null) From d88897b2c885779fb1b7eac920e7bee20c6c1546 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 10:43:52 +0100 Subject: [PATCH 18/51] Adjust exceptions type in StardardPriorityHandler --- src/Exception/RangeException.php | 7 +++++ .../StandardPriorityHandler.php | 28 +++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 src/Exception/RangeException.php diff --git a/src/Exception/RangeException.php b/src/Exception/RangeException.php new file mode 100644 index 0000000..f848406 --- /dev/null +++ b/src/Exception/RangeException.php @@ -0,0 +1,7 @@ +priorities)) { - throw new \InvalidArgumentException('Level ' . $name . ' already exists.'); + throw new LogicException('Level ' . $name . ' already exists.'); } $this->priorities[] = $name; return $this; @@ -33,7 +37,7 @@ public function remove($name) { $key = array_search($name, $this->priorities); if (false === $key) { - throw new \InvalidArgumentException("Level " . $name . " doesn't exist."); + throw new LogicException("Level " . $name . " doesn't exist."); } $default = $this->getDefault(); unset($this->priorities[$key]); @@ -54,7 +58,7 @@ public function addBefore($addName, $beforeName) $key = array_search($beforeName, $this->priorities); if (false !== $key) { if (in_array($addName, $this->priorities)) { - throw new \InvalidArgumentException('Level ' . $addName . ' already exists.'); + throw new LogicException('Level ' . $addName . ' already exists.'); } $default = $this->getDefault(); if (0 === $key) { @@ -67,7 +71,7 @@ public function addBefore($addName, $beforeName) } $this->setDefault($default); } else { - throw new \InvalidArgumentException("Level " . $beforeName . " doesn't exist."); + throw new LogicException("Level " . $beforeName . " doesn't exist."); } return $this; } @@ -91,7 +95,7 @@ public function removeBefore($beforeName) } } } else { - throw new \InvalidArgumentException("Level " . $beforeName . " doesn't exist."); + throw new LogicException("Level " . $beforeName . " doesn't exist."); } return $this; } @@ -104,7 +108,7 @@ public function addAfter($addName, $afterName) $key = array_search($afterName, $this->priorities); if (false !== $key) { if (in_array($addName, $this->priorities)) { - throw new \InvalidArgumentException('Level ' . $addName . ' already exists.'); + throw new LogicException('Level ' . $addName . ' already exists.'); } $default = $this->getDefault(); if ($key === (count($this->priorities) - 1)) { @@ -117,7 +121,7 @@ public function addAfter($addName, $afterName) } $this->setDefault($default); } else { - throw new \InvalidArgumentException("Level " . $afterName . " doesn't exist."); + throw new LogicException("Level " . $afterName . " doesn't exist."); } return $this; } @@ -141,7 +145,7 @@ public function removeAfter($afterName) } } } else { - throw new \InvalidArgumentException("Level " . $afterName . " doesn't exist."); + throw new LogicException("Level " . $afterName . " doesn't exist."); } return $this; } @@ -175,7 +179,7 @@ public function has($name) public function getName($index) { if ($index < 0 || $index >= count($this->priorities)) { - throw new \InvalidArgumentException('Level index out of range.'); + throw new RangeException('Level index out of range.'); } return $this->priorities[$index]; } @@ -203,7 +207,7 @@ public function setDefault($newDefault) if (false !== $key) { $this->defaultIndex = $key; } else { - throw new \InvalidArgumentException("Level " . $newDefault . " doesn't exist."); + throw new LogicException("Level " . $newDefault . " doesn't exist."); } return $this; @@ -239,7 +243,7 @@ public function getBefore($beforeName) $key = array_search($beforeName, $this->priorities); if (false === $key) { - throw new \InvalidArgumentException("Level " . $beforeName . " doesn't exist."); + throw new LogicException("Level " . $beforeName . " doesn't exist."); } if (0 === $key) { @@ -257,7 +261,7 @@ public function getAfter($afterName) $key = array_search($afterName, $this->priorities); if (false === $key) { - throw new \InvalidArgumentException("Level " . $afterName . " doesn't exist."); + throw new LogicException("Level " . $afterName . " doesn't exist."); } if (count($this->priorities) - 1 === $key) { From 7a4aa5e8df82299fa2bd2468c8a6e6baedad5cb4 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 14:43:48 +0100 Subject: [PATCH 19/51] Make all exceptions implement QueueClientException --- src/Exception/DomainException.php | 2 +- src/Exception/ErrorException.php | 2 +- src/Exception/IOException.php | 2 +- src/Exception/InvalidArgumentException.php | 2 +- src/Exception/LogicException.php | 2 +- src/Exception/NoticeException.php | 2 +- src/Exception/QueueClientException.php | 8 ++++++++ src/Exception/RangeException.php | 2 +- src/Exception/UnexpectedValueException.php | 2 +- src/Exception/WarningException.php | 2 +- 10 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 src/Exception/QueueClientException.php diff --git a/src/Exception/DomainException.php b/src/Exception/DomainException.php index bc3245f..ab059b3 100644 --- a/src/Exception/DomainException.php +++ b/src/Exception/DomainException.php @@ -2,6 +2,6 @@ namespace ReputationVIP\QueueClient\Exception; -class DomainException extends \DomainException +class DomainException extends \DomainException implements QueueClientException { } diff --git a/src/Exception/ErrorException.php b/src/Exception/ErrorException.php index a3e9672..65c3372 100644 --- a/src/Exception/ErrorException.php +++ b/src/Exception/ErrorException.php @@ -2,7 +2,7 @@ namespace ReputationVIP\QueueClient\Exception; -class ErrorException extends \ErrorException +class ErrorException extends \ErrorException implements QueueClientException { /** * ErrorException constructor. diff --git a/src/Exception/IOException.php b/src/Exception/IOException.php index 41cee36..a15310c 100644 --- a/src/Exception/IOException.php +++ b/src/Exception/IOException.php @@ -2,6 +2,6 @@ namespace ReputationVIP\QueueClient\Exception; -class IOException extends \Exception +class IOException extends \Exception implements QueueClientException { } diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index ce53a87..edffe25 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -2,6 +2,6 @@ namespace ReputationVIP\QueueClient\Exception; -class InvalidArgumentException extends \InvalidArgumentException +class InvalidArgumentException extends \InvalidArgumentException implements QueueClientException { } diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php index fc889c3..b0dd0f3 100644 --- a/src/Exception/LogicException.php +++ b/src/Exception/LogicException.php @@ -2,6 +2,6 @@ namespace ReputationVIP\QueueClient\Exception; -class LogicException extends \LogicException +class LogicException extends \LogicException implements QueueClientException { } diff --git a/src/Exception/NoticeException.php b/src/Exception/NoticeException.php index d197694..3e59f25 100644 --- a/src/Exception/NoticeException.php +++ b/src/Exception/NoticeException.php @@ -2,7 +2,7 @@ namespace ReputationVIP\QueueClient\Exception; -class NoticeException extends \ErrorException +class NoticeException extends \ErrorException implements QueueClientException { /** * NoticeException constructor. diff --git a/src/Exception/QueueClientException.php b/src/Exception/QueueClientException.php new file mode 100644 index 0000000..e19d847 --- /dev/null +++ b/src/Exception/QueueClientException.php @@ -0,0 +1,8 @@ + Date: Thu, 10 Mar 2016 14:52:39 +0100 Subject: [PATCH 20/51] Move common exception into special directory --- src/Adapter/FileAdapter.php | 6 +++--- src/Adapter/MemoryAdapter.php | 6 +++--- src/Adapter/SQSAdapter.php | 2 +- src/{ => Common}/Exception/DomainException.php | 2 +- src/{ => Common}/Exception/ErrorException.php | 2 +- src/{ => Common}/Exception/InvalidArgumentException.php | 2 +- src/{ => Common}/Exception/LogicException.php | 2 +- src/{ => Common}/Exception/NoticeException.php | 2 +- src/{ => Common}/Exception/QueueClientException.php | 2 +- src/{ => Common}/Exception/RangeException.php | 2 +- src/{ => Common}/Exception/UnexpectedValueException.php | 2 +- src/{ => Common}/Exception/WarningException.php | 2 +- src/Exception/IOException.php | 2 ++ src/PriorityHandler/StandardPriorityHandler.php | 5 ++--- src/QueueClient.php | 7 ++----- 15 files changed, 22 insertions(+), 24 deletions(-) rename src/{ => Common}/Exception/DomainException.php (62%) rename src/{ => Common}/Exception/ErrorException.php (91%) rename src/{ => Common}/Exception/InvalidArgumentException.php (66%) rename src/{ => Common}/Exception/LogicException.php (62%) rename src/{ => Common}/Exception/NoticeException.php (91%) rename src/{ => Common}/Exception/QueueClientException.php (57%) rename src/{ => Common}/Exception/RangeException.php (62%) rename src/{ => Common}/Exception/UnexpectedValueException.php (66%) rename src/{ => Common}/Exception/WarningException.php (91%) diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 8cc52ea..bad15c4 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -2,10 +2,10 @@ namespace ReputationVIP\QueueClient\Adapter; -use ReputationVIP\QueueClient\Exception\InvalidArgumentException; +use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\Exception\IOException; -use ReputationVIP\QueueClient\Exception\LogicException; -use ReputationVIP\QueueClient\Exception\UnexpectedValueException; +use ReputationVIP\QueueClient\Common\Exception\LogicException; +use ReputationVIP\QueueClient\Common\Exception\UnexpectedValueException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use ReputationVIP\QueueClient\Utils\LockHandlerFactory; diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index bbd78b4..c7e8dda 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -2,9 +2,9 @@ namespace ReputationVIP\QueueClient\Adapter; -use ReputationVIP\QueueClient\Exception\DomainException; -use ReputationVIP\QueueClient\Exception\InvalidArgumentException; -use ReputationVIP\QueueClient\Exception\LogicException; +use ReputationVIP\QueueClient\Common\Exception\DomainException; +use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; +use ReputationVIP\QueueClient\Common\Exception\LogicException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use SplQueue; diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index bf85fbf..78a4771 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -4,7 +4,7 @@ use Aws\Sqs\Exception\SqsException; use Aws\Sqs\SqsClient; -use ReputationVIP\QueueClient\Exception\InvalidArgumentException; +use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; diff --git a/src/Exception/DomainException.php b/src/Common/Exception/DomainException.php similarity index 62% rename from src/Exception/DomainException.php rename to src/Common/Exception/DomainException.php index ab059b3..6e2228c 100644 --- a/src/Exception/DomainException.php +++ b/src/Common/Exception/DomainException.php @@ -1,6 +1,6 @@ Date: Thu, 10 Mar 2016 15:06:20 +0100 Subject: [PATCH 21/51] Add QueueAccessException --- .../Exception/QueueAccessException.php | 7 + src/Adapter/FileAdapter.php | 15 +- src/Adapter/SQSAdapter.php | 167 +++++++++++------- 3 files changed, 122 insertions(+), 67 deletions(-) create mode 100644 src/Adapter/Exception/QueueAccessException.php diff --git a/src/Adapter/Exception/QueueAccessException.php b/src/Adapter/Exception/QueueAccessException.php new file mode 100644 index 0000000..9b67dc6 --- /dev/null +++ b/src/Adapter/Exception/QueueAccessException.php @@ -0,0 +1,7 @@ +fs->mkdir($repository); } catch (IOExceptionInterface $e) { - throw new IOException('An error occurred while creating your directory at ' . $e->getPath()); + throw new QueueAccessException('An error occurred while creating your directory at ' . $e->getPath()); } } @@ -131,7 +132,7 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); + throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); @@ -175,7 +176,7 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); + throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(100); return $this->writeQueueInFile($queueName, $priority, $queue, ($nbTries + 1)); @@ -210,7 +211,7 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); + throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); @@ -290,7 +291,7 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); + throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); @@ -392,7 +393,7 @@ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0 $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); + throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); return $this->deleteMessageLock($queueName, $message, $priority, ($nbTries + 1)); @@ -547,7 +548,7 @@ private function deleteQueueLock($queueName, $priority, $nbTries = 0) $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { - throw new IOException('Reach max retry for locking queue file ' . $queueFilePath); + throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); return $this->deleteQueueLock($queueName, $priority, ($nbTries + 1)); diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index 78a4771..f901774 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -4,6 +4,7 @@ use Aws\Sqs\Exception\SqsException; use Aws\Sqs\SqsClient; +use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -87,11 +88,15 @@ public function addMessages($queueName, $messages, $priority = null) } foreach ($batchMessages as $messages) { - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); - $this->sqsClient->sendMessageBatch([ - 'QueueUrl' => $queueUrl, - 'Entries' => $messages, - ]); + try { + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); + $this->sqsClient->sendMessageBatch([ + 'QueueUrl' => $queueUrl, + 'Entries' => $messages, + ]); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } } return $this; @@ -101,7 +106,7 @@ public function addMessages($queueName, $messages, $priority = null) * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { @@ -116,13 +121,18 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds if (empty($message)) { throw new InvalidArgumentException('Message empty or not defined.'); } + $message = serialize($message); - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); - $this->sqsClient->sendMessage([ - 'QueueUrl' => $queueUrl, - 'MessageBody' => $message, - 'delaySeconds' => $delaySeconds - ]); + try { + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); + $this->sqsClient->sendMessage([ + 'QueueUrl' => $queueUrl, + 'MessageBody' => $message, + 'delaySeconds' => $delaySeconds, + ]); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } return $this; } @@ -131,7 +141,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { @@ -160,12 +170,16 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) throw new InvalidArgumentException('Number of messages not valid.'); } - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); - $results = $this->sqsClient->receiveMessage([ - 'QueueUrl' => $queueUrl, - 'MaxNumberOfMessages' => $nbMsg, - ]); - $messages = $results->get('Messages'); + try { + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); + $results = $this->sqsClient->receiveMessage([ + 'QueueUrl' => $queueUrl, + 'MaxNumberOfMessages' => $nbMsg, + ]); + $messages = $results->get('Messages'); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } if (is_null($messages)) { return []; @@ -182,7 +196,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function deleteMessage($queueName, $message) { @@ -202,11 +216,16 @@ public function deleteMessage($queueName, $message) if (!isset($message['priority'])) { throw new InvalidArgumentException('Priority not found in message.'); } - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $message['priority'])])->get('QueueUrl'); - $this->sqsClient->deleteMessage([ - 'QueueUrl' => $queueUrl, - 'ReceiptHandle' => $message['ReceiptHandle'], - ]); + + try { + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $message['priority'])])->get('QueueUrl'); + $this->sqsClient->deleteMessage([ + 'QueueUrl' => $queueUrl, + 'ReceiptHandle' => $message['ReceiptHandle'], + ]); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } return $this; } @@ -215,7 +234,7 @@ public function deleteMessage($queueName, $message) * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function isEmpty($queueName, $priority = null) { @@ -232,11 +251,16 @@ public function isEmpty($queueName, $priority = null) throw new InvalidArgumentException('Queue name empty or not defined.'); } - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); - $result = $this->sqsClient->getQueueAttributes([ - 'QueueUrl' => $queueUrl, - 'AttributeNames' => ['ApproximateNumberOfMessages'], - ]); + try { + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); + $result = $this->sqsClient->getQueueAttributes([ + 'QueueUrl' => $queueUrl, + 'AttributeNames' => ['ApproximateNumberOfMessages'], + ]); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } + $result = $result->get('Attributes'); if (!empty($result['ApproximateNumberOfMessages']) && $result['ApproximateNumberOfMessages'] > 0) { return false; @@ -249,7 +273,7 @@ public function isEmpty($queueName, $priority = null) * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function getNumberMessages($queueName, $priority = null) { @@ -268,11 +292,16 @@ public function getNumberMessages($queueName, $priority = null) throw new InvalidArgumentException('Queue name empty or not defined.'); } - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); - $result = $this->sqsClient->getQueueAttributes([ - 'QueueUrl' => $queueUrl, - 'AttributeNames' => ['ApproximateNumberOfMessages'], - ]); + try { + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); + $result = $this->sqsClient->getQueueAttributes([ + 'QueueUrl' => $queueUrl, + 'AttributeNames' => ['ApproximateNumberOfMessages'], + ]); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } + $result = $result->get('Attributes'); if (!empty($result['ApproximateNumberOfMessages']) && $result['ApproximateNumberOfMessages'] > 0) { return $result['ApproximateNumberOfMessages']; @@ -285,7 +314,7 @@ public function getNumberMessages($queueName, $priority = null) * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function deleteQueue($queueName) { @@ -296,10 +325,14 @@ public function deleteQueue($queueName) $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); - $this->sqsClient->deleteQueue([ - 'QueueUrl' => $queueUrl, - ]); + try { + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); + $this->sqsClient->deleteQueue([ + 'QueueUrl' => $queueUrl, + ]); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } } return $this; @@ -309,7 +342,7 @@ public function deleteQueue($queueName) * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function createQueue($queueName) { @@ -320,10 +353,14 @@ public function createQueue($queueName) $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { - $this->sqsClient->createQueue([ - 'QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority), - 'Attributes' => [], - ]); + try { + $this->sqsClient->createQueue([ + 'QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority), + 'Attributes' => [], + ]); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } } return $this; @@ -333,7 +370,7 @@ public function createQueue($queueName) * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function renameQueue($sourceQueueName, $targetQueueName) { @@ -366,7 +403,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) * @inheritdoc * * @throws InvalidArgumentException - * @throws SqsException + * @throws QueueAccessException */ public function purgeQueue($queueName, $priority = null) { @@ -384,10 +421,14 @@ public function purgeQueue($queueName, $priority = null) throw new InvalidArgumentException('Queue name empty or not defined.'); } - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); - $this->sqsClient->purgeQueue([ - 'QueueUrl' => $queueUrl, - ]); + try { + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); + $this->sqsClient->purgeQueue([ + 'QueueUrl' => $queueUrl, + ]); + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); + } return $this; } @@ -395,18 +436,24 @@ public function purgeQueue($queueName, $priority = null) /** * @inheritdoc * - * @throws SqsException + * @throws QueueAccessException */ public function listQueues($prefix = '') { $listQueues = []; - if (empty($prefix)) { - $results = $this->sqsClient->listQueues(); - } else { - $results = $this->sqsClient->listQueues([ - 'QueueNamePrefix' => $prefix, - ]); + + try { + if (empty($prefix)) { + $results = $this->sqsClient->listQueues(); + } else { + $results = $this->sqsClient->listQueues([ + 'QueueNamePrefix' => $prefix, + ]); + } + } catch (SqsException $e) { + throw new QueueAccessException($e->getMessage()); } + $results = $results->get('QueueUrls'); foreach ($results as $result) { From cb84f78f1bef5c80d244bb847d9590358b79f2f3 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 15:28:21 +0100 Subject: [PATCH 22/51] Wrap SQSException in QueueAccessException --- .../Exception/QueueAccessException.php | 2 +- src/Adapter/SQSAdapter.php | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Adapter/Exception/QueueAccessException.php b/src/Adapter/Exception/QueueAccessException.php index 9b67dc6..0315eeb 100644 --- a/src/Adapter/Exception/QueueAccessException.php +++ b/src/Adapter/Exception/QueueAccessException.php @@ -4,4 +4,4 @@ use ReputationVIP\QueueClient\Common\Exception\QueueClientException; -class QueueAccessException extends \RuntimeException implements QueueClientException {} +class QueueAccessException extends \RuntimeException implements QueueClientException {} diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index f901774..016bf7a 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -95,7 +95,7 @@ public function addMessages($queueName, $messages, $priority = null) 'Entries' => $messages, ]); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Cannot add messages in queue.', 0, $e); } } @@ -131,7 +131,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds 'delaySeconds' => $delaySeconds, ]); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Cannot add message in queue.', 0, $e); } return $this; @@ -178,7 +178,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) ]); $messages = $results->get('Messages'); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Cannot get messages from queue.', 0, $e); } if (is_null($messages)) { @@ -224,7 +224,7 @@ public function deleteMessage($queueName, $message) 'ReceiptHandle' => $message['ReceiptHandle'], ]); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Cannot delete message from queue.', 0, $e); } return $this; @@ -258,7 +258,7 @@ public function isEmpty($queueName, $priority = null) 'AttributeNames' => ['ApproximateNumberOfMessages'], ]); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Unable to determine whether queue is empty.', 0, $e); } $result = $result->get('Attributes'); @@ -299,7 +299,7 @@ public function getNumberMessages($queueName, $priority = null) 'AttributeNames' => ['ApproximateNumberOfMessages'], ]); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Unable to get number of messages.', 0, $e); } $result = $result->get('Attributes'); @@ -331,7 +331,7 @@ public function deleteQueue($queueName) 'QueueUrl' => $queueUrl, ]); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Cannot delete queue.', 0, $e); } } @@ -359,7 +359,7 @@ public function createQueue($queueName) 'Attributes' => [], ]); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Cannot create queue', 0, $e); } } @@ -427,7 +427,7 @@ public function purgeQueue($queueName, $priority = null) 'QueueUrl' => $queueUrl, ]); } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Cannot purge queue', 0, $e); } return $this; @@ -451,7 +451,7 @@ public function listQueues($prefix = '') ]); } } catch (SqsException $e) { - throw new QueueAccessException($e->getMessage()); + throw new QueueAccessException('Cannot list queues', 0, $e); } $results = $results->get('QueueUrls'); From 7c5eb03a23c3b4430adc02570494faa339685a03 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 15:43:30 +0100 Subject: [PATCH 23/51] Add InvalidMessageException Also, move argument checking at the top of methods --- .../Exception/InvalidMessageException.php | 7 ++ src/Adapter/FileAdapter.php | 80 +++++++++++-------- src/Adapter/MemoryAdapter.php | 75 +++++++++-------- src/Adapter/SQSAdapter.php | 29 +++---- src/QueueClient.php | 1 + 5 files changed, 110 insertions(+), 82 deletions(-) create mode 100644 src/Adapter/Exception/InvalidMessageException.php diff --git a/src/Adapter/Exception/InvalidMessageException.php b/src/Adapter/Exception/InvalidMessageException.php new file mode 100644 index 0000000..8f17a59 --- /dev/null +++ b/src/Adapter/Exception/InvalidMessageException.php @@ -0,0 +1,7 @@ +priorityHandler->getDefault(); - } if (empty($queueName)) { throw new InvalidArgumentException('Queue name empty or not defined.'); } + if (empty($message)) { + throw new InvalidMessageException('Message empty or not defined.'); + } + + if (null === $priority) { + $priority = $this->priorityHandler->getDefault(); + } + if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } - if (empty($message)) { - throw new InvalidArgumentException('Message empty or not defined.'); - } $this->addMessageLock($queueName, $message, $priority); @@ -345,6 +348,18 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { + if (empty($queueName)) { + throw new InvalidArgumentException('Queue name empty or not defined.'); + } + + if (!is_numeric($nbMsg)) { + throw new InvalidArgumentException('Number of messages must be numeric.'); + } + + if ($nbMsg <= 0 || $nbMsg > static::MAX_NB_MESSAGES) { + throw new InvalidArgumentException('Number of messages is not valid.'); + } + if (null === $priority) { $priorities = $this->priorityHandler->getAll(); $messages = []; @@ -359,16 +374,6 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) return $messages; } - if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); - } - - if (!is_numeric($nbMsg)) { - throw new InvalidArgumentException('Number of messages must be numeric.'); - } - if ($nbMsg <= 0 || $nbMsg > static::MAX_NB_MESSAGES) { - throw new InvalidArgumentException('Number of messages is not valid.'); - } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } @@ -440,17 +445,21 @@ public function deleteMessage($queueName, $message) } if (empty($message)) { - throw new InvalidArgumentException('Message empty or not defined.'); + throw new InvalidMessageException('Message empty or not defined.'); } + if (!is_array($message)) { - throw new InvalidArgumentException('Message must be an array.'); + throw new InvalidMessageException('Message must be an array.'); } + if (!isset($message['id'])) { - throw new InvalidArgumentException('Message id not found in message.'); + throw new InvalidMessageException('Message id not found in message.'); } + if (!isset($message['priority'])) { - throw new InvalidArgumentException('Message priority not found in message.'); + throw new InvalidMessageException('Message priority not found in message.'); } + if (!$this->fs->exists($this->getQueuePath($queueName, $message['priority']))) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } @@ -465,6 +474,10 @@ public function deleteMessage($queueName, $message) */ public function isEmpty($queueName, $priority = null) { + if (empty($queueName)) { + throw new InvalidArgumentException('Queue name empty or not defined.'); + } + if (null === $priority) { $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) @@ -474,10 +487,6 @@ public function isEmpty($queueName, $priority = null) return true; } - if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); - } - if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } @@ -497,6 +506,10 @@ public function getNumberMessages($queueName, $priority = null) { $nbrMsg = 0; + if (empty($queueName)) { + throw new InvalidArgumentException('Queue name empty or not defined.'); + } + if (null === $priority) { $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { @@ -506,10 +519,6 @@ public function getNumberMessages($queueName, $priority = null) return $nbrMsg; } - if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); - } - if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } @@ -584,13 +593,14 @@ public function deleteQueue($queueName) */ private function createQueueLock($queueName, $priority) { - if ($this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new LogicException('A queue named ' . $queueName . ' already exist.'); - } if (strpos($queueName, ' ') !== false) { throw new InvalidArgumentException('Queue name must not contain white spaces.'); } + if ($this->fs->exists($this->getQueuePath($queueName, $priority))) { + throw new LogicException('A queue named ' . $queueName . ' already exist.'); + } + $queue = [ 'queue' => [], ]; @@ -645,6 +655,10 @@ public function renameQueue($sourceQueueName, $targetQueueName) */ public function purgeQueue($queueName, $priority = null) { + if (empty($queueName)) { + throw new InvalidArgumentException('Queue name empty or not defined.'); + } + if (null === $priority) { $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { @@ -654,10 +668,6 @@ public function purgeQueue($queueName, $priority = null) return $this; } - if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); - } - if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index c7e8dda..98739a4 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -2,6 +2,7 @@ namespace ReputationVIP\QueueClient\Adapter; +use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Common\Exception\DomainException; use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\Common\Exception\LogicException; @@ -46,20 +47,22 @@ private function startsWith($haystack, $needle) */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { - if (null === $priority) { - $priority = $this->priorityHandler->getDefault(); - } - if (empty($queueName)) { throw new InvalidArgumentException('Queue name empty or not defined.'); } + if (empty($message)) { + throw new InvalidMessageException('Message empty or not defined.'); + } + + if (null === $priority) { + $priority = $this->priorityHandler->getDefault(); + } + if (!isset($this->queues[$queueName])) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } - if (empty($message)) { - throw new InvalidArgumentException('Message empty or not defined.'); - } + if (isset($this->queues[$queueName][$priority])) { $new_message = [ 'id' => uniqid($queueName . $priority, true), @@ -87,16 +90,19 @@ public function deleteMessage($queueName, $message) } if (empty($message)) { - throw new InvalidArgumentException('Message empty or not defined.'); + throw new InvalidMessageException('Message empty or not defined.'); } + if (!is_array($message)) { - throw new InvalidArgumentException('Message must be an array.'); + throw new InvalidMessageException('Message must be an array.'); } + if (!isset($message['id'])) { - throw new InvalidArgumentException('Message id not found in message.'); + throw new InvalidMessageException('Message id not found in message.'); } + if (!isset($message['priority'])) { - throw new InvalidArgumentException('Message priority not found in message.'); + throw new InvalidMessageException('Message priority not found in message.'); } if (isset($this->queues[$queueName][$message['priority']])) { @@ -119,6 +125,11 @@ public function deleteMessage($queueName, $message) public function getMessages($queueName, $nbMsg = 1, $priority = null) { $messages = []; + + if (empty($queueName)) { + throw new InvalidArgumentException('Queue name empty or not defined.'); + } + if (null === $priority) { $priorities = $this->priorityHandler->getAll(); $messages = []; @@ -133,10 +144,6 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) return $messages; } - if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); - } - if (!isset($this->queues[$queueName])) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } @@ -172,6 +179,10 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) */ public function isEmpty($queueName, $priority = null) { + if (empty($queueName)) { + throw new InvalidArgumentException('Queue name empty or not defined.'); + } + if (null === $priority) { $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) @@ -181,10 +192,6 @@ public function isEmpty($queueName, $priority = null) return true; } - if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); - } - if (!isset($this->queues[$queueName])) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } @@ -204,6 +211,10 @@ public function getNumberMessages($queueName, $priority = null) { $nbrMsg = 0; + if (empty($queueName)) { + throw new InvalidArgumentException('Queue name empty or not defined.'); + } + if (null === $priority) { $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { @@ -213,10 +224,6 @@ public function getNumberMessages($queueName, $priority = null) return $nbrMsg; } - if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); - } - if (!isset($this->queues[$queueName])) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } @@ -261,13 +268,14 @@ public function createQueue($queueName) throw new InvalidArgumentException('Queue name empty or not defined.'); } - if (isset($this->queues[$queueName])) { - throw new LogicException('A queue named ' . $queueName . ' already exist.'); - } if (strpos($queueName, ' ') !== false) { throw new InvalidArgumentException('Queue name must not contain white spaces.'); } + if (isset($this->queues[$queueName])) { + throw new LogicException('A queue named ' . $queueName . ' already exist.'); + } + $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { $this->queues[$queueName][$priority] = new SplQueue(); @@ -285,13 +293,14 @@ public function renameQueue($sourceQueueName, $targetQueueName) throw new InvalidArgumentException('Source queue name empty or not defined.'); } - if (!isset($this->queues[$sourceQueueName])) { - throw new LogicException("Queue " . $sourceQueueName . " doesn't exist, please create it before using it."); - } if (empty($targetQueueName)) { throw new InvalidArgumentException('Target queue name empty or not defined.'); } + if (!isset($this->queues[$sourceQueueName])) { + throw new LogicException("Queue " . $sourceQueueName . " doesn't exist, please create it before using it."); + } + if (isset($this->queues[$targetQueueName])) { throw new LogicException("Queue " . $targetQueueName . ' already exist.'); } @@ -308,6 +317,10 @@ public function renameQueue($sourceQueueName, $targetQueueName) */ public function purgeQueue($queueName, $priority = null) { + if (empty($queueName)) { + throw new InvalidArgumentException('Queue name empty or not defined.'); + } + if (null === $priority) { $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { @@ -317,10 +330,6 @@ public function purgeQueue($queueName, $priority = null) return $this; } - if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); - } - if (!isset($this->queues[$queueName])) { throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); } diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index 016bf7a..0cb8eb1 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -4,6 +4,7 @@ use Aws\Sqs\Exception\SqsException; use Aws\Sqs\SqsClient; +use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; @@ -58,21 +59,21 @@ public function __construct(SqsClient $sqsClient, PriorityHandlerInterface $prio */ public function addMessages($queueName, $messages, $priority = null) { - if (null === $priority) { - $priority = $this->priorityHandler->getDefault(); - } - if (empty($queueName)) { throw new InvalidArgumentException('Queue name empty or not defined.'); } + if (null === $priority) { + $priority = $this->priorityHandler->getDefault(); + } + $batchMessages = []; $batchesCount = 0; $blockCounter = 0; foreach ($messages as $index => $message) { if (empty($message)) { - throw new InvalidArgumentException('Message empty or not defined.'); + throw new InvalidMessageException('Message empty or not defined.'); } $messageData = [ 'Id' => (string) $index, @@ -110,16 +111,16 @@ public function addMessages($queueName, $messages, $priority = null) */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { - if (null === $priority) { - $priority = $this->priorityHandler->getDefault(); - } - if (empty($queueName)) { throw new InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { - throw new InvalidArgumentException('Message empty or not defined.'); + throw new InvalidMessageException('Message empty or not defined.'); + } + + if (null === $priority) { + $priority = $this->priorityHandler->getDefault(); } $message = serialize($message); @@ -205,16 +206,16 @@ public function deleteMessage($queueName, $message) } if (empty($message)) { - throw new InvalidArgumentException('Message empty or not defined.'); + throw new InvalidMessageException('Message empty or not defined.'); } if (!is_array($message)) { - throw new InvalidArgumentException('Message must be an array.'); + throw new InvalidMessageException('Message must be an array.'); } if (!isset($message['ReceiptHandle'])) { - throw new InvalidArgumentException('ReceiptHandle not found in message.'); + throw new InvalidMessageException('ReceiptHandle not found in message.'); } if (!isset($message['priority'])) { - throw new InvalidArgumentException('Priority not found in message.'); + throw new InvalidMessageException('Priority not found in message.'); } try { diff --git a/src/QueueClient.php b/src/QueueClient.php index 7aff5aa..e4d8ac7 100644 --- a/src/QueueClient.php +++ b/src/QueueClient.php @@ -238,6 +238,7 @@ public function addAlias($queueName, $alias) if (empty($alias)) { throw new InvalidArgumentException('Alias is empty.'); } + if (!in_array($queueName, $listQueues)) { throw new DomainException('Attempting to create alias on unknown queue.'); } From bd8a1d67a7a0cc2941bdb0fc70f8f5eaa81f9408 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 15:55:10 +0100 Subject: [PATCH 24/51] Remove IOException --- src/Adapter/FileAdapter.php | 8 -------- src/Exception/IOException.php | 9 --------- 2 files changed, 17 deletions(-) delete mode 100644 src/Exception/IOException.php diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index cc25711..bff4d6f 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -5,7 +5,6 @@ use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; -use ReputationVIP\QueueClient\Exception\IOException; use ReputationVIP\QueueClient\Common\Exception\LogicException; use ReputationVIP\QueueClient\Common\Exception\UnexpectedValueException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; @@ -48,7 +47,6 @@ class FileAdapter extends AbstractAdapter implements AdapterInterface * @param LockHandlerFactoryInterface $lockHandlerFactory * * @throws InvalidArgumentException - * @throws IOException */ public function __construct($repository, PriorityHandlerInterface $priorityHandler = null, Filesystem $fs = null, Finder $finder = null, LockHandlerFactoryInterface $lockHandlerFactory = null) { @@ -123,7 +121,6 @@ private function getQueuePath($queueName, $priority) * * @return array * - * @throws IOException * @throws UnexpectedValueException * @throws \Exception */ @@ -168,7 +165,6 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) * * @return AdapterInterface * - * @throws IOException * @throws \Exception */ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) @@ -202,7 +198,6 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) * * @return AdapterInterface * - * @throws IOException * @throws UnexpectedValueException * @throws \Exception */ @@ -284,7 +279,6 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * * @return array * - * @throws IOException * @throws UnexpectedValueException * @throws \Exception */ @@ -388,7 +382,6 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * * @return AdapterInterface * - * @throws IOException * @throws UnexpectedValueException * @throws \Exception */ @@ -545,7 +538,6 @@ public function getNumberMessages($queueName, $priority = null) * @return AdapterInterface * * @throws LogicException - * @throws IOException */ private function deleteQueueLock($queueName, $priority, $nbTries = 0) { diff --git a/src/Exception/IOException.php b/src/Exception/IOException.php deleted file mode 100644 index 44f3992..0000000 --- a/src/Exception/IOException.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Thu, 10 Mar 2016 16:16:48 +0100 Subject: [PATCH 25/51] Add LevelException --- .../Exception/LevelException.php | 7 ++++++ .../StandardPriorityHandler.php | 24 +++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 src/PriorityHandler/Exception/LevelException.php diff --git a/src/PriorityHandler/Exception/LevelException.php b/src/PriorityHandler/Exception/LevelException.php new file mode 100644 index 0000000..d55c1d9 --- /dev/null +++ b/src/PriorityHandler/Exception/LevelException.php @@ -0,0 +1,7 @@ +priorities)) { - throw new LogicException('Level ' . $name . ' already exists.'); + throw new LevelException('Level ' . $name . ' already exists.'); } $this->priorities[] = $name; return $this; @@ -36,7 +36,7 @@ public function remove($name) { $key = array_search($name, $this->priorities); if (false === $key) { - throw new LogicException("Level " . $name . " doesn't exist."); + throw new LevelException("Level " . $name . " doesn't exist."); } $default = $this->getDefault(); unset($this->priorities[$key]); @@ -57,7 +57,7 @@ public function addBefore($addName, $beforeName) $key = array_search($beforeName, $this->priorities); if (false !== $key) { if (in_array($addName, $this->priorities)) { - throw new LogicException('Level ' . $addName . ' already exists.'); + throw new LevelException('Level ' . $addName . ' already exists.'); } $default = $this->getDefault(); if (0 === $key) { @@ -70,7 +70,7 @@ public function addBefore($addName, $beforeName) } $this->setDefault($default); } else { - throw new LogicException("Level " . $beforeName . " doesn't exist."); + throw new LevelException("Level " . $beforeName . " doesn't exist."); } return $this; } @@ -94,7 +94,7 @@ public function removeBefore($beforeName) } } } else { - throw new LogicException("Level " . $beforeName . " doesn't exist."); + throw new LevelException("Level " . $beforeName . " doesn't exist."); } return $this; } @@ -107,7 +107,7 @@ public function addAfter($addName, $afterName) $key = array_search($afterName, $this->priorities); if (false !== $key) { if (in_array($addName, $this->priorities)) { - throw new LogicException('Level ' . $addName . ' already exists.'); + throw new LevelException('Level ' . $addName . ' already exists.'); } $default = $this->getDefault(); if ($key === (count($this->priorities) - 1)) { @@ -120,7 +120,7 @@ public function addAfter($addName, $afterName) } $this->setDefault($default); } else { - throw new LogicException("Level " . $afterName . " doesn't exist."); + throw new LevelException("Level " . $afterName . " doesn't exist."); } return $this; } @@ -144,7 +144,7 @@ public function removeAfter($afterName) } } } else { - throw new LogicException("Level " . $afterName . " doesn't exist."); + throw new LevelException("Level " . $afterName . " doesn't exist."); } return $this; } @@ -206,7 +206,7 @@ public function setDefault($newDefault) if (false !== $key) { $this->defaultIndex = $key; } else { - throw new LogicException("Level " . $newDefault . " doesn't exist."); + throw new LevelException("Level " . $newDefault . " doesn't exist."); } return $this; @@ -242,7 +242,7 @@ public function getBefore($beforeName) $key = array_search($beforeName, $this->priorities); if (false === $key) { - throw new LogicException("Level " . $beforeName . " doesn't exist."); + throw new LevelException("Level " . $beforeName . " doesn't exist."); } if (0 === $key) { @@ -260,7 +260,7 @@ public function getAfter($afterName) $key = array_search($afterName, $this->priorities); if (false === $key) { - throw new LogicException("Level " . $afterName . " doesn't exist."); + throw new LevelException("Level " . $afterName . " doesn't exist."); } if (count($this->priorities) - 1 === $key) { From 518ebb4f885fed125e201596b24141bfb5b85b7b Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Thu, 10 Mar 2016 16:20:08 +0100 Subject: [PATCH 26/51] Move back exception in src directory --- src/Adapter/Exception/InvalidMessageException.php | 2 +- src/Adapter/Exception/QueueAccessException.php | 2 +- src/Adapter/FileAdapter.php | 6 +++--- src/Adapter/MemoryAdapter.php | 6 +++--- src/Adapter/SQSAdapter.php | 2 +- src/{Common => }/Exception/DomainException.php | 2 +- src/{Common => }/Exception/ErrorException.php | 2 +- src/{Common => }/Exception/InvalidArgumentException.php | 2 +- src/{Common => }/Exception/LogicException.php | 2 +- src/{Common => }/Exception/NoticeException.php | 2 +- src/{Common => }/Exception/QueueClientException.php | 2 +- src/{Common => }/Exception/RangeException.php | 2 +- src/{Common => }/Exception/UnexpectedValueException.php | 2 +- src/{Common => }/Exception/WarningException.php | 2 +- src/PriorityHandler/Exception/LevelException.php | 2 +- src/PriorityHandler/StandardPriorityHandler.php | 2 +- src/QueueClient.php | 4 ++-- 17 files changed, 22 insertions(+), 22 deletions(-) rename src/{Common => }/Exception/DomainException.php (62%) rename src/{Common => }/Exception/ErrorException.php (91%) rename src/{Common => }/Exception/InvalidArgumentException.php (66%) rename src/{Common => }/Exception/LogicException.php (62%) rename src/{Common => }/Exception/NoticeException.php (91%) rename src/{Common => }/Exception/QueueClientException.php (57%) rename src/{Common => }/Exception/RangeException.php (62%) rename src/{Common => }/Exception/UnexpectedValueException.php (66%) rename src/{Common => }/Exception/WarningException.php (91%) diff --git a/src/Adapter/Exception/InvalidMessageException.php b/src/Adapter/Exception/InvalidMessageException.php index 8f17a59..fc55786 100644 --- a/src/Adapter/Exception/InvalidMessageException.php +++ b/src/Adapter/Exception/InvalidMessageException.php @@ -2,6 +2,6 @@ namespace ReputationVIP\QueueClient\Adapter\Exception; -use ReputationVIP\QueueClient\Common\Exception\QueueClientException; +use ReputationVIP\QueueClient\Exception\QueueClientException; class InvalidMessageException extends \InvalidArgumentException implements QueueClientException {} diff --git a/src/Adapter/Exception/QueueAccessException.php b/src/Adapter/Exception/QueueAccessException.php index 0315eeb..f320680 100644 --- a/src/Adapter/Exception/QueueAccessException.php +++ b/src/Adapter/Exception/QueueAccessException.php @@ -2,6 +2,6 @@ namespace ReputationVIP\QueueClient\Adapter\Exception; -use ReputationVIP\QueueClient\Common\Exception\QueueClientException; +use ReputationVIP\QueueClient\Exception\QueueClientException; class QueueAccessException extends \RuntimeException implements QueueClientException {} diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index bff4d6f..ca1c2e0 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -4,9 +4,9 @@ use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; -use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; -use ReputationVIP\QueueClient\Common\Exception\LogicException; -use ReputationVIP\QueueClient\Common\Exception\UnexpectedValueException; +use ReputationVIP\QueueClient\Exception\InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\LogicException; +use ReputationVIP\QueueClient\Exception\UnexpectedValueException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use ReputationVIP\QueueClient\Utils\LockHandlerFactory; diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index 98739a4..dbbf619 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -3,9 +3,9 @@ namespace ReputationVIP\QueueClient\Adapter; use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; -use ReputationVIP\QueueClient\Common\Exception\DomainException; -use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; -use ReputationVIP\QueueClient\Common\Exception\LogicException; +use ReputationVIP\QueueClient\Exception\DomainException; +use ReputationVIP\QueueClient\Exception\InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\LogicException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use SplQueue; diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index 0cb8eb1..85c00dd 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -6,7 +6,7 @@ use Aws\Sqs\SqsClient; use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; -use ReputationVIP\QueueClient\Common\Exception\InvalidArgumentException; +use ReputationVIP\QueueClient\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; diff --git a/src/Common/Exception/DomainException.php b/src/Exception/DomainException.php similarity index 62% rename from src/Common/Exception/DomainException.php rename to src/Exception/DomainException.php index 6e2228c..ab059b3 100644 --- a/src/Common/Exception/DomainException.php +++ b/src/Exception/DomainException.php @@ -1,6 +1,6 @@ Date: Thu, 10 Mar 2016 16:59:10 +0100 Subject: [PATCH 27/51] Clean Exception related PHPDoc --- src/Adapter/AdapterInterface.php | 10 ----- src/Adapter/FileAdapter.php | 38 ++++++++++++++++++- src/Adapter/MemoryAdapter.php | 33 ++++++++++++++++ src/Adapter/SQSAdapter.php | 7 ++++ .../StandardPriorityHandler.php | 20 ++++++++++ src/QueueClient.php | 17 ++++++++- src/QueueClientInterface.php | 16 +------- 7 files changed, 114 insertions(+), 27 deletions(-) diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index ef6beae..8335992 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -11,7 +11,6 @@ interface AdapterInterface * @param mixed $message * @param string $priority * @param int $delaySeconds - * @throw InvalidArgumentException * * @return AdapterInterface */ @@ -23,14 +22,12 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * @param int $nbMsg * * @return array - * @throw InvalidArgumentException */ public function getMessages($queueName, $nbMsg = 1, $priority = null); /** * @param string $queueName * @param array $message - * @throw InvalidArgumentException * * @return AdapterInterface */ @@ -41,7 +38,6 @@ public function deleteMessage($queueName, $message); * @param string $priority * * @return bool - * @throw InvalidArgumentException */ public function isEmpty($queueName, $priority = null); @@ -50,13 +46,11 @@ public function isEmpty($queueName, $priority = null); * @param string $priority * * @return int - * @throw InvalidArgumentException */ public function getNumberMessages($queueName, $priority = null); /** * @param string $queueName - * @throw InvalidArgumentException * * @return AdapterInterface */ @@ -64,7 +58,6 @@ public function deleteQueue($queueName); /** * @param string $queueName - * @throw InvalidArgumentException * * @return AdapterInterface */ @@ -73,7 +66,6 @@ public function createQueue($queueName); /** * @param string $sourceQueueName * @param string $targetQueueName - * @throw InvalidArgumentException * * @return AdapterInterface */ @@ -82,7 +74,6 @@ public function renameQueue($sourceQueueName, $targetQueueName); /** * @param string $queueName * @param string $priority - * @throw InvalidArgumentException * * @return AdapterInterface */ @@ -92,7 +83,6 @@ public function purgeQueue($queueName, $priority = null); * @param string $prefix * * @return array - * @throw InvalidArgumentException */ public function listQueues($prefix = ''); diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index ca1c2e0..936f431 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -47,6 +47,7 @@ class FileAdapter extends AbstractAdapter implements AdapterInterface * @param LockHandlerFactoryInterface $lockHandlerFactory * * @throws InvalidArgumentException + * @throws QueueAccessException */ public function __construct($repository, PriorityHandlerInterface $priorityHandler = null, Filesystem $fs = null, Finder $finder = null, LockHandlerFactoryInterface $lockHandlerFactory = null) { @@ -121,6 +122,7 @@ private function getQueuePath($queueName, $priority) * * @return array * + * @throws QueueAccessException * @throws UnexpectedValueException * @throws \Exception */ @@ -165,6 +167,7 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) * * @return AdapterInterface * + * @throws QueueAccessException * @throws \Exception */ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) @@ -198,6 +201,7 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) * * @return AdapterInterface * + * @throws QueueAccessException * @throws UnexpectedValueException * @throws \Exception */ @@ -247,6 +251,10 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws InvalidMessageException + * @throws LogicException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { @@ -279,6 +287,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * * @return array * + * @throws QueueAccessException * @throws UnexpectedValueException * @throws \Exception */ @@ -339,6 +348,9 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { @@ -382,6 +394,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * * @return AdapterInterface * + * @throws QueueAccessException * @throws UnexpectedValueException * @throws \Exception */ @@ -430,6 +443,10 @@ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0 /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws InvalidMessageException + * @throws LogicException */ public function deleteMessage($queueName, $message) { @@ -464,6 +481,10 @@ public function deleteMessage($queueName, $message) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException + * @throws UnexpectedValueException */ public function isEmpty($queueName, $priority = null) { @@ -494,6 +515,10 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException + * @throws UnexpectedValueException */ public function getNumberMessages($queueName, $priority = null) { @@ -538,6 +563,7 @@ public function getNumberMessages($queueName, $priority = null) * @return AdapterInterface * * @throws LogicException + * @throws QueueAccessException */ private function deleteQueueLock($queueName, $priority, $nbTries = 0) { @@ -561,6 +587,8 @@ private function deleteQueueLock($queueName, $priority, $nbTries = 0) /** * @inheritdoc + * + * @throws InvalidArgumentException */ public function deleteQueue($queueName) { @@ -580,8 +608,8 @@ public function deleteQueue($queueName) * @param string $queueName * @param string $priority * - * @throws LogicException * @throws InvalidArgumentException + * @throws LogicException */ private function createQueueLock($queueName, $priority) { @@ -601,6 +629,8 @@ private function createQueueLock($queueName, $priority) /** * @inheritdoc + * + * @throws InvalidArgumentException */ public function createQueue($queueName) { @@ -618,6 +648,8 @@ public function createQueue($queueName) /** * @inheritdoc + * + * @throws InvalidArgumentException */ public function renameQueue($sourceQueueName, $targetQueueName) { @@ -644,6 +676,10 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException + * @throws UnexpectedValueException */ public function purgeQueue($queueName, $priority = null) { diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index dbbf619..2dd1b9a 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -44,6 +44,10 @@ private function startsWith($haystack, $needle) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws InvalidMessageException + * @throws LogicException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { @@ -82,6 +86,10 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws InvalidMessageException + * @throws DomainException */ public function deleteMessage($queueName, $message) { @@ -121,6 +129,10 @@ public function deleteMessage($queueName, $message) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException + * @throws DomainException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { @@ -176,6 +188,10 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException + * @throws DomainException */ public function isEmpty($queueName, $priority = null) { @@ -206,6 +222,10 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException + * @throws DomainException */ public function getNumberMessages($queueName, $priority = null) { @@ -243,6 +263,9 @@ public function getNumberMessages($queueName, $priority = null) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException */ public function deleteQueue($queueName, $nb_try = 0) { @@ -261,6 +284,9 @@ public function deleteQueue($queueName, $nb_try = 0) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException */ public function createQueue($queueName) { @@ -286,6 +312,9 @@ public function createQueue($queueName) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException */ public function renameQueue($sourceQueueName, $targetQueueName) { @@ -314,6 +343,10 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws LogicException + * @throws DomainException */ public function purgeQueue($queueName, $priority = null) { diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index 85c00dd..6b0522e 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -27,6 +27,7 @@ class SQSAdapter extends AbstractAdapter implements AdapterInterface /** * @param string $queueName * @param string $priority + * * @return string */ private function getQueueNameWithPrioritySuffix($queueName, $priority) { @@ -56,6 +57,10 @@ public function __construct(SqsClient $sqsClient, PriorityHandlerInterface $prio /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws InvalidMessageException + * @throws QueueAccessException */ public function addMessages($queueName, $messages, $priority = null) { @@ -107,6 +112,7 @@ public function addMessages($queueName, $messages, $priority = null) * @inheritdoc * * @throws InvalidArgumentException + * @throws InvalidArgumentException * @throws QueueAccessException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) @@ -197,6 +203,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * @inheritdoc * * @throws InvalidArgumentException + * @throws InvalidMessageException * @throws QueueAccessException */ public function deleteMessage($queueName, $message) diff --git a/src/PriorityHandler/StandardPriorityHandler.php b/src/PriorityHandler/StandardPriorityHandler.php index 27a9014..a2c1a04 100644 --- a/src/PriorityHandler/StandardPriorityHandler.php +++ b/src/PriorityHandler/StandardPriorityHandler.php @@ -19,6 +19,8 @@ class StandardPriorityHandler implements PriorityHandlerInterface /** * @inheritdoc + * + * @throws LevelException */ public function add($name) { @@ -31,6 +33,8 @@ public function add($name) /** * @inheritdoc + * + * @throws LevelException */ public function remove($name) { @@ -51,6 +55,8 @@ public function remove($name) /** * @inheritdoc + * + * @throws LevelException */ public function addBefore($addName, $beforeName) { @@ -77,6 +83,8 @@ public function addBefore($addName, $beforeName) /** * @inheritdoc + * + * @throws LevelException */ public function removeBefore($beforeName) { @@ -101,6 +109,8 @@ public function removeBefore($beforeName) /** * @inheritdoc + * + * @throws LevelException */ public function addAfter($addName, $afterName) { @@ -127,6 +137,8 @@ public function addAfter($addName, $afterName) /** * @inheritdoc + * + * @throws LevelException */ public function removeAfter($afterName) { @@ -174,6 +186,8 @@ public function has($name) /** * @inheritdoc + * + * @throws RangeException */ public function getName($index) { @@ -196,6 +210,8 @@ public function getDefault() /** * @inheritdoc + * + * @throws LevelException */ public function setDefault($newDefault) { @@ -236,6 +252,8 @@ public function getLowest() /** * @inheritdoc + * + * @throws LevelException */ public function getBefore($beforeName) { @@ -254,6 +272,8 @@ public function getBefore($beforeName) /** * @inheritdoc + * + * @throws LevelException */ public function getAfter($afterName) { diff --git a/src/QueueClient.php b/src/QueueClient.php index 0f42927..3494603 100644 --- a/src/QueueClient.php +++ b/src/QueueClient.php @@ -2,10 +2,10 @@ namespace ReputationVIP\QueueClient; -use InvalidArgumentException; use ReputationVIP\QueueClient\Adapter\AdapterInterface; use ReputationVIP\QueueClient\Adapter\NullAdapter; use ReputationVIP\QueueClient\Exception\DomainException; +use ReputationVIP\QueueClient\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\Exception\LogicException; class QueueClient implements QueueClientInterface @@ -77,6 +77,8 @@ public function addMessages($queueName, $messages, $priority = null) /** * @inheritdoc + * + * @throws LogicException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { @@ -90,6 +92,8 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) /** * @inheritdoc + * + * @throws LogicException */ public function deleteMessage($queueName, $message) { @@ -117,6 +121,8 @@ public function deleteMessages($queueName, $messages) /** * @inheritdoc + * + * @throws LogicException */ public function isEmpty($queueName, $priority = null) { @@ -131,6 +137,8 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc + * + * @throws LogicException */ public function getNumberMessages($queueName, $priority = null) { @@ -192,6 +200,8 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc + * + * @throws LogicException */ public function purgeQueue($queueName, $priority = null) { @@ -226,6 +236,9 @@ public function listQueues($regex = null) /** * @inheritdoc + * + * @throws InvalidArgumentException + * @throws DomainException */ public function addAlias($queueName, $alias) { @@ -255,6 +268,8 @@ public function addAlias($queueName, $alias) /** * @inheritdoc + * + * @throws DomainException */ public function removeAlias($alias) { diff --git a/src/QueueClientInterface.php b/src/QueueClientInterface.php index f094864..e324b33 100644 --- a/src/QueueClientInterface.php +++ b/src/QueueClientInterface.php @@ -11,7 +11,6 @@ interface QueueClientInterface * @param mixed $message * @param string $priority * @param int $delaySeconds - * @throw InvalidArgumentException * * @return QueueClientInterface */ @@ -21,7 +20,6 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * @param string $queueName * @param array $messages * @param string $priority - * @throw InvalidArgumentException * * @return QueueClientInterface */ @@ -30,17 +28,15 @@ public function addMessages($queueName, $messages, $priority = null); /** * @param string $queueName * @param string $priority - * @param int $nbMsg + * @param int $nbMsg * * @return array - * @throw InvalidArgumentException */ public function getMessages($queueName, $nbMsg = 1, $priority = null); /** * @param string $queueName * @param array $message - * @throw InvalidArgumentException * * @return QueueClientInterface */ @@ -49,7 +45,6 @@ public function deleteMessage($queueName, $message); /** * @param string $queueName * @param array $messages - * @throw InvalidArgumentException * * @return QueueClientInterface */ @@ -60,7 +55,6 @@ public function deleteMessages($queueName, $messages); * @param string $priority * * @return bool - * @throw InvalidArgumentException */ public function isEmpty($queueName, $priority = null); @@ -69,13 +63,11 @@ public function isEmpty($queueName, $priority = null); * @param string $priority * * @return int - * @throw InvalidArgumentException */ public function getNumberMessages($queueName, $priority = null); /** * @param string $queueName - * @throw InvalidArgumentException * * @return QueueClientInterface */ @@ -83,7 +75,6 @@ public function deleteQueue($queueName); /** * @param string $queueName - * @throw InvalidArgumentException * * @return QueueClientInterface */ @@ -92,7 +83,6 @@ public function createQueue($queueName); /** * @param string $sourceQueueName * @param string $targetQueueName - * @throw InvalidArgumentException * * @return QueueClientInterface */ @@ -101,7 +91,6 @@ public function renameQueue($sourceQueueName, $targetQueueName); /** * @param string $queueName * @param string $priority - * @throw InvalidArgumentException * * @return QueueClientInterface */ @@ -111,7 +100,6 @@ public function purgeQueue($queueName, $priority = null); * @param string $regex * * @return array - * @throw InvalidArgumentException */ public function listQueues($regex = null); @@ -120,7 +108,6 @@ public function listQueues($regex = null); * @param string $alias * * @return QueueClientInterface - * @throw InvalidArgumentException */ public function addAlias($queueName, $alias); @@ -128,7 +115,6 @@ public function addAlias($queueName, $alias); * @param string $alias * * @return QueueClientInterface - * @throw InvalidArgumentException */ public function removeAlias($alias); From 887fd8df178c8caa68a53a47f3e76f857c8482ff Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Fri, 11 Mar 2016 10:34:47 +0100 Subject: [PATCH 28/51] Get rid of warning, logic, error, notice exception --- src/Adapter/FileAdapter.php | 34 ++++++++++++------------- src/Adapter/MemoryAdapter.php | 36 +++++++++++++-------------- src/Exception/ErrorException.php | 20 --------------- src/Exception/LogicException.php | 7 ------ src/Exception/NoticeException.php | 20 --------------- src/Exception/QueueAliasException.php | 7 ++++++ src/Exception/WarningException.php | 20 --------------- src/QueueClient.php | 22 ++++++++-------- 8 files changed, 52 insertions(+), 114 deletions(-) delete mode 100644 src/Exception/ErrorException.php delete mode 100644 src/Exception/LogicException.php delete mode 100644 src/Exception/NoticeException.php create mode 100644 src/Exception/QueueAliasException.php delete mode 100644 src/Exception/WarningException.php diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 936f431..8ac703f 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -5,7 +5,6 @@ use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; use ReputationVIP\QueueClient\Exception\InvalidArgumentException; -use ReputationVIP\QueueClient\Exception\LogicException; use ReputationVIP\QueueClient\Exception\UnexpectedValueException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -254,7 +253,7 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ * * @throws InvalidArgumentException * @throws InvalidMessageException - * @throws LogicException + * @throws QueueAccessException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { @@ -271,7 +270,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $this->addMessageLock($queueName, $message, $priority); @@ -350,7 +349,7 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { @@ -381,8 +380,9 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } + return $this->getMessagesLock($queueName, $nbMsg, $priority); } @@ -446,7 +446,7 @@ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0 * * @throws InvalidArgumentException * @throws InvalidMessageException - * @throws LogicException + * @throws QueueAccessException */ public function deleteMessage($queueName, $message) { @@ -471,7 +471,7 @@ public function deleteMessage($queueName, $message) } if (!$this->fs->exists($this->getQueuePath($queueName, $message['priority']))) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $this->deleteMessageLock($queueName, $message, $message['priority']); @@ -483,7 +483,7 @@ public function deleteMessage($queueName, $message) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException * @throws UnexpectedValueException */ public function isEmpty($queueName, $priority = null) @@ -502,7 +502,7 @@ public function isEmpty($queueName, $priority = null) } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); @@ -517,7 +517,7 @@ public function isEmpty($queueName, $priority = null) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException * @throws UnexpectedValueException */ public function getNumberMessages($queueName, $priority = null) @@ -538,7 +538,7 @@ public function getNumberMessages($queueName, $priority = null) } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); @@ -561,14 +561,12 @@ public function getNumberMessages($queueName, $priority = null) * @param int $nbTries * * @return AdapterInterface - * - * @throws LogicException * @throws QueueAccessException */ private function deleteQueueLock($queueName, $priority, $nbTries = 0) { if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queueFilePath = $this->getQueuePath($queueName, $priority); @@ -609,7 +607,7 @@ public function deleteQueue($queueName) * @param string $priority * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException */ private function createQueueLock($queueName, $priority) { @@ -618,7 +616,7 @@ private function createQueueLock($queueName, $priority) } if ($this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new LogicException('A queue named ' . $queueName . ' already exist.'); + throw new QueueAccessException('A queue named ' . $queueName . ' already exist.'); } $queue = [ @@ -678,7 +676,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException * @throws UnexpectedValueException */ public function purgeQueue($queueName, $priority = null) @@ -697,7 +695,7 @@ public function purgeQueue($queueName, $priority = null) } if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queue = $this->readQueueFromFile($queueName, $priority); diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index 2dd1b9a..d30bbb7 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -3,9 +3,9 @@ namespace ReputationVIP\QueueClient\Adapter; use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; +use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; use ReputationVIP\QueueClient\Exception\DomainException; use ReputationVIP\QueueClient\Exception\InvalidArgumentException; -use ReputationVIP\QueueClient\Exception\LogicException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use SplQueue; @@ -47,7 +47,7 @@ private function startsWith($haystack, $needle) * * @throws InvalidArgumentException * @throws InvalidMessageException - * @throws LogicException + * @throws QueueAccessException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { @@ -64,7 +64,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds } if (!isset($this->queues[$queueName])) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (isset($this->queues[$queueName][$priority])) { @@ -131,7 +131,7 @@ public function deleteMessage($queueName, $message) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException * @throws DomainException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) @@ -157,7 +157,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } if (!isset($this->queues[$queueName])) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (isset($this->queues[$queueName][$priority])) { @@ -190,7 +190,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException * @throws DomainException */ public function isEmpty($queueName, $priority = null) @@ -209,7 +209,7 @@ public function isEmpty($queueName, $priority = null) } if (!isset($this->queues[$queueName])) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new DomainException('Unknown priority: ' . $priority); @@ -224,7 +224,7 @@ public function isEmpty($queueName, $priority = null) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException * @throws DomainException */ public function getNumberMessages($queueName, $priority = null) @@ -245,7 +245,7 @@ public function getNumberMessages($queueName, $priority = null) } if (!isset($this->queues[$queueName])) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new DomainException('Unknown priority: ' . $priority); @@ -265,7 +265,7 @@ public function getNumberMessages($queueName, $priority = null) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException */ public function deleteQueue($queueName, $nb_try = 0) { @@ -274,7 +274,7 @@ public function deleteQueue($queueName, $nb_try = 0) } if (!isset($this->queues[$queueName])) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } unset($this->queues[$queueName]); @@ -286,7 +286,7 @@ public function deleteQueue($queueName, $nb_try = 0) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException */ public function createQueue($queueName) { @@ -299,7 +299,7 @@ public function createQueue($queueName) } if (isset($this->queues[$queueName])) { - throw new LogicException('A queue named ' . $queueName . ' already exist.'); + throw new QueueAccessException('A queue named ' . $queueName . ' already exist.'); } $priorities = $this->priorityHandler->getAll(); @@ -314,7 +314,7 @@ public function createQueue($queueName) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException */ public function renameQueue($sourceQueueName, $targetQueueName) { @@ -327,11 +327,11 @@ public function renameQueue($sourceQueueName, $targetQueueName) } if (!isset($this->queues[$sourceQueueName])) { - throw new LogicException("Queue " . $sourceQueueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $sourceQueueName . " doesn't exist, please create it before using it."); } if (isset($this->queues[$targetQueueName])) { - throw new LogicException("Queue " . $targetQueueName . ' already exist.'); + throw new QueueAccessException("Queue " . $targetQueueName . ' already exist.'); } $this->createQueue($targetQueueName); @@ -345,7 +345,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) * @inheritdoc * * @throws InvalidArgumentException - * @throws LogicException + * @throws QueueAccessException * @throws DomainException */ public function purgeQueue($queueName, $priority = null) @@ -364,7 +364,7 @@ public function purgeQueue($queueName, $priority = null) } if (!isset($this->queues[$queueName])) { - throw new LogicException("Queue " . $queueName . " doesn't exist, please create it before using it."); + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { throw new DomainException('Unknown priority: ' . $priority); diff --git a/src/Exception/ErrorException.php b/src/Exception/ErrorException.php deleted file mode 100644 index 65c3372..0000000 --- a/src/Exception/ErrorException.php +++ /dev/null @@ -1,20 +0,0 @@ -severity = E_ERROR; - } -} diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php deleted file mode 100644 index b0dd0f3..0000000 --- a/src/Exception/LogicException.php +++ /dev/null @@ -1,7 +0,0 @@ -severity = E_NOTICE; - } -} diff --git a/src/Exception/QueueAliasException.php b/src/Exception/QueueAliasException.php new file mode 100644 index 0000000..354ce00 --- /dev/null +++ b/src/Exception/QueueAliasException.php @@ -0,0 +1,7 @@ +severity = E_WARNING; - } -} diff --git a/src/QueueClient.php b/src/QueueClient.php index 3494603..fc73369 100644 --- a/src/QueueClient.php +++ b/src/QueueClient.php @@ -4,9 +4,9 @@ use ReputationVIP\QueueClient\Adapter\AdapterInterface; use ReputationVIP\QueueClient\Adapter\NullAdapter; +use ReputationVIP\QueueClient\Exception\QueueAliasException; use ReputationVIP\QueueClient\Exception\DomainException; use ReputationVIP\QueueClient\Exception\InvalidArgumentException; -use ReputationVIP\QueueClient\Exception\LogicException; class QueueClient implements QueueClientInterface { @@ -78,13 +78,13 @@ public function addMessages($queueName, $messages, $priority = null) /** * @inheritdoc * - * @throws LogicException + * @throws QueueAliasException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new QueueAliasException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->getMessages($queues, $nbMsg, $priority); } @@ -93,13 +93,13 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) /** * @inheritdoc * - * @throws LogicException + * @throws QueueAliasException */ public function deleteMessage($queueName, $message) { $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new QueueAliasException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { $this->adapter->deleteMessage($queues, $message); } @@ -122,14 +122,14 @@ public function deleteMessages($queueName, $messages) /** * @inheritdoc * - * @throws LogicException + * @throws QueueAliasException */ public function isEmpty($queueName, $priority = null) { $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new QueueAliasException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->isEmpty($queues, $priority); } @@ -138,14 +138,14 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc * - * @throws LogicException + * @throws QueueAliasException */ public function getNumberMessages($queueName, $priority = null) { $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new QueueAliasException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { return $this->adapter->getNumberMessages($queues, $priority); } @@ -201,14 +201,14 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc * - * @throws LogicException + * @throws QueueAliasException */ public function purgeQueue($queueName, $priority = null) { $queues = $this->resolveAliasQueueName($queueName); if (is_array($queues)) { - throw new LogicException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); + throw new QueueAliasException('Alias ' . $queueName . ' corresponds to several queues: ' . implode(' , ', $queues)); } else { $this->adapter->purgeQueue($queues, $priority); } From 665ce733e72896988b3003a71d5d8bbb63697a4c Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Fri, 11 Mar 2016 10:40:31 +0100 Subject: [PATCH 29/51] Get rid of DomainException --- src/Adapter/MemoryAdapter.php | 25 ++++++++++--------- src/Exception/DomainException.php | 7 ------ .../Exception/InvalidPriorityException.php | 7 ++++++ src/QueueClient.php | 10 ++++---- 4 files changed, 25 insertions(+), 24 deletions(-) delete mode 100644 src/Exception/DomainException.php create mode 100644 src/PriorityHandler/Exception/InvalidPriorityException.php diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index d30bbb7..630abaf 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -4,8 +4,8 @@ use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; -use ReputationVIP\QueueClient\Exception\DomainException; use ReputationVIP\QueueClient\Exception\InvalidArgumentException; +use ReputationVIP\QueueClient\PriorityHandler\Exception\InvalidPriorityException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use SplQueue; @@ -48,6 +48,7 @@ private function startsWith($haystack, $needle) * @throws InvalidArgumentException * @throws InvalidMessageException * @throws QueueAccessException + * @throws InvalidPriorityException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { @@ -78,7 +79,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds $splQueue = $this->queues[$queueName][$priority]; $splQueue->enqueue($new_message); } else { - throw new DomainException('Unknown priority: ' . $priority); + throw new InvalidPriorityException('Unknown priority: ' . $priority); } return $this; @@ -89,7 +90,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * * @throws InvalidArgumentException * @throws InvalidMessageException - * @throws DomainException + * @throws InvalidPriorityException */ public function deleteMessage($queueName, $message) { @@ -121,7 +122,7 @@ public function deleteMessage($queueName, $message) } } } else { - throw new DomainException('Unknown priority: ' . $message['priority']); + throw new InvalidPriorityException('Unknown priority: ' . $message['priority']); } return $this; @@ -132,7 +133,7 @@ public function deleteMessage($queueName, $message) * * @throws InvalidArgumentException * @throws QueueAccessException - * @throws DomainException + * @throws InvalidPriorityException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { @@ -180,7 +181,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } } } else { - throw new DomainException('Unknown priority: ' . $priority); + throw new InvalidPriorityException('Unknown priority: ' . $priority); } return $messages; @@ -191,7 +192,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * * @throws InvalidArgumentException * @throws QueueAccessException - * @throws DomainException + * @throws InvalidPriorityException */ public function isEmpty($queueName, $priority = null) { @@ -212,7 +213,7 @@ public function isEmpty($queueName, $priority = null) throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { - throw new DomainException('Unknown priority: ' . $priority); + throw new InvalidPriorityException('Unknown priority: ' . $priority); } /** @var SplQueue $splQueue */ @@ -225,7 +226,7 @@ public function isEmpty($queueName, $priority = null) * * @throws InvalidArgumentException * @throws QueueAccessException - * @throws DomainException + * @throws InvalidPriorityException */ public function getNumberMessages($queueName, $priority = null) { @@ -248,7 +249,7 @@ public function getNumberMessages($queueName, $priority = null) throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { - throw new DomainException('Unknown priority: ' . $priority); + throw new InvalidPriorityException('Unknown priority: ' . $priority); } foreach ($this->queues[$queueName][$priority] as $key => $message) { @@ -346,7 +347,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) * * @throws InvalidArgumentException * @throws QueueAccessException - * @throws DomainException + * @throws InvalidPriorityException */ public function purgeQueue($queueName, $priority = null) { @@ -367,7 +368,7 @@ public function purgeQueue($queueName, $priority = null) throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } if (!isset($this->queues[$queueName][$priority])) { - throw new DomainException('Unknown priority: ' . $priority); + throw new InvalidPriorityException('Unknown priority: ' . $priority); } $this->queues[$queueName][$priority] = new SplQueue(); diff --git a/src/Exception/DomainException.php b/src/Exception/DomainException.php deleted file mode 100644 index ab059b3..0000000 --- a/src/Exception/DomainException.php +++ /dev/null @@ -1,7 +0,0 @@ -aliases[$alias])) { @@ -269,7 +269,7 @@ public function addAlias($queueName, $alias) /** * @inheritdoc * - * @throws DomainException + * @throws QueueAliasException */ public function removeAlias($alias) { @@ -280,7 +280,7 @@ public function removeAlias($alias) unset($this->aliases[$alias]); } } else { - throw new DomainException('No alias found.'); + throw new QueueAliasException('No alias found.'); } return $this; } From 1981b16cd6c38fd6ef2717a93e80b2e11ede28fa Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Fri, 11 Mar 2016 10:46:03 +0100 Subject: [PATCH 30/51] Remove own InvalidArgumentException --- src/Adapter/FileAdapter.php | 51 +++++++++++----------- src/Adapter/MemoryAdapter.php | 41 +++++++++-------- src/Adapter/SQSAdapter.php | 49 ++++++++++----------- src/Exception/InvalidArgumentException.php | 7 --- src/QueueClient.php | 8 ++-- 5 files changed, 73 insertions(+), 83 deletions(-) delete mode 100644 src/Exception/InvalidArgumentException.php diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 8ac703f..b2b0987 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -4,7 +4,6 @@ use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; -use ReputationVIP\QueueClient\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\Exception\UnexpectedValueException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -45,13 +44,13 @@ class FileAdapter extends AbstractAdapter implements AdapterInterface * @param Finder $finder * @param LockHandlerFactoryInterface $lockHandlerFactory * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function __construct($repository, PriorityHandlerInterface $priorityHandler = null, Filesystem $fs = null, Finder $finder = null, LockHandlerFactoryInterface $lockHandlerFactory = null) { if (empty($repository)) { - throw new InvalidArgumentException('Argument repository empty or not defined.'); + throw new \InvalidArgumentException('Argument repository empty or not defined.'); } if (null === $fs) { @@ -251,14 +250,14 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidMessageException * @throws QueueAccessException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { @@ -348,21 +347,21 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (!is_numeric($nbMsg)) { - throw new InvalidArgumentException('Number of messages must be numeric.'); + throw new \InvalidArgumentException('Number of messages must be numeric.'); } if ($nbMsg <= 0 || $nbMsg > static::MAX_NB_MESSAGES) { - throw new InvalidArgumentException('Number of messages is not valid.'); + throw new \InvalidArgumentException('Number of messages is not valid.'); } if (null === $priority) { @@ -444,14 +443,14 @@ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0 /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidMessageException * @throws QueueAccessException */ public function deleteMessage($queueName, $message) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { @@ -482,14 +481,14 @@ public function deleteMessage($queueName, $message) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException * @throws UnexpectedValueException */ public function isEmpty($queueName, $priority = null) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (null === $priority) { @@ -516,7 +515,7 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException * @throws UnexpectedValueException */ @@ -525,7 +524,7 @@ public function getNumberMessages($queueName, $priority = null) $nbrMsg = 0; if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (null === $priority) { @@ -586,12 +585,12 @@ private function deleteQueueLock($queueName, $priority, $nbTries = 0) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function deleteQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); @@ -606,13 +605,13 @@ public function deleteQueue($queueName) * @param string $queueName * @param string $priority * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ private function createQueueLock($queueName, $priority) { if (strpos($queueName, ' ') !== false) { - throw new InvalidArgumentException('Queue name must not contain white spaces.'); + throw new \InvalidArgumentException('Queue name must not contain white spaces.'); } if ($this->fs->exists($this->getQueuePath($queueName, $priority))) { @@ -628,12 +627,12 @@ private function createQueueLock($queueName, $priority) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function createQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); @@ -647,16 +646,16 @@ public function createQueue($queueName) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function renameQueue($sourceQueueName, $targetQueueName) { if (empty($sourceQueueName)) { - throw new InvalidArgumentException('Source queue name empty or not defined.'); + throw new \InvalidArgumentException('Source queue name empty or not defined.'); } if (empty($targetQueueName)) { - throw new InvalidArgumentException('Target queue name empty or not defined.'); + throw new \InvalidArgumentException('Target queue name empty or not defined.'); } $this->createQueue($targetQueueName); @@ -675,14 +674,14 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException * @throws UnexpectedValueException */ public function purgeQueue($queueName, $priority = null) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (null === $priority) { diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index 630abaf..84aca94 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -4,7 +4,6 @@ use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; -use ReputationVIP\QueueClient\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\PriorityHandler\Exception\InvalidPriorityException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -45,7 +44,7 @@ private function startsWith($haystack, $needle) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidMessageException * @throws QueueAccessException * @throws InvalidPriorityException @@ -53,7 +52,7 @@ private function startsWith($haystack, $needle) public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { @@ -88,14 +87,14 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidMessageException * @throws InvalidPriorityException */ public function deleteMessage($queueName, $message) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { @@ -131,7 +130,7 @@ public function deleteMessage($queueName, $message) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException * @throws InvalidPriorityException */ @@ -140,7 +139,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) $messages = []; if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (null === $priority) { @@ -190,14 +189,14 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException * @throws InvalidPriorityException */ public function isEmpty($queueName, $priority = null) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (null === $priority) { @@ -224,7 +223,7 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException * @throws InvalidPriorityException */ @@ -233,7 +232,7 @@ public function getNumberMessages($queueName, $priority = null) $nbrMsg = 0; if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (null === $priority) { @@ -265,13 +264,13 @@ public function getNumberMessages($queueName, $priority = null) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function deleteQueue($queueName, $nb_try = 0) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (!isset($this->queues[$queueName])) { @@ -286,17 +285,17 @@ public function deleteQueue($queueName, $nb_try = 0) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function createQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (strpos($queueName, ' ') !== false) { - throw new InvalidArgumentException('Queue name must not contain white spaces.'); + throw new \InvalidArgumentException('Queue name must not contain white spaces.'); } if (isset($this->queues[$queueName])) { @@ -314,17 +313,17 @@ public function createQueue($queueName) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function renameQueue($sourceQueueName, $targetQueueName) { if (empty($sourceQueueName)) { - throw new InvalidArgumentException('Source queue name empty or not defined.'); + throw new \InvalidArgumentException('Source queue name empty or not defined.'); } if (empty($targetQueueName)) { - throw new InvalidArgumentException('Target queue name empty or not defined.'); + throw new \InvalidArgumentException('Target queue name empty or not defined.'); } if (!isset($this->queues[$sourceQueueName])) { @@ -345,14 +344,14 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException * @throws InvalidPriorityException */ public function purgeQueue($queueName, $priority = null) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (null === $priority) { diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index 6b0522e..bc6139c 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -6,7 +6,6 @@ use Aws\Sqs\SqsClient; use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; -use ReputationVIP\QueueClient\Exception\InvalidArgumentException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -58,14 +57,14 @@ public function __construct(SqsClient $sqsClient, PriorityHandlerInterface $prio /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidMessageException * @throws QueueAccessException */ public function addMessages($queueName, $messages, $priority = null) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (null === $priority) { @@ -111,14 +110,14 @@ public function addMessages($queueName, $messages, $priority = null) /** * @inheritdoc * - * @throws InvalidArgumentException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { @@ -147,7 +146,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function getMessages($queueName, $nbMsg = 1, $priority = null) @@ -167,14 +166,14 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (!is_numeric($nbMsg)) { - throw new InvalidArgumentException('Number of messages must be numeric.'); + throw new \InvalidArgumentException('Number of messages must be numeric.'); } if ($nbMsg <= 0 || $nbMsg > self::MAX_NB_MESSAGES) { - throw new InvalidArgumentException('Number of messages not valid.'); + throw new \InvalidArgumentException('Number of messages not valid.'); } try { @@ -202,14 +201,14 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidMessageException * @throws QueueAccessException */ public function deleteMessage($queueName, $message) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } if (empty($message)) { @@ -241,7 +240,7 @@ public function deleteMessage($queueName, $message) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function isEmpty($queueName, $priority = null) @@ -256,7 +255,7 @@ public function isEmpty($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } try { @@ -280,7 +279,7 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function getNumberMessages($queueName, $priority = null) @@ -297,7 +296,7 @@ public function getNumberMessages($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } try { @@ -321,13 +320,13 @@ public function getNumberMessages($queueName, $priority = null) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function deleteQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); @@ -349,13 +348,13 @@ public function deleteQueue($queueName) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function createQueue($queueName) { if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } $priorities = $this->priorityHandler->getAll(); @@ -377,16 +376,16 @@ public function createQueue($queueName) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function renameQueue($sourceQueueName, $targetQueueName) { if (empty($sourceQueueName)) { - throw new InvalidArgumentException('Source queue name empty or not defined.'); + throw new \InvalidArgumentException('Source queue name empty or not defined.'); } if (empty($targetQueueName)) { - throw new InvalidArgumentException('Target queue name empty or not defined.'); + throw new \InvalidArgumentException('Target queue name empty or not defined.'); } $this->createQueue($targetQueueName); @@ -410,7 +409,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws QueueAccessException */ public function purgeQueue($queueName, $priority = null) @@ -426,7 +425,7 @@ public function purgeQueue($queueName, $priority = null) } if (empty($queueName)) { - throw new InvalidArgumentException('Queue name empty or not defined.'); + throw new \InvalidArgumentException('Queue name empty or not defined.'); } try { diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php deleted file mode 100644 index edffe25..0000000 --- a/src/Exception/InvalidArgumentException.php +++ /dev/null @@ -1,7 +0,0 @@ -listQueues(); if (empty($queueName)) { - throw new InvalidArgumentException('Queue name is empty.'); + throw new \InvalidArgumentException('Queue name is empty.'); } if (empty($alias)) { - throw new InvalidArgumentException('Alias is empty.'); + throw new QueueAliasException('Alias is empty.'); } if (!in_array($queueName, $listQueues)) { From 74f10773e9a5fa702057f14b4c635ebf47e1a239 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Fri, 11 Mar 2016 10:48:17 +0100 Subject: [PATCH 31/51] Remove own RangeException --- src/Exception/RangeException.php | 7 ------- src/PriorityHandler/StandardPriorityHandler.php | 5 ++--- 2 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 src/Exception/RangeException.php diff --git a/src/Exception/RangeException.php b/src/Exception/RangeException.php deleted file mode 100644 index 046fcc4..0000000 --- a/src/Exception/RangeException.php +++ /dev/null @@ -1,7 +0,0 @@ -= count($this->priorities)) { - throw new RangeException('Level index out of range.'); + throw new \RangeException('Level index out of range.'); } return $this->priorities[$index]; } From 725bfe02ce2dccf0fef514134fc396ecac87f091 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Fri, 11 Mar 2016 10:50:31 +0100 Subject: [PATCH 32/51] Rename LevelException into PriorityLevelException --- ...ception.php => PriorityLevelException.php} | 2 +- .../StandardPriorityHandler.php | 42 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) rename src/PriorityHandler/Exception/{LevelException.php => PriorityLevelException.php} (59%) diff --git a/src/PriorityHandler/Exception/LevelException.php b/src/PriorityHandler/Exception/PriorityLevelException.php similarity index 59% rename from src/PriorityHandler/Exception/LevelException.php rename to src/PriorityHandler/Exception/PriorityLevelException.php index 897c360..472e8f4 100644 --- a/src/PriorityHandler/Exception/LevelException.php +++ b/src/PriorityHandler/Exception/PriorityLevelException.php @@ -4,4 +4,4 @@ use ReputationVIP\QueueClient\Exception\QueueClientException; -class LevelException extends \RuntimeException implements QueueClientException {} +class PriorityLevelException extends \RuntimeException implements QueueClientException {} diff --git a/src/PriorityHandler/StandardPriorityHandler.php b/src/PriorityHandler/StandardPriorityHandler.php index a3b275e..8bdd570 100644 --- a/src/PriorityHandler/StandardPriorityHandler.php +++ b/src/PriorityHandler/StandardPriorityHandler.php @@ -2,7 +2,7 @@ namespace ReputationVIP\QueueClient\PriorityHandler; -use ReputationVIP\QueueClient\PriorityHandler\Exception\LevelException; +use ReputationVIP\QueueClient\PriorityHandler\Exception\PriorityLevelException; class StandardPriorityHandler implements PriorityHandlerInterface { @@ -19,12 +19,12 @@ class StandardPriorityHandler implements PriorityHandlerInterface /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function add($name) { if (in_array($name, $this->priorities)) { - throw new LevelException('Level ' . $name . ' already exists.'); + throw new PriorityLevelException('Level ' . $name . ' already exists.'); } $this->priorities[] = $name; return $this; @@ -33,13 +33,13 @@ public function add($name) /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function remove($name) { $key = array_search($name, $this->priorities); if (false === $key) { - throw new LevelException("Level " . $name . " doesn't exist."); + throw new PriorityLevelException("Level " . $name . " doesn't exist."); } $default = $this->getDefault(); unset($this->priorities[$key]); @@ -55,14 +55,14 @@ public function remove($name) /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function addBefore($addName, $beforeName) { $key = array_search($beforeName, $this->priorities); if (false !== $key) { if (in_array($addName, $this->priorities)) { - throw new LevelException('Level ' . $addName . ' already exists.'); + throw new PriorityLevelException('Level ' . $addName . ' already exists.'); } $default = $this->getDefault(); if (0 === $key) { @@ -75,7 +75,7 @@ public function addBefore($addName, $beforeName) } $this->setDefault($default); } else { - throw new LevelException("Level " . $beforeName . " doesn't exist."); + throw new PriorityLevelException("Level " . $beforeName . " doesn't exist."); } return $this; } @@ -83,7 +83,7 @@ public function addBefore($addName, $beforeName) /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function removeBefore($beforeName) { @@ -101,7 +101,7 @@ public function removeBefore($beforeName) } } } else { - throw new LevelException("Level " . $beforeName . " doesn't exist."); + throw new PriorityLevelException("Level " . $beforeName . " doesn't exist."); } return $this; } @@ -109,14 +109,14 @@ public function removeBefore($beforeName) /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function addAfter($addName, $afterName) { $key = array_search($afterName, $this->priorities); if (false !== $key) { if (in_array($addName, $this->priorities)) { - throw new LevelException('Level ' . $addName . ' already exists.'); + throw new PriorityLevelException('Level ' . $addName . ' already exists.'); } $default = $this->getDefault(); if ($key === (count($this->priorities) - 1)) { @@ -129,7 +129,7 @@ public function addAfter($addName, $afterName) } $this->setDefault($default); } else { - throw new LevelException("Level " . $afterName . " doesn't exist."); + throw new PriorityLevelException("Level " . $afterName . " doesn't exist."); } return $this; } @@ -137,7 +137,7 @@ public function addAfter($addName, $afterName) /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function removeAfter($afterName) { @@ -155,7 +155,7 @@ public function removeAfter($afterName) } } } else { - throw new LevelException("Level " . $afterName . " doesn't exist."); + throw new PriorityLevelException("Level " . $afterName . " doesn't exist."); } return $this; } @@ -210,7 +210,7 @@ public function getDefault() /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function setDefault($newDefault) { @@ -221,7 +221,7 @@ public function setDefault($newDefault) if (false !== $key) { $this->defaultIndex = $key; } else { - throw new LevelException("Level " . $newDefault . " doesn't exist."); + throw new PriorityLevelException("Level " . $newDefault . " doesn't exist."); } return $this; @@ -252,14 +252,14 @@ public function getLowest() /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function getBefore($beforeName) { $key = array_search($beforeName, $this->priorities); if (false === $key) { - throw new LevelException("Level " . $beforeName . " doesn't exist."); + throw new PriorityLevelException("Level " . $beforeName . " doesn't exist."); } if (0 === $key) { @@ -272,14 +272,14 @@ public function getBefore($beforeName) /** * @inheritdoc * - * @throws LevelException + * @throws PriorityLevelException */ public function getAfter($afterName) { $key = array_search($afterName, $this->priorities); if (false === $key) { - throw new LevelException("Level " . $afterName . " doesn't exist."); + throw new PriorityLevelException("Level " . $afterName . " doesn't exist."); } if (count($this->priorities) - 1 === $key) { From f6f44c964847570f34bca1692c70ce9cda07c5d7 Mon Sep 17 00:00:00 2001 From: Quentin Fayet Date: Fri, 11 Mar 2016 10:55:24 +0100 Subject: [PATCH 33/51] Get rid of own UnexpectedValueException --- src/Adapter/FileAdapter.php | 34 ++++++++++------------ src/Exception/UnexpectedValueException.php | 7 ----- 2 files changed, 16 insertions(+), 25 deletions(-) delete mode 100644 src/Exception/UnexpectedValueException.php diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index b2b0987..3d0039d 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -4,7 +4,6 @@ use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; -use ReputationVIP\QueueClient\Exception\UnexpectedValueException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use ReputationVIP\QueueClient\Utils\LockHandlerFactory; @@ -121,7 +120,6 @@ private function getQueuePath($queueName, $priority) * @return array * * @throws QueueAccessException - * @throws UnexpectedValueException * @throws \Exception */ private function readQueueFromFile($queueName, $priority, $nbTries = 0) @@ -145,7 +143,7 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) } } if (empty($content)) { - throw new UnexpectedValueException('Fail to get content from file ' . $queueFilePath); + throw new QueueAccessException('Fail to get content from file ' . $queueFilePath); } $queue = json_decode($content, true); } catch (\Exception $e) { @@ -200,7 +198,7 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) * @return AdapterInterface * * @throws QueueAccessException - * @throws UnexpectedValueException + * @throws \UnexpectedValueException * @throws \Exception */ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $delaySeconds = 0) @@ -224,11 +222,11 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ } } if (empty($content)) { - throw new UnexpectedValueException('Fail to get content from file ' . $queueFilePath); + throw new QueueAccessException('Fail to get content from file ' . $queueFilePath); } $queue = json_decode($content, true); if (!(isset($queue['queue']))) { - throw new UnexpectedValueException('Queue content bad format.'); + throw new \UnexpectedValueException('Queue content bad format.'); } $new_message = [ 'id' => uniqid($queueName . $priority, true), @@ -286,7 +284,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * @return array * * @throws QueueAccessException - * @throws UnexpectedValueException + * @throws \UnexpectedValueException * @throws \Exception */ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) @@ -311,11 +309,11 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) } } if (empty($content)) { - throw new UnexpectedValueException('Fail to get content from file ' . $queueFilePath); + throw new QueueAccessException('Fail to get content from file ' . $queueFilePath); } $queue = json_decode($content, true); if (!isset($queue['queue'])) { - throw new UnexpectedValueException('Queue content bad format.'); + throw new \UnexpectedValueException('Queue content bad format.'); } foreach ($queue['queue'] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; @@ -394,7 +392,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * @return AdapterInterface * * @throws QueueAccessException - * @throws UnexpectedValueException + * @throws \UnexpectedValueException * @throws \Exception */ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0) @@ -417,11 +415,11 @@ private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0 } } if (empty($content)) { - throw new UnexpectedValueException('Fail to get content from file ' . $queueFilePath); + throw new QueueAccessException('Fail to get content from file ' . $queueFilePath); } $queue = json_decode($content, true); if (!isset($queue['queue'])) { - throw new UnexpectedValueException('Queue content bad format.'); + throw new \UnexpectedValueException('Queue content bad format.'); } foreach ($queue['queue'] as $key => $messageIterator) { if ($messageIterator['id'] === $message['id']) { @@ -483,7 +481,7 @@ public function deleteMessage($queueName, $message) * * @throws \InvalidArgumentException * @throws QueueAccessException - * @throws UnexpectedValueException + * @throws \UnexpectedValueException */ public function isEmpty($queueName, $priority = null) { @@ -506,7 +504,7 @@ public function isEmpty($queueName, $priority = null) $queue = $this->readQueueFromFile($queueName, $priority); if (!(isset($queue['queue']))) { - throw new UnexpectedValueException('Queue content bad format.'); + throw new \UnexpectedValueException('Queue content bad format.'); } return count($queue['queue']) > 0 ? false : true; @@ -517,7 +515,7 @@ public function isEmpty($queueName, $priority = null) * * @throws \InvalidArgumentException * @throws QueueAccessException - * @throws UnexpectedValueException + * @throws \UnexpectedValueException */ public function getNumberMessages($queueName, $priority = null) { @@ -542,7 +540,7 @@ public function getNumberMessages($queueName, $priority = null) $queue = $this->readQueueFromFile($queueName, $priority); if (!(isset($queue['queue']))) { - throw new UnexpectedValueException('Queue content bad format.'); + throw new \UnexpectedValueException('Queue content bad format.'); } foreach ($queue['queue'] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; @@ -676,7 +674,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) * * @throws \InvalidArgumentException * @throws QueueAccessException - * @throws UnexpectedValueException + * @throws \UnexpectedValueException */ public function purgeQueue($queueName, $priority = null) { @@ -699,7 +697,7 @@ public function purgeQueue($queueName, $priority = null) $queue = $this->readQueueFromFile($queueName, $priority); if (!isset($queue['queue'])) { - throw new UnexpectedValueException('Queue content bad format.'); + throw new \UnexpectedValueException('Queue content bad format.'); } $queue['queue'] = []; $this->writeQueueInFile($queueName, $priority, $queue); diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php deleted file mode 100644 index 5050b40..0000000 --- a/src/Exception/UnexpectedValueException.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Fri, 4 Mar 2016 16:12:36 +0100 Subject: [PATCH 34/51] change priority type --- composer.json | 3 +- coverage.xml | 9 + src/Adapter/AbstractAdapter.php | 9 +- src/Adapter/AdapterInterface.php | 21 +- src/Adapter/BeanstalkdAdapter.php | 132 ++++++ src/Adapter/FileAdapter.php | 61 +-- src/Adapter/MemoryAdapter.php | 51 +-- src/Adapter/NullAdapter.php | 11 +- src/Adapter/SQSAdapter.php | 29 +- src/PriorityHandler/Priority/Priority.php | 82 ++++ .../PriorityHandlerInterface.php | 76 ++-- .../StandardPriorityHandler.php | 268 +++++------ .../ThreeLevelPriorityHandler.php | 25 +- src/QueueClientInterface.php | 13 +- tests/units/Adapter/FileAdapter.php | 70 +-- tests/units/Adapter/MemoryAdapter.php | 12 +- tests/units/Adapter/SQSAdapter.php | 2 +- .../StandardPriorityHandler.php | 416 ------------------ 18 files changed, 521 insertions(+), 769 deletions(-) create mode 100644 coverage.xml create mode 100644 src/Adapter/BeanstalkdAdapter.php create mode 100644 src/PriorityHandler/Priority/Priority.php delete mode 100644 tests/units/PriorityHandler/StandardPriorityHandler.php diff --git a/composer.json b/composer.json index fd73bd7..8b1edb8 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "require": { "symfony/filesystem": ">=2.7", "symfony/finder": ">=2.7", - "aws/aws-sdk-php": ">=2.7" + "aws/aws-sdk-php": ">=2.7", + "pda/pheanstalk": "^3.1" }, "require-dev": { "atoum/atoum": "~2", diff --git a/coverage.xml b/coverage.xml new file mode 100644 index 0000000..ee32d25 --- /dev/null +++ b/coverage.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 5af26a3..60f0cef 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -2,6 +2,7 @@ namespace ReputationVIP\QueueClient\Adapter; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\QueueClientInterface; class AbstractAdapter @@ -10,11 +11,11 @@ class AbstractAdapter /** * @param string $queueName * @param array $messages - * @param string $priority + * @param Priority $priority * * @return QueueClientInterface */ - public function addMessages($queueName, $messages, $priority = null) + public function addMessages($queueName, $messages, Priority $priority = null) { foreach ($messages as $message) { $this->addMessage($queueName, $message, $priority); @@ -26,12 +27,12 @@ public function addMessages($queueName, $messages, $priority = null) /** * @param string $queueName * @param mixed $message - * @param string $priority + * @param Priority $priority * @param int $delaySeconds * * @return AdapterInterface */ - public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) + public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0) { return $this; } diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 8335992..78bc8fa 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -2,6 +2,7 @@ namespace ReputationVIP\QueueClient\Adapter; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; interface AdapterInterface @@ -9,21 +10,21 @@ interface AdapterInterface /** * @param string $queueName * @param mixed $message - * @param string $priority + * @param Priority $priority * @param int $delaySeconds * * @return AdapterInterface */ - public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0); + public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0); /** * @param string $queueName - * @param string $priority * @param int $nbMsg + * @param Priority $priority * * @return array */ - public function getMessages($queueName, $nbMsg = 1, $priority = null); + public function getMessages($queueName, $nbMsg = 1, Priority $priority = null); /** * @param string $queueName @@ -35,19 +36,19 @@ public function deleteMessage($queueName, $message); /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @return bool */ - public function isEmpty($queueName, $priority = null); + public function isEmpty($queueName, Priority $priority = null); /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @return int */ - public function getNumberMessages($queueName, $priority = null); + public function getNumberMessages($queueName, Priority $priority = null); /** * @param string $queueName @@ -73,11 +74,11 @@ public function renameQueue($sourceQueueName, $targetQueueName); /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @return AdapterInterface */ - public function purgeQueue($queueName, $priority = null); + public function purgeQueue($queueName, Priority $priority = null); /** * @param string $prefix diff --git a/src/Adapter/BeanstalkdAdapter.php b/src/Adapter/BeanstalkdAdapter.php new file mode 100644 index 0000000..c17d8d6 --- /dev/null +++ b/src/Adapter/BeanstalkdAdapter.php @@ -0,0 +1,132 @@ +pheanstalkInterface = $pheanstalkInterface; + $this->priorityHandler = $priorityHandler; + } + + /** + * @param string $queueName + * @param mixed $message + * @param Priority $priority + * + * @return AdapterInterface + */ + public function addMessage($queueName, $message, Priority $priority = null) + { + + return $this; + } + + /** + * @inheritdoc + */ + public function getMessages($queueName, $nbMsg = 1, Priority $priority = null) + { + return []; + } + + /** + * @inheritdoc + */ + public function deleteMessage($queueName, $message, Priority $priority = null) + { + return $this; + } + + /** + * @inheritdoc + */ + public function isEmpty($queueName, Priority $priority = null) + { + return true; + } + + /** + * @inheritdoc + */ + public function getNumberMessages($queueName, Priority $priority = null) + { + return 0; + } + + /** + * @inheritdoc + */ + public function deleteQueue($queueName) + { + return $this; + } + + /** + * @inheritdoc + */ + public function createQueue($queueName) + { + return $this; + } + + /** + * @inheritdoc + */ + public function renameQueue($sourceQueueName, $targetQueueName) + { + return $this; + } + + /** + * @inheritdoc + */ + public function purgeQueue($queueName, Priority $priority = null) + { + return $this; + } + + /** + * @inheritdoc + */ + public function listQueues($prefix = '') + { + return []; + } + + /** + * @inheritdoc + */ + public function getPriorityHandler() + { + return $this->priorityHandler; + } +} \ No newline at end of file diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 3d0039d..254f5e3 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -4,6 +4,7 @@ use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use ReputationVIP\QueueClient\Utils\LockHandlerFactory; @@ -99,22 +100,22 @@ private function startsWith($haystack, $needle) /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @return string */ - private function getQueuePath($queueName, $priority) + private function getQueuePath($queueName, Priority $priority) { $prioritySuffix = ''; - if ('' !== $priority) { - $prioritySuffix = static::PRIORITY_SEPARATOR . $priority; + if ('' !== $priority->getName()) { + $prioritySuffix = static::PRIORITY_SEPARATOR . $priority->getName(); } return (rtrim($this->repository, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $queueName . $prioritySuffix . '.' . static::QUEUE_FILE_EXTENSION); } /** * @param string $queueName - * @param string $priority + * @param Priority $priority * @param int $nbTries * * @return array @@ -122,7 +123,7 @@ private function getQueuePath($queueName, $priority) * @throws QueueAccessException * @throws \Exception */ - private function readQueueFromFile($queueName, $priority, $nbTries = 0) + private function readQueueFromFile($queueName, Priority $priority, $nbTries = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); @@ -157,7 +158,7 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) /** * @param string $queueName - * @param string $priority + * @param Priority $priority * @param array $queue * @param int $nbTries * @@ -166,7 +167,7 @@ private function readQueueFromFile($queueName, $priority, $nbTries = 0) * @throws QueueAccessException * @throws \Exception */ - private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) + private function writeQueueInFile($queueName, Priority $priority, $queue, $nbTries = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); @@ -191,7 +192,7 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) /** * @param string $queueName * @param string $message - * @param string $priority + * @param Priority $priority * @param int $nbTries * @param int $delaySeconds * @@ -201,7 +202,7 @@ private function writeQueueInFile($queueName, $priority, $queue, $nbTries = 0) * @throws \UnexpectedValueException * @throws \Exception */ - private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $delaySeconds = 0) + private function addMessageLock($queueName, $message, Priority $priority, $nbTries = 0, $delaySeconds = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); @@ -229,7 +230,7 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ throw new \UnexpectedValueException('Queue content bad format.'); } $new_message = [ - 'id' => uniqid($queueName . $priority, true), + 'id' => uniqid($queueName . $priority->getLevel(), true), 'time-in-flight' => null, 'delayed-until' => time() + $delaySeconds, 'Body' => serialize($message), @@ -252,7 +253,7 @@ private function addMessageLock($queueName, $message, $priority, $nbTries = 0, $ * @throws InvalidMessageException * @throws QueueAccessException */ - public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) + public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -277,7 +278,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds /** * @param string $queueName - * @param string $priority + * @param Priority $priority * @param int $nbMsg * @param int $nbTries * @@ -287,7 +288,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * @throws \UnexpectedValueException * @throws \Exception */ - private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) + private function getMessagesLock($queueName, $nbMsg, Priority $priority, $nbTries = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); @@ -323,7 +324,7 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) $queue['queue'][$key]['time-in-flight'] = time(); $message['time-in-flight'] = time(); $message['Body'] = unserialize($message['Body']); - $message['priority'] = $priority; + $message['priority'] = $priority->getLevel(); $messages[] = $message; --$nbMsg; if (0 === $nbMsg) { @@ -348,7 +349,7 @@ private function getMessagesLock($queueName, $nbMsg, $priority, $nbTries = 0) * @throws \InvalidArgumentException * @throws QueueAccessException */ - public function getMessages($queueName, $nbMsg = 1, $priority = null) + public function getMessages($queueName, $nbMsg = 1, Priority $priority = null) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -386,7 +387,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) /** * @param string $queueName * @param string $message - * @param string $priority + * @param Priority $priority * @param int $nbTries * * @return AdapterInterface @@ -395,7 +396,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * @throws \UnexpectedValueException * @throws \Exception */ - private function deleteMessageLock($queueName, $message, $priority, $nbTries = 0) + private function deleteMessageLock($queueName, $message, Priority $priority, $nbTries = 0) { $queueFilePath = $this->getQueuePath($queueName, $priority); $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); @@ -467,11 +468,13 @@ public function deleteMessage($queueName, $message) throw new InvalidMessageException('Message priority not found in message.'); } - if (!$this->fs->exists($this->getQueuePath($queueName, $message['priority']))) { - throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); + $priority = $this->priorityHandler->getPriorityByLevel($message['priority']); + + if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { + throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before use it."); } - $this->deleteMessageLock($queueName, $message, $message['priority']); + $this->deleteMessageLock($queueName, $message, $priority); return $this; } @@ -483,7 +486,7 @@ public function deleteMessage($queueName, $message) * @throws QueueAccessException * @throws \UnexpectedValueException */ - public function isEmpty($queueName, $priority = null) + public function isEmpty($queueName, Priority $priority = null) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -517,7 +520,7 @@ public function isEmpty($queueName, $priority = null) * @throws QueueAccessException * @throws \UnexpectedValueException */ - public function getNumberMessages($queueName, $priority = null) + public function getNumberMessages($queueName, Priority $priority = null) { $nbrMsg = 0; @@ -554,13 +557,13 @@ public function getNumberMessages($queueName, $priority = null) /** * @param string $queueName - * @param string $priority + * @param Priority $priority * @param int $nbTries * * @return AdapterInterface * @throws QueueAccessException */ - private function deleteQueueLock($queueName, $priority, $nbTries = 0) + private function deleteQueueLock($queueName, Priority $priority, $nbTries = 0) { if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); @@ -601,12 +604,12 @@ public function deleteQueue($queueName) /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @throws \InvalidArgumentException * @throws QueueAccessException */ - private function createQueueLock($queueName, $priority) + private function createQueueLock($queueName, Priority $priority) { if (strpos($queueName, ' ') !== false) { throw new \InvalidArgumentException('Queue name must not contain white spaces.'); @@ -676,7 +679,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) * @throws QueueAccessException * @throws \UnexpectedValueException */ - public function purgeQueue($queueName, $priority = null) + public function purgeQueue($queueName, Priority $priority = null) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -723,7 +726,7 @@ public function listQueues($prefix = '') $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { if (!empty($priority)) { - $implode = str_replace(static::PRIORITY_SEPARATOR . $priority, '', $implode); + $implode = str_replace(static::PRIORITY_SEPARATOR . $priority->getName(), '', $implode); } } $result[] = $implode; diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index 84aca94..4998525 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -2,6 +2,7 @@ namespace ReputationVIP\QueueClient\Adapter; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; use ReputationVIP\QueueClient\PriorityHandler\Exception\InvalidPriorityException; @@ -49,7 +50,7 @@ private function startsWith($haystack, $needle) * @throws QueueAccessException * @throws InvalidPriorityException */ - public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) + public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -67,18 +68,18 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } - if (isset($this->queues[$queueName][$priority])) { + if (isset($this->queues[$queueName][$priority->getName()])) { $new_message = [ - 'id' => uniqid($queueName . $priority, true), + 'id' => uniqid($queueName . $priority->getName(), true), 'time-in-flight' => null, 'delayed-until' => time() + $delaySeconds, 'Body' => serialize($message), ]; /** @var SplQueue $splQueue */ - $splQueue = $this->queues[$queueName][$priority]; + $splQueue = $this->queues[$queueName][$priority->getName()]; $splQueue->enqueue($new_message); } else { - throw new InvalidPriorityException('Unknown priority: ' . $priority); + throw new InvalidPriorityException('Unknown priority: ' . $priority->getName()); } return $this; @@ -134,7 +135,7 @@ public function deleteMessage($queueName, $message) * @throws QueueAccessException * @throws InvalidPriorityException */ - public function getMessages($queueName, $nbMsg = 1, $priority = null) + public function getMessages($queueName, $nbMsg = 1, Priority $priority = null) { $messages = []; @@ -160,18 +161,18 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } - if (isset($this->queues[$queueName][$priority])) { - foreach ($this->queues[$queueName][$priority] as $key => $message) { + if (isset($this->queues[$queueName][$priority->getName()])) { + foreach ($this->queues[$queueName][$priority->getName()] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; if ((null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) && $message['delayed-until'] <= time() ) { - $splQueueContent = $this->queues[$queueName][$priority][$key]; + $splQueueContent = $this->queues[$queueName][$priority->getName()][$key]; $splQueueContent['time-in-flight'] = time(); - $this->queues[$queueName][$priority][$key] = $splQueueContent; + $this->queues[$queueName][$priority->getName()][$key] = $splQueueContent; $message['time-in-flight'] = time(); $message['Body'] = unserialize($message['Body']); - $message['priority'] = $priority; + $message['priority'] = $priority->getName(); $messages[] = $message; --$nbMsg; if (0 === $nbMsg) { @@ -180,7 +181,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } } } else { - throw new InvalidPriorityException('Unknown priority: ' . $priority); + throw new InvalidPriorityException('Unknown priority: ' . $priority->getName()); } return $messages; @@ -193,7 +194,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) * @throws QueueAccessException * @throws InvalidPriorityException */ - public function isEmpty($queueName, $priority = null) + public function isEmpty($queueName, Priority $priority = null) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -211,12 +212,12 @@ public function isEmpty($queueName, $priority = null) if (!isset($this->queues[$queueName])) { throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } - if (!isset($this->queues[$queueName][$priority])) { - throw new InvalidPriorityException('Unknown priority: ' . $priority); + if (!isset($this->queues[$queueName][$priority->getName()])) { + throw new InvalidPriorityException('Unknown priority: ' . $priority->getName()); } /** @var SplQueue $splQueue */ - $splQueue = $this->queues[$queueName][$priority]; + $splQueue = $this->queues[$queueName][$priority->getName()]; return $splQueue->isEmpty(); } @@ -227,7 +228,7 @@ public function isEmpty($queueName, $priority = null) * @throws QueueAccessException * @throws InvalidPriorityException */ - public function getNumberMessages($queueName, $priority = null) + public function getNumberMessages($queueName, Priority $priority = null) { $nbrMsg = 0; @@ -247,11 +248,11 @@ public function getNumberMessages($queueName, $priority = null) if (!isset($this->queues[$queueName])) { throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } - if (!isset($this->queues[$queueName][$priority])) { - throw new InvalidPriorityException('Unknown priority: ' . $priority); + if (!isset($this->queues[$queueName][$priority->getName()])) { + throw new InvalidPriorityException('Unknown priority: ' . $priority->getName()); } - foreach ($this->queues[$queueName][$priority] as $key => $message) { + foreach ($this->queues[$queueName][$priority->getName()] as $key => $message) { $timeDiff = time() - $message['time-in-flight']; if (null === $message['time-in-flight'] || $timeDiff > self::MAX_TIME_IN_FLIGHT) { ++$nbrMsg; @@ -304,7 +305,7 @@ public function createQueue($queueName) $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { - $this->queues[$queueName][$priority] = new SplQueue(); + $this->queues[$queueName][$priority->getName()] = new SplQueue(); } return $this; @@ -348,7 +349,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) * @throws QueueAccessException * @throws InvalidPriorityException */ - public function purgeQueue($queueName, $priority = null) + public function purgeQueue($queueName, Priority $priority = null) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -366,11 +367,11 @@ public function purgeQueue($queueName, $priority = null) if (!isset($this->queues[$queueName])) { throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } - if (!isset($this->queues[$queueName][$priority])) { - throw new InvalidPriorityException('Unknown priority: ' . $priority); + if (!isset($this->queues[$queueName][$priority->getName()])) { + throw new InvalidPriorityException('Unknown priority: ' . $priority->getName()); } - $this->queues[$queueName][$priority] = new SplQueue(); + $this->queues[$queueName][$priority->getName()] = new SplQueue(); return $this; } diff --git a/src/Adapter/NullAdapter.php b/src/Adapter/NullAdapter.php index f1b904d..9077224 100644 --- a/src/Adapter/NullAdapter.php +++ b/src/Adapter/NullAdapter.php @@ -2,6 +2,7 @@ namespace ReputationVIP\QueueClient\Adapter; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; @@ -26,7 +27,7 @@ public function __construct(PriorityHandlerInterface $priorityHandler = null) /** * @inheritdoc */ - public function getMessages($queueName, $nbMsg = 1, $priority = null) + public function getMessages($queueName, $nbMsg = 1, Priority $priority = null) { return []; } @@ -34,7 +35,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) /** * @inheritdoc */ - public function deleteMessage($queueName, $message, $priority = null) + public function deleteMessage($queueName, $message, Priority $priority = null) { return $this; } @@ -42,7 +43,7 @@ public function deleteMessage($queueName, $message, $priority = null) /** * @inheritdoc */ - public function isEmpty($queueName, $priority = null) + public function isEmpty($queueName, Priority $priority = null) { return true; } @@ -50,7 +51,7 @@ public function isEmpty($queueName, $priority = null) /** * @inheritdoc */ - public function getNumberMessages($queueName, $priority = null) + public function getNumberMessages($queueName, Priority $priority = null) { return 0; } @@ -82,7 +83,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) /** * @inheritdoc */ - public function purgeQueue($queueName, $priority = null) + public function purgeQueue($queueName, Priority $priority = null) { return $this; } diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index bc6139c..cad24e9 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -4,6 +4,7 @@ use Aws\Sqs\Exception\SqsException; use Aws\Sqs\SqsClient; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\Adapter\Exception\InvalidMessageException; use ReputationVIP\QueueClient\Adapter\Exception\QueueAccessException; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; @@ -25,14 +26,14 @@ class SQSAdapter extends AbstractAdapter implements AdapterInterface /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @return string */ - private function getQueueNameWithPrioritySuffix($queueName, $priority) { + private function getQueueNameWithPrioritySuffix($queueName, Priority $priority) { $prioritySuffix = ''; - if ('' !== $priority) { - $prioritySuffix = static::PRIORITY_SEPARATOR . $priority; + if ('' !== $priority->getName()) { + $prioritySuffix = static::PRIORITY_SEPARATOR . $priority->getName(); } return $queueName . $prioritySuffix; @@ -61,7 +62,7 @@ public function __construct(SqsClient $sqsClient, PriorityHandlerInterface $prio * @throws InvalidMessageException * @throws QueueAccessException */ - public function addMessages($queueName, $messages, $priority = null) + public function addMessages($queueName, $messages, Priority $priority = null) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -114,7 +115,7 @@ public function addMessages($queueName, $messages, $priority = null) * @throws \InvalidArgumentException * @throws QueueAccessException */ - public function addMessage($queueName, $message, $priority = null, $delaySeconds = 0) + public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0) { if (empty($queueName)) { throw new \InvalidArgumentException('Queue name empty or not defined.'); @@ -149,7 +150,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds * @throws \InvalidArgumentException * @throws QueueAccessException */ - public function getMessages($queueName, $nbMsg = 1, $priority = null) + public function getMessages($queueName, $nbMsg = 1, Priority $priority = null) { if (null === $priority) { $priorities = $this->priorityHandler->getAll(); @@ -192,7 +193,7 @@ public function getMessages($queueName, $nbMsg = 1, $priority = null) } foreach ($messages as $messageId => $message) { $messages[$messageId]['Body'] = unserialize($message['Body']); - $messages[$messageId]['priority'] = $priority; + $messages[$messageId]['priority'] = $priority->getLevel(); } return $messages; @@ -224,8 +225,10 @@ public function deleteMessage($queueName, $message) throw new InvalidMessageException('Priority not found in message.'); } + $priority = $this->priorityHandler->getPriorityByLevel($message['priority']); + try { - $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $message['priority'])])->get('QueueUrl'); + $queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl'); $this->sqsClient->deleteMessage([ 'QueueUrl' => $queueUrl, 'ReceiptHandle' => $message['ReceiptHandle'], @@ -243,7 +246,7 @@ public function deleteMessage($queueName, $message) * @throws \InvalidArgumentException * @throws QueueAccessException */ - public function isEmpty($queueName, $priority = null) + public function isEmpty($queueName, Priority $priority = null) { if (null === $priority) { $priorities = $this->priorityHandler->getAll(); @@ -282,7 +285,7 @@ public function isEmpty($queueName, $priority = null) * @throws \InvalidArgumentException * @throws QueueAccessException */ - public function getNumberMessages($queueName, $priority = null) + public function getNumberMessages($queueName, Priority $priority = null) { $nbrMsg = 0; @@ -412,7 +415,7 @@ public function renameQueue($sourceQueueName, $targetQueueName) * @throws \InvalidArgumentException * @throws QueueAccessException */ - public function purgeQueue($queueName, $priority = null) + public function purgeQueue($queueName, Priority $priority = null) { if (null === $priority) { $priorities = $this->priorityHandler->getAll(); @@ -469,7 +472,7 @@ public function listQueues($prefix = '') $priorities = $this->priorityHandler->getAll(); foreach ($priorities as $priority) { if (!empty($priority)) { - $result = str_replace(static::PRIORITY_SEPARATOR . $priority, '', $result); + $result = str_replace(static::PRIORITY_SEPARATOR . $priority->getName(), '', $result); } } $listQueues[] = $result; diff --git a/src/PriorityHandler/Priority/Priority.php b/src/PriorityHandler/Priority/Priority.php new file mode 100644 index 0000000..9ba9613 --- /dev/null +++ b/src/PriorityHandler/Priority/Priority.php @@ -0,0 +1,82 @@ +name = $name; + $this->level = $level; + $this->priorityHandler = $priorityHandler; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @return integer + */ + public function getLevel() + { + return $this->level; + } + + + /** + * @return PriorityHandlerInterface + */ + public function getPriorityHandler() { + return $this->priorityHandler; + } + + /** + * @param PriorityHandlerInterface $priorityHandler + * @return $this + */ + public function setPriorityHandler(PriorityHandlerInterface $priorityHandler) { + $this->priorityHandler = $priorityHandler; + + return $this; + } + + /** + * @return Priority + */ + public function next() + { + if (null === $this->priorityHandler) { + return $this; + } + + return $this->priorityHandler->getAfter($this); + } + + /** + * @return Priority + */ + public function prev() + { + if (null === $this->priorityHandler) { + return $this; + } + + return $this->priorityHandler->getBefore($this); + } +} \ No newline at end of file diff --git a/src/PriorityHandler/PriorityHandlerInterface.php b/src/PriorityHandler/PriorityHandlerInterface.php index da18415..5a9af90 100644 --- a/src/PriorityHandler/PriorityHandlerInterface.php +++ b/src/PriorityHandler/PriorityHandlerInterface.php @@ -2,98 +2,80 @@ namespace ReputationVIP\QueueClient\PriorityHandler; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; + interface PriorityHandlerInterface { /** - * @param string $name - * @return PriorityHandlerInterface - */ - public function add($name); - - /** - * @param string $name + * @param Priority $priority * @return PriorityHandlerInterface */ - public function remove($name); + public function add(Priority $priority); /** - * @param string $addName - * @param string $beforeName + * @param Priority $priority * @return PriorityHandlerInterface */ - public function addBefore($addName, $beforeName); + public function remove(Priority $priority); /** - * @param string $beforeName * @return PriorityHandlerInterface */ - public function removeBefore($beforeName); + public function clear(); /** - * @param string $addName - * @param string $afterName - * @return PriorityHandlerInterface + * @param string $name + * @return boolean */ - public function addAfter($addName, $afterName); + public function has($name); /** - * @param string $afterName - * @return PriorityHandlerInterface + * @return Priority */ - public function removeAfter($afterName); + public function getDefault(); /** + * @param Priority $priority * @return PriorityHandlerInterface */ - public function clear(); - - /** - * @param $name - * @return boolean - */ - public function has($name); + public function setDefault(Priority $priority); /** - * @param int $index - * @return string - */ - public function getName($index); - - /** - * @return string + * @param string $name + * @return Priority */ - public function getDefault(); + public function getPriorityByName($name); /** - * @param string $newDefault - * @return PriorityHandlerInterface + * @param integer $level + * @return Priority */ - public function setDefault($newDefault); + public function getPriorityByLevel($level); /** - * @return string + * @return Priority */ public function getHighest(); /** - * @return string + * @return Priority */ public function getLowest(); /** - * @param string $beforeName - * @return string + * @param Priority $priority + * @return Priority */ - public function getBefore($beforeName); + public function getBefore(Priority $priority); /** - * @param string $afterName - * @return string + * @param Priority $priority + * @return Priority */ - public function getAfter($afterName); + public function getAfter(Priority $priority); /** - * @return array + * @return Priority[] */ public function getAll(); diff --git a/src/PriorityHandler/StandardPriorityHandler.php b/src/PriorityHandler/StandardPriorityHandler.php index 8bdd570..15c2102 100644 --- a/src/PriorityHandler/StandardPriorityHandler.php +++ b/src/PriorityHandler/StandardPriorityHandler.php @@ -2,6 +2,7 @@ namespace ReputationVIP\QueueClient\PriorityHandler; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\PriorityHandler\Exception\PriorityLevelException; class StandardPriorityHandler implements PriorityHandlerInterface @@ -12,21 +13,43 @@ class StandardPriorityHandler implements PriorityHandlerInterface protected $defaultIndex = 0; /** - * @var [] + * @var Priority[] */ - protected $priorities = ['']; + protected $priorities = []; + + + public function __construct() + { + $this->add(new Priority('', 0)); + } /** * @inheritdoc * * @throws PriorityLevelException */ - public function add($name) + public function add(Priority $priority) { - if (in_array($name, $this->priorities)) { - throw new PriorityLevelException('Level ' . $name . ' already exists.'); + $newName = $priority->getName(); + $alreadyAdded = false; + + foreach ($this->priorities as $checkPriority) { + if ($checkPriority->getName() === $newName) { + $alreadyAdded = true; + break; + } } - $this->priorities[] = $name; + + if ($alreadyAdded) { + throw new PriorityLevelException('Level name ' . $priority->getName() . ' already exist.'); + } + if (isset($this->priorities[$priority->getLevel()])) { + throw new PriorityLevelException('Level ' . $priority->getLevel() . ' already exist.'); + } + + $priority->setPriorityHandler($this); + $this->priorities[$priority->getLevel()] = $priority; + ksort($this->priorities); return $this; } @@ -35,103 +58,61 @@ public function add($name) * * @throws PriorityLevelException */ - public function remove($name) + public function remove(Priority $priority) { - $key = array_search($name, $this->priorities); - if (false === $key) { - throw new PriorityLevelException("Level " . $name . " doesn't exist."); + if (!isset($this->priorities[$priority->getLevel()])) { + throw new PriorityLevelException('Level ' . $priority->getLevel() . ' doesn\'t exist.'); } $default = $this->getDefault(); - unset($this->priorities[$key]); - $this->priorities = array_values($this->priorities); - if ($name === $default) { + unset($this->priorities[$priority->getLevel()]); + if ($priority === $default) { $this->defaultIndex = 0; } else { $this->setDefault($default); } + ksort($this->priorities); + return $this; } /** * @inheritdoc - * - * @throws PriorityLevelException */ - public function addBefore($addName, $beforeName) + public function clear() { - $key = array_search($beforeName, $this->priorities); - if (false !== $key) { - if (in_array($addName, $this->priorities)) { - throw new PriorityLevelException('Level ' . $addName . ' already exists.'); - } - $default = $this->getDefault(); - if (0 === $key) { - array_unshift($this->priorities, $addName); - } else { - $oldPriorities = $this->priorities; - $this->priorities = array_slice($oldPriorities, 0, $key, true); - $this->priorities[] = $addName; - $this->priorities = array_merge($this->priorities, array_slice($oldPriorities, $key, count($oldPriorities) - 1, true)); - } - $this->setDefault($default); - } else { - throw new PriorityLevelException("Level " . $beforeName . " doesn't exist."); - } + $this->priorities = []; + $priority = new Priority('', 0); + $this->add($priority); + return $this; } /** * @inheritdoc - * - * @throws PriorityLevelException */ - public function removeBefore($beforeName) + public function has($name) { - $key = array_search($beforeName, $this->priorities); - if (false !== $key) { - if (0 !== $key) { - $default = $this->getDefault(); - $name = $this->priorities[$key - 1]; - unset($this->priorities[$key - 1]); - $this->priorities = array_values($this->priorities); - if ($name === $default) { - $this->defaultIndex = 0; - } else { - $this->setDefault($default); - } + $has = false; + + foreach ($this->priorities as $priority) { + if ($priority->getName() === $name) { + $has = true; + break; } - } else { - throw new PriorityLevelException("Level " . $beforeName . " doesn't exist."); } - return $this; + + return $has; } /** * @inheritdoc - * - * @throws PriorityLevelException */ - public function addAfter($addName, $afterName) + public function getDefault() { - $key = array_search($afterName, $this->priorities); - if (false !== $key) { - if (in_array($addName, $this->priorities)) { - throw new PriorityLevelException('Level ' . $addName . ' already exists.'); - } - $default = $this->getDefault(); - if ($key === (count($this->priorities) - 1)) { - $this->priorities[] = $addName; - } else { - $oldPriorities = $this->priorities; - $this->priorities = array_slice($oldPriorities, 0, $key + 1, true); - $this->priorities[] = $addName; - $this->priorities = array_merge($this->priorities, array_slice($oldPriorities, $key + 1, count($oldPriorities) - 1, true)); - } - $this->setDefault($default); - } else { - throw new PriorityLevelException("Level " . $afterName . " doesn't exist."); + if (empty($this->priorities)) { + return new Priority('', 0); } - return $this; + return $this->priorities[$this->defaultIndex]; } /** @@ -139,34 +120,14 @@ public function addAfter($addName, $afterName) * * @throws PriorityLevelException */ - public function removeAfter($afterName) + public function setDefault(Priority $priority) { - $key = array_search($afterName, $this->priorities); - if (false !== $key) { - if ($key !== (count($this->priorities) - 1)) { - $default = $this->getDefault(); - $name = $this->priorities[$key + 1]; - unset($this->priorities[$key + 1]); - $this->priorities = array_values($this->priorities); - if ($name === $default) { - $this->defaultIndex = 0; - } else { - $this->setDefault($default); - } - } - } else { - throw new PriorityLevelException("Level " . $afterName . " doesn't exist."); + + if (!isset($this->priorities[$priority->getLevel()])) { + throw new PriorityLevelException('Level ' . $priority->getLevel() . ' doesn\'t exist.'); } - return $this; - } - /** - * @inheritdoc - */ - public function clear() - { - $this->priorities = ['']; - $this->defaultIndex = 0; + $this->defaultIndex = $priority->getLevel(); return $this; } @@ -174,57 +135,33 @@ public function clear() /** * @inheritdoc */ - public function has($name) + public function getPriorityByName($name) { - $key = array_search($name, $this->priorities); - if (false === $key) { - return false; + $returnPriority = null; + foreach ($this->priorities as $priority) { + if ($priority->getName() === $name) { + $returnPriority = $priority; + break; + } } - return true; - } - /** - * @inheritdoc - * - * @throws \RangeException - */ - public function getName($index) - { - if ($index < 0 || $index >= count($this->priorities)) { - throw new \RangeException('Level index out of range.'); + if (null === $returnPriority) { + throw new \InvalidArgumentException('Level name' . $name . ' doesn\'t exist.'); } - return $this->priorities[$index]; - } - /** - * @inheritdoc - */ - public function getDefault() - { - if (empty($this->priorities)) { - return ''; - } - return $this->priorities[$this->defaultIndex]; + return $returnPriority; } /** * @inheritdoc - * - * @throws PriorityLevelException */ - public function setDefault($newDefault) + public function getPriorityByLevel($level) { - if (empty($this->priorities)) { - $this->defaultIndex = 0; - } - $key = array_search($newDefault, $this->priorities); - if (false !== $key) { - $this->defaultIndex = $key; - } else { - throw new PriorityLevelException("Level " . $newDefault . " doesn't exist."); + if (isset($this->priorities[$level])) { + return $this->priorities[$level]; } - return $this; + throw new \InvalidArgumentException('Level ' . $level . ' doesn\'t exist.'); } /** @@ -232,10 +169,10 @@ public function setDefault($newDefault) */ public function getHighest() { - if (empty($this->priorities)) { - return ''; + foreach ($this->priorities as $priority) { + return $priority; } - return $this->priorities[0]; + return new Priority('', 0); } /** @@ -243,10 +180,7 @@ public function getHighest() */ public function getLowest() { - if (empty($this->priorities)) { - return ''; - } - return $this->priorities[count($this->priorities) - 1]; + return end(array_values($this->priorities)); } /** @@ -254,19 +188,25 @@ public function getLowest() * * @throws PriorityLevelException */ - public function getBefore($beforeName) + public function getBefore(Priority $priority) { - $key = array_search($beforeName, $this->priorities); + /** @var Priority $searchPriority*/ + $searchPriority = reset($this->priorities); - if (false === $key) { - throw new PriorityLevelException("Level " . $beforeName . " doesn't exist."); + if ($searchPriority->getLevel() === $priority->getLevel()) { + return $searchPriority; } - - if (0 === $key) { - return $this->priorities[0]; + while ($searchPriority = next($this->priorities)) { + if ($searchPriority->getLevel() === $priority->getLevel()) { + $prevPriority = prev($this->priorities); + if (false === $prevPriority) { + return $searchPriority; + } + return $prevPriority; + } } - return $this->priorities[$key - 1]; + throw new PriorityLevelException('Level ' . $priority->getLevel() . ' doesn\'t exist.'); } /** @@ -274,19 +214,29 @@ public function getBefore($beforeName) * * @throws PriorityLevelException */ - public function getAfter($afterName) + public function getAfter(Priority $priority) { - $key = array_search($afterName, $this->priorities); + /** @var Priority $searchPriority*/ + $searchPriority = reset($this->priorities); - if (false === $key) { - throw new PriorityLevelException("Level " . $afterName . " doesn't exist."); + if ($searchPriority->getLevel() === $priority->getLevel()) { + $nextPriority = next($this->priorities); + if (false === $nextPriority) { + return $searchPriority; + } + return $searchPriority; } - - if (count($this->priorities) - 1 === $key) { - return $this->priorities[count($this->priorities) - 1]; + while ($searchPriority = next($this->priorities)) { + if ($searchPriority->getLevel() === $priority->getLevel()) { + $nextPriority = next($this->priorities); + if (false === $nextPriority) { + return $searchPriority; + } + return $nextPriority; + } } - return $this->priorities[$key + 1]; + throw new PriorityLevelException('Level ' . $priority->getLevel() . ' doesn\'t exist.'); } /** diff --git a/src/PriorityHandler/ThreeLevelPriorityHandler.php b/src/PriorityHandler/ThreeLevelPriorityHandler.php index 90a51e8..bae3eb3 100644 --- a/src/PriorityHandler/ThreeLevelPriorityHandler.php +++ b/src/PriorityHandler/ThreeLevelPriorityHandler.php @@ -2,19 +2,18 @@ namespace ReputationVIP\QueueClient\PriorityHandler; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; + class ThreeLevelPriorityHandler extends StandardPriorityHandler { - /** - * @var int - */ - protected $defaultIndex = 1; - - /** - * @var [] - */ - protected $priorities = [ - 'HIGH', - 'MID', - 'LOW' - ]; + public function __construct() + { + parent::__construct(); + $this->priorities = []; + $this->add(new Priority('HIGH', 0)); + $default = new Priority('MID', 100); + $this->add($default); + $this->add(new Priority('LOW', 200)); + $this->setDefault($default); + } } diff --git a/src/QueueClientInterface.php b/src/QueueClientInterface.php index e324b33..4761cbe 100644 --- a/src/QueueClientInterface.php +++ b/src/QueueClientInterface.php @@ -2,6 +2,7 @@ namespace ReputationVIP\QueueClient; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; use ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface; interface QueueClientInterface @@ -9,7 +10,7 @@ interface QueueClientInterface /** * @param string $queueName * @param mixed $message - * @param string $priority + * @param Priority $priority * @param int $delaySeconds * * @return QueueClientInterface @@ -19,7 +20,7 @@ public function addMessage($queueName, $message, $priority = null, $delaySeconds /** * @param string $queueName * @param array $messages - * @param string $priority + * @param Priority $priority * * @return QueueClientInterface */ @@ -27,7 +28,7 @@ public function addMessages($queueName, $messages, $priority = null); /** * @param string $queueName - * @param string $priority + * @param Priority $priority * @param int $nbMsg * * @return array @@ -52,7 +53,7 @@ public function deleteMessages($queueName, $messages); /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @return bool */ @@ -60,7 +61,7 @@ public function isEmpty($queueName, $priority = null); /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @return int */ @@ -90,7 +91,7 @@ public function renameQueue($sourceQueueName, $targetQueueName); /** * @param string $queueName - * @param string $priority + * @param Priority $priority * * @return QueueClientInterface */ diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index a8abc21..458de9b 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -221,7 +221,7 @@ public function testFileAdapterPurgeQueue() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -298,7 +298,7 @@ public function testFileAdapterPurgeQueueWithEmptyQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -334,7 +334,7 @@ public function testFileAdapterPurgeQueueWithBadQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -371,7 +371,7 @@ public function testFileAdapterIsEmptyWithEmptyQueue() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -409,7 +409,7 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -472,7 +472,7 @@ public function testFileAdapterIsEmptyWithEmptyQueueContent() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -509,7 +509,7 @@ public function testFileAdapterIsEmptyWithBadQueueContent() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -540,10 +540,10 @@ public function testFileAdapterListQueues() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'prefixTestTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'testTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'testThreeQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'prefixTestTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testThreeQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -573,10 +573,10 @@ public function testFileAdapterListQueuesWithPrefix() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'prefixTestTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'testTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'prefixTestOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'prefixTestTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'prefixTestOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -628,7 +628,7 @@ public function testFileAdapterAddMessage() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -761,7 +761,7 @@ public function testFileAdapterAddMessageWithEmptyQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -797,7 +797,7 @@ public function testFileAdapterAddMessageWithBadQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -875,7 +875,7 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -911,7 +911,7 @@ public function testFileAdapterGetNumberMessagesWithBadQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -947,7 +947,7 @@ public function testFileAdapterGetNumberMessages() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1063,7 +1063,7 @@ public function testFileAdapterGetMessagesWithEmptyQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1099,7 +1099,7 @@ public function testFileAdapterGetMessagesWithBadQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1135,7 +1135,7 @@ public function testFileAdapterGetMessages() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1177,7 +1177,7 @@ public function testFileAdapterDeleteMessageWithNoQueueFile() $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; $this->exception(function() use($fileAdapter, $priorityHandler) { - $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } @@ -1204,7 +1204,7 @@ public function testFileAdapterDeleteMessageWithNoIdField() $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $this->exception(function() use($FileAdapter, $priorityHandler) { - $FileAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest()]); + $FileAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest()->getLevel()]); }); } @@ -1249,7 +1249,7 @@ public function testFileAdapterDeleteMessageLockFailed() return $mockLockHandler; }; $this->exception(function() use($fileAdapter, $priorityHandler) { - $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } @@ -1271,7 +1271,7 @@ public function testFileAdapterDeleteMessageWithEmptyQueueContent() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1286,7 +1286,7 @@ public function testFileAdapterDeleteMessageWithEmptyQueueContent() return new ArrayIterator($mocksSplFileInfo); }; $this->exception(function() use($fileAdapter, $priorityHandler) { - $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } @@ -1308,7 +1308,7 @@ public function testFileAdapterDeleteMessageWithBadQueueContent() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1322,8 +1322,8 @@ public function testFileAdapterDeleteMessageWithBadQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($fileAdapter, $priorityHandler) { - $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()]); + $this->exception(function() use($fileAdapter, $priorityHandler) { + $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } @@ -1345,7 +1345,7 @@ public function testFileAdapterDeleteMessage() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1360,7 +1360,7 @@ public function testFileAdapterDeleteMessage() return new ArrayIterator($mocksSplFileInfo); }; $this->given($fileAdapter) - ->class($fileAdapter->deleteMessage('testQueue', array('id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest())))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + ->class($fileAdapter->deleteMessage('testQueue', array('id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel())))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testFileAdapterRenameQueueWithEmptyParameter() @@ -1403,7 +1403,7 @@ public function testFileAdapterRenameQueue() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { diff --git a/tests/units/Adapter/MemoryAdapter.php b/tests/units/Adapter/MemoryAdapter.php index e184717..45be0e6 100644 --- a/tests/units/Adapter/MemoryAdapter.php +++ b/tests/units/Adapter/MemoryAdapter.php @@ -3,6 +3,8 @@ namespace ReputationVIP\QueueClient\tests\units\Adapter; use mageekguy\atoum; +use ReputationVIP\QueueClient\PriorityHandler\Priority\Priority; +use ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler; use ReputationVIP\QueueClient\PriorityHandler\ThreeLevelPriorityHandler; class MemoryAdapter extends atoum\test @@ -158,7 +160,7 @@ public function testMemoryAdapterPurgeQueueWithBadPriority() $memoryAdapter->createQueue('testQueue'); $this->exception(function() use($memoryAdapter) { - $memoryAdapter->purgeQueue('testQueue', 'BAD_PRIORITY'); + $memoryAdapter->purgeQueue('testQueue', new Priority('BAD_PRIORITY', 100)); }); } @@ -217,7 +219,7 @@ public function testMemoryAdapterAddMessageWithBadPriority() $memoryAdapter->createQueue('testQueue'); $this->exception(function() use($memoryAdapter) { - $memoryAdapter->addMessage('testQueue', 'test message', 'BAD_PRIORITY'); + $memoryAdapter->AddMessage('testQueue', 'test message', new Priority('BAD_PRIORITY', 100)); }); } @@ -257,7 +259,7 @@ public function testMemoryAdapterIsEmptyWithBadPriority() $memoryAdapter->createQueue('testQueue'); $this->exception(function() use($memoryAdapter) { - $memoryAdapter->isEmpty('testQueue', 'BAD_PRIORITY'); + $memoryAdapter->isEmpty('testQueue', new Priority('BAD_PRIORITY', 100)); }); } @@ -323,7 +325,7 @@ public function testMemoryAdapterGetNumberMessagesWithBadPriority() $memoryAdapter->createQueue('testQueue'); $this->exception(function() use($memoryAdapter) { - $memoryAdapter->getNumberMessages('testQueue', 'BAD_PRIORITY'); + $memoryAdapter->getNumberMessages('testQueue', new Priority('BAD_PRIORITY', 100)); }); } @@ -452,7 +454,7 @@ public function testMemoryAdapterGetMessagesWithBadPriority() $memoryAdapter->createQueue('testQueue'); $memoryAdapter->addMessage('testQueue', 'test message'); $this->exception(function() use($memoryAdapter) { - $memoryAdapter->getMessages('testQueue', 1, 'BAD_PRIORITY'); + $memoryAdapter->getMessages('testQueue', 1, new Priority('BAD_PRIORITY', 100)); }); } diff --git a/tests/units/Adapter/SQSAdapter.php b/tests/units/Adapter/SQSAdapter.php index 9ae14a4..f3989bc 100644 --- a/tests/units/Adapter/SQSAdapter.php +++ b/tests/units/Adapter/SQSAdapter.php @@ -244,7 +244,7 @@ public function testSQSAdapterDeleteMessage() return null; }; $this->given($sqsAdapter) - ->class($sqsAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest(), 'ReceiptHandle' => 'testReceiptHandle']))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); + ->class($sqsAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest()->getLevel(), 'ReceiptHandle' => 'testReceiptHandle']))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } public function testSQSAdapterIsEmptyWithEmptyQueueName() diff --git a/tests/units/PriorityHandler/StandardPriorityHandler.php b/tests/units/PriorityHandler/StandardPriorityHandler.php deleted file mode 100644 index dc3a849..0000000 --- a/tests/units/PriorityHandler/StandardPriorityHandler.php +++ /dev/null @@ -1,416 +0,0 @@ -add('testPriority'); - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->add('testPriority'); - }); - } - - public function testStandardPriorityHandlerAdd() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->add('testPriority'))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['', 'testPriority']); - } - - public function testStandardPriorityHandlerRemoveWithNoPriority() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->remove('testPriority'); - }); - } - - public function testStandardPriorityHandlerRemoveWithDefaultValue() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $standardPriorityHandler->setDefault('testPriority'); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->remove('testPriority'))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerRemove() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->remove('testPriority'))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerAddBeforeWithAddValuesAlreadyExists() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->addBefore('testPriority', ''); - }); - } - - public function testStandardPriorityHandlerAddBeforeWithNoBeforeValues() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->addBefore('testPriority', 'wrongPriority'); - }); - } - - public function testStandardPriorityHandlerAddBefore() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->addBefore('testPriority', ''))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->addBefore('testPriorityTwo', ''))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['testPriority', 'testPriorityTwo', '']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerRemoveBeforeWithNoBeforeValues() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->removeBefore('testPriority'); - }); - } - - public function testStandardPriorityHandlerRemoveBeforeWithDefaultValue() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->addBefore('testPriority', ''); - $standardPriorityHandler->setDefault('testPriority'); - $standardPriorityHandler->addBefore('testPriorityTwo', ''); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->removeBefore('testPriorityTwo'))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['testPriorityTwo', '']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo('testPriorityTwo'); - } - - public function testStandardPriorityHandlerRemoveBefore() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->addBefore('testPriority', ''); - $standardPriorityHandler->addBefore('testPriorityTwo', ''); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->removeBefore('testPriorityTwo'))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['testPriorityTwo', '']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerAddAfterWithAddValuesAlreadyExists() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->addAfter('testPriority', ''); - }); - } - - public function testStandardPriorityHandlerAddAfterWithNoBeforeValues() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->addAfter('testPriority', 'wrongPriority'); - }); - } - - public function testStandardPriorityHandlerAddAfter() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->addAfter('testPriority', ''))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->addAfter('testPriorityTwo', ''))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['', 'testPriorityTwo', 'testPriority']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerRemoveAfterWithNoBeforeValues() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->removeAfter('testPriority'); - }); - } - - public function testStandardPriorityHandlerRemoveAfterWithDefaultValue() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $standardPriorityHandler->add('testPriorityTwo'); - $standardPriorityHandler->setDefault('testPriorityTwo'); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->removeAfter('testPriority'))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['', 'testPriority']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerRemoveAfter() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $standardPriorityHandler->add('testPriorityTwo'); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->removeAfter(''))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['', 'testPriorityTwo']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerClear() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $standardPriorityHandler->add('testPriorityTwo'); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->clear())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerHas() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $this->given($standardPriorityHandler) - ->boolean($standardPriorityHandler->has('testPriority'))->isTrue(); - $this->given($standardPriorityHandler) - ->boolean($standardPriorityHandler->has($standardPriorityHandler->getDefault()))->isTrue(); - $this->given($standardPriorityHandler) - ->boolean($standardPriorityHandler->has('wrongPriority'))->isFalse(); - } - - public function testStandardPriorityHandlerGetNameWithWrongIndex() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->getName(-1); - }); - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->getName(42); - }); - } - - public function testStandardPriorityHandlerGetName() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $standardPriorityHandler->add('testPriorityTwo'); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getName(0))->isIdenticalTo(''); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getName(2))->isIdenticalTo('testPriorityTwo'); - } - - public function testStandardPriorityHandlerGetDefaultWithEmptyPriority() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->remove(''); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerSetDefaultWithEmptyPriority() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->remove(''); - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->setDefault('testPriority'); - }); - } - - public function testStandardPriorityHandlerSetDefaultWithUndefinedValue() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->setDefault('wrongPriority'); - }); - } - - public function testStandardPriorityHandlerSetDefault() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $standardPriorityHandler->setDefault('testPriority'); - $this->given($standardPriorityHandler) - ->class($standardPriorityHandler->setDefault('testPriority'))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getDefault())->isIdenticalTo('testPriority'); - } - - public function testStandardPriorityHandlerGetHighestWithEmptyPriority() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->remove(''); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getHighest())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerGetHighest() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->addBefore('testPriorityHigh', ''); - $standardPriorityHandler->add('testPriorityLow'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['testPriorityHigh', '', 'testPriorityLow']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getHighest())->isIdenticalTo('testPriorityHigh'); - } - - public function testStandardPriorityHandlerGetLowestWithEmptyPriority() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->remove(''); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getLowest())->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerGetLowest() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->addBefore('testPriorityHigh', ''); - $standardPriorityHandler->add('testPriorityLow'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['testPriorityHigh', '', 'testPriorityLow']); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getLowest())->isIdenticalTo('testPriorityLow'); - } - - public function testStandardPriorityHandlerGetBeforeWithFirstValue() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->addBefore('testPriority', ''); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getBefore('testPriority'))->isIdenticalTo('testPriority'); - } - - public function testStandardPriorityHandlerGetBeforeWithUndefinedValue() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->getBefore('wrongPriority'); - }); - } - - public function testStandardPriorityHandlerGetBefore() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getBefore('testPriority'))->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerGetAfterWithFirstValue() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getAfter('testPriority'))->isIdenticalTo('testPriority'); - } - - public function testStandardPriorityHandlerGetAfterWithUndefinedValue() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $this->exception(function() use($standardPriorityHandler) { - $standardPriorityHandler->getAfter('wrongPriority'); - }); - } - - public function testStandardPriorityHandlerGetAfter() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->addBefore('testPriority', ''); - $this->given($standardPriorityHandler) - ->string($standardPriorityHandler->getAfter('testPriority'))->isIdenticalTo(''); - } - - public function testStandardPriorityHandlerGetAll() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->add('testPriority'); - $standardPriorityHandler->add('testPriorityTwo'); - $this->given($standardPriorityHandler) - ->array($standardPriorityHandler->getAll())->isIdenticalTo(['', 'testPriority', 'testPriorityTwo']); - } - - public function testStandardPriorityHandlerCount() - { - $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); - - $standardPriorityHandler->remove(''); - $this->given($standardPriorityHandler) - ->integer($standardPriorityHandler->count())->isEqualTo(0); - $standardPriorityHandler->add('testPriority'); - $standardPriorityHandler->add('testPriorityTwo'); - $this->given($standardPriorityHandler) - ->integer($standardPriorityHandler->count())->isEqualTo(2); - } -} From 64e21c3973d8551c70a430c0fa7579c22ae6583a Mon Sep 17 00:00:00 2001 From: "nicolas.couet" Date: Fri, 11 Mar 2016 09:12:06 +0100 Subject: [PATCH 35/51] Fix FileAdapter test --- src/Adapter/BeanstalkdAdapter.php | 132 ---------------------------- tests/units/Adapter/FileAdapter.php | 97 ++++++++++---------- 2 files changed, 49 insertions(+), 180 deletions(-) delete mode 100644 src/Adapter/BeanstalkdAdapter.php diff --git a/src/Adapter/BeanstalkdAdapter.php b/src/Adapter/BeanstalkdAdapter.php deleted file mode 100644 index c17d8d6..0000000 --- a/src/Adapter/BeanstalkdAdapter.php +++ /dev/null @@ -1,132 +0,0 @@ -pheanstalkInterface = $pheanstalkInterface; - $this->priorityHandler = $priorityHandler; - } - - /** - * @param string $queueName - * @param mixed $message - * @param Priority $priority - * - * @return AdapterInterface - */ - public function addMessage($queueName, $message, Priority $priority = null) - { - - return $this; - } - - /** - * @inheritdoc - */ - public function getMessages($queueName, $nbMsg = 1, Priority $priority = null) - { - return []; - } - - /** - * @inheritdoc - */ - public function deleteMessage($queueName, $message, Priority $priority = null) - { - return $this; - } - - /** - * @inheritdoc - */ - public function isEmpty($queueName, Priority $priority = null) - { - return true; - } - - /** - * @inheritdoc - */ - public function getNumberMessages($queueName, Priority $priority = null) - { - return 0; - } - - /** - * @inheritdoc - */ - public function deleteQueue($queueName) - { - return $this; - } - - /** - * @inheritdoc - */ - public function createQueue($queueName) - { - return $this; - } - - /** - * @inheritdoc - */ - public function renameQueue($sourceQueueName, $targetQueueName) - { - return $this; - } - - /** - * @inheritdoc - */ - public function purgeQueue($queueName, Priority $priority = null) - { - return $this; - } - - /** - * @inheritdoc - */ - public function listQueues($prefix = '') - { - return []; - } - - /** - * @inheritdoc - */ - public function getPriorityHandler() - { - return $this->priorityHandler; - } -} \ No newline at end of file diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index 458de9b..108717a 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -51,12 +51,12 @@ public function testFileAdapterDeleteQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $this->calling($mockFs)->exists = true; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->given($fileAdapter) ->class($fileAdapter->deleteQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } @@ -80,12 +80,12 @@ public function testFileAdapterDeleteQueueWithNoQueueFile() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $this->calling($mockFs)->exists = false; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->deleteQueue('testQueue'); }); @@ -97,13 +97,13 @@ public function testFileAdapterDeleteQueueWithLockFailed() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->calling($mockFs)->exists = true; $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->deleteQueue('testQueue'); }); @@ -115,12 +115,12 @@ public function testFileAdapterCreateQueue() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; $this->given($fileAdapter) ->class($fileAdapter->createQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); @@ -132,7 +132,6 @@ public function testFileAdapterCreateQueueWithFsException() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; @@ -142,6 +141,7 @@ public function testFileAdapterCreateQueueWithFsException() $mockFs->getMockController()->dumpFile = function($repository) { throw new \Exception('test exception'); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->createQueue('testQueue'); }); @@ -153,12 +153,12 @@ public function testFileAdapterCreateQueueWithLockFailed() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; $this->exception(function() use($fileAdapter) { $fileAdapter->createQueue('testQueue'); @@ -183,8 +183,8 @@ public function testFileAdapterCreateQueueWithExistingQueue() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->createQueue('testQueue'); }); @@ -196,8 +196,8 @@ public function testFileAdapterCreateQueueWithSpaceIngQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->createQueue('test Queue'); }); @@ -210,7 +210,6 @@ public function testFileAdapterPurgeQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -235,6 +234,7 @@ public function testFileAdapterPurgeQueue() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->given($fileAdapter) ->class($fileAdapter->purgeQueue('testQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } @@ -245,10 +245,10 @@ public function testFileAdapterPurgeQueueWithNoQueueFile() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; - $this->exception(function() use($fileAdapter) { - $fileAdapter->purgeQueue('testQueue'); + $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($FileAdapter) { + $FileAdapter->purgeQueue('testQueue'); }); } @@ -269,13 +269,13 @@ public function testFileAdapterPurgeQueueWithLockFailed() { $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->purgeQueue('testQueue'); }); @@ -287,7 +287,6 @@ public function testFileAdapterPurgeQueueWithEmptyQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -312,6 +311,7 @@ public function testFileAdapterPurgeQueueWithEmptyQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->purgeQueue('testQueue'); }); @@ -323,7 +323,6 @@ public function testFileAdapterPurgeQueueWithBadQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -348,6 +347,7 @@ public function testFileAdapterPurgeQueueWithBadQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->purgeQueue('testQueue'); }); @@ -360,7 +360,6 @@ public function testFileAdapterIsEmptyWithEmptyQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -385,6 +384,8 @@ public function testFileAdapterIsEmptyWithEmptyQueue() } return new ArrayIterator($mocksSplFileInfo); }; + + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this ->given($fileAdapter) ->boolean($fileAdapter->isEmpty('testQueue')) @@ -398,7 +399,6 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -423,6 +423,7 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this ->given($fileAdapter) ->boolean($fileAdapter->isEmpty('testQueue')) @@ -447,8 +448,8 @@ public function testFileAdapterIsEmptyWithNoQueueFile() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->isEmpty('testQueue'); }); @@ -461,7 +462,6 @@ public function testFileAdapterIsEmptyWithEmptyQueueContent() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -486,6 +486,7 @@ public function testFileAdapterIsEmptyWithEmptyQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->isEmpty('testQueue'); }); @@ -498,7 +499,6 @@ public function testFileAdapterIsEmptyWithBadQueueContent() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -523,6 +523,7 @@ public function testFileAdapterIsEmptyWithBadQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->isEmpty('testQueue'); }); @@ -535,7 +536,6 @@ public function testFileAdapterListQueues() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { $files = []; $priorities = $priorityHandler->getAll(); @@ -555,6 +555,7 @@ public function testFileAdapterListQueues() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this ->given($fileAdapter) ->array($fileAdapter->listQueues()) @@ -568,7 +569,6 @@ public function testFileAdapterListQueuesWithPrefix() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFinder->getMockController()->getIterator = function () use ($priorityHandler) { $files = []; $priorities = $priorityHandler->getAll(); @@ -588,6 +588,7 @@ public function testFileAdapterListQueuesWithPrefix() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this ->given($fileAdapter) ->array($fileAdapter->listQueues('prefix')) @@ -600,10 +601,10 @@ public function testFileAdapterListQueuesWithEmptyQueue() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFinder->getMockController()->getIterator = function () { return new ArrayIterator([]); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this ->given($fileAdapter) ->array($fileAdapter->listQueues()) @@ -617,7 +618,6 @@ public function testFileAdapterAddMessage() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -642,6 +642,7 @@ public function testFileAdapterAddMessage() } return new ArrayIterator($mocksSplFileInfo); }; + $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->given($FileAdapter) ->class($FileAdapter->addMessage('testQueue', 'test Message one'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } @@ -732,13 +733,13 @@ public function testFileAdapterAddMessageLockFailed() { $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->addMessage('testQueue', 'test message'); }); @@ -750,7 +751,6 @@ public function testFileAdapterAddMessageWithEmptyQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -775,6 +775,7 @@ public function testFileAdapterAddMessageWithEmptyQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->addMessage('testQueue', 'test message'); }); @@ -786,7 +787,6 @@ public function testFileAdapterAddMessageWithBadQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -811,6 +811,7 @@ public function testFileAdapterAddMessageWithBadQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->addMessage('testQueue', 'test message'); }); @@ -846,13 +847,13 @@ public function testFileAdapterGetNumberMessagesLockFailed() { $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->getNumberMessages('testQueue'); }); @@ -864,7 +865,6 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -889,6 +889,7 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->getNumberMessages('testQueue'); }); @@ -900,7 +901,6 @@ public function testFileAdapterGetNumberMessagesWithBadQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -925,6 +925,7 @@ public function testFileAdapterGetNumberMessagesWithBadQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->getNumberMessages('testQueue'); }); @@ -936,7 +937,6 @@ public function testFileAdapterGetNumberMessages() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -961,6 +961,7 @@ public function testFileAdapterGetNumberMessages() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->given($fileAdapter) ->integer($fileAdapter->getNumberMessages('testQueue'))->isEqualTo(6); } @@ -1034,13 +1035,13 @@ public function testFileAdapterGetMessagesLockFailed() { $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->getMessages('testQueue'); }); @@ -1052,7 +1053,6 @@ public function testFileAdapterGetMessagesWithEmptyQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -1077,6 +1077,7 @@ public function testFileAdapterGetMessagesWithEmptyQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->getMessages('testQueue'); }); @@ -1088,7 +1089,6 @@ public function testFileAdapterGetMessagesWithBadQueueContent() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -1113,6 +1113,7 @@ public function testFileAdapterGetMessagesWithBadQueueContent() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->getMessages('testQueue'); }); @@ -1124,7 +1125,6 @@ public function testFileAdapterGetMessages() { $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -1149,10 +1149,11 @@ public function testFileAdapterGetMessages() { } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->given($fileAdapter) - ->array($fileAdapter->getMessages('testQueue', 6)); + ->array($fileAdapter->GetMessages('testQueue', 6)); $this->given($fileAdapter) - ->array($fileAdapter->getMessages('testQueue', 8)); + ->array($fileAdapter->GetMessages('testQueue', 8)); } public function testFileAdapterDeleteMessageWithEmptyQueueName() @@ -1174,8 +1175,8 @@ public function testFileAdapterDeleteMessageWithNoQueueFile() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter, $priorityHandler) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); @@ -1187,8 +1188,8 @@ public function testFileAdapterDeleteMessageWithNoMessage() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->deleteMessage('testQueue', []); }); @@ -1201,8 +1202,8 @@ public function testFileAdapterDeleteMessageWithNoIdField() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; + $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($FileAdapter, $priorityHandler) { $FileAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest()->getLevel()]); }); @@ -1214,8 +1215,8 @@ public function testFileAdapterDeleteMessageWithNotPriorityField() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915']); }); @@ -1227,8 +1228,8 @@ public function testFileAdapterDeleteMessageWithBadMessageType() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = true; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter) { $fileAdapter->deleteMessage('testQueue', 'message'); }); @@ -1241,13 +1242,13 @@ public function testFileAdapterDeleteMessageLockFailed() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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 = false; return $mockLockHandler; }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter, $priorityHandler) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); @@ -1260,7 +1261,6 @@ public function testFileAdapterDeleteMessageWithEmptyQueueContent() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -1285,6 +1285,7 @@ public function testFileAdapterDeleteMessageWithEmptyQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function() use($fileAdapter, $priorityHandler) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); @@ -1297,7 +1298,6 @@ public function testFileAdapterDeleteMessageWithBadQueueContent() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -1322,7 +1322,8 @@ public function testFileAdapterDeleteMessageWithBadQueueContent() } return new ArrayIterator($mocksSplFileInfo); }; - $this->exception(function() use($fileAdapter, $priorityHandler) { + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); + $this->exception(function() use($fileAdapter, $priorityHandler) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } @@ -1334,7 +1335,6 @@ public function testFileAdapterDeleteMessage() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $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); @@ -1359,6 +1359,7 @@ public function testFileAdapterDeleteMessage() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->given($fileAdapter) ->class($fileAdapter->deleteMessage('testQueue', array('id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel())))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } @@ -1385,7 +1386,6 @@ public function testFileAdapterRenameQueue() $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); - $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = function ($queue) { static $i = 0; if ($i < 3) { @@ -1417,6 +1417,7 @@ public function testFileAdapterRenameQueue() } return new ArrayIterator($mocksSplFileInfo); }; + $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->given($fileAdapter) ->class($fileAdapter->renameQueue('testQueue', 'newTestQueue'))->hasInterface('\ReputationVIP\QueueClient\Adapter\AdapterInterface'); } From 5db81b98c9f66b545565e8e71317f7082560af1a Mon Sep 17 00:00:00 2001 From: "nicolas.couet" Date: Fri, 11 Mar 2016 09:25:16 +0100 Subject: [PATCH 36/51] Update gitignore --- .gitignore | 50 ++------------------------------------------------ composer.json | 3 +-- coverage.xml | 9 --------- 3 files changed, 3 insertions(+), 59 deletions(-) delete mode 100644 coverage.xml diff --git a/.gitignore b/.gitignore index b52930a..2bf1645 100644 --- a/.gitignore +++ b/.gitignore @@ -1,50 +1,4 @@ -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio - -*.iml - -## Directory-based project format: .idea/ -# if you remove the above rule, at least ignore the following: - -# User-specific stuff: -# .idea/workspace.xml -# .idea/tasks.xml -# .idea/dictionaries - -# Sensitive or high-churn files: -# .idea/dataSources.ids -# .idea/dataSources.xml -# .idea/sqlDataSources.xml -# .idea/dynamic.xml -# .idea/uiDesigner.xml - -# Gradle: -# .idea/gradle.xml -# .idea/libraries - -# Mongo Explorer plugin: -# .idea/mongoSettings.xml - -## File-based project format: -*.ipr -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties - vendor -composer.lock \ No newline at end of file +composer.lock +coverage.xml \ No newline at end of file diff --git a/composer.json b/composer.json index 8b1edb8..fd73bd7 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,7 @@ "require": { "symfony/filesystem": ">=2.7", "symfony/finder": ">=2.7", - "aws/aws-sdk-php": ">=2.7", - "pda/pheanstalk": "^3.1" + "aws/aws-sdk-php": ">=2.7" }, "require-dev": { "atoum/atoum": "~2", diff --git a/coverage.xml b/coverage.xml deleted file mode 100644 index ee32d25..0000000 --- a/coverage.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - From 78e6ae92c997449542c692bb3318a302999a0085 Mon Sep 17 00:00:00 2001 From: "nicolas.couet" Date: Fri, 11 Mar 2016 16:07:18 +0100 Subject: [PATCH 37/51] Update test --- .gitignore | 4 +- Makefile | 19 + README.md | 4 + docker-compose.yml.dist | 10 + docker/test/Dockerfile | 12 + docker/test/ssh/ssh_config | 2 + .../StandardPriorityHandler.php | 26 +- tests/units/Adapter/FileAdapter.php | 6 +- .../StandardPriorityHandler.php | 330 ++++++++++++++++++ 9 files changed, 393 insertions(+), 20 deletions(-) create mode 100644 Makefile create mode 100644 docker-compose.yml.dist create mode 100644 docker/test/Dockerfile create mode 100644 docker/test/ssh/ssh_config create mode 100644 tests/units/PriorityHandler/StandardPriorityHandler.php diff --git a/.gitignore b/.gitignore index 2bf1645..918583c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .idea/ vendor composer.lock -coverage.xml \ No newline at end of file +coverage.xml +docker-compose.yml +codeCoverage \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6b7d12c --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +USER_UID = $(shell id -u $(USER)) + +web_test_start: + @mkdir -p codeCoverage + docker-compose up -d web_test + +web_test_stop: + $(eval DOCKER_ID := $(shell docker-compose ps -q web_test)) + @if [ $(DOCKER_ID) ]; then /bin/bash -c 'echo "stop container" && docker stop $(DOCKER_ID)'; fi + @if [ $(DOCKER_ID) ]; then /bin/bash -c 'echo "rm container" && docker rm $(DOCKER_ID)'; fi + +test: + @mkdir -p codeCoverage + @docker-compose build test && \ + docker-compose run --rm test /bin/bash -c \ + '(composer install --prefer-dist --no-interaction && \ + php vendor/atoum/atoum/bin/atoum -c coverage.php -d tests/units/)' ; \ + docker-compose run --rm test /bin/bash -c \ + 'chown $(USER_UID):$(USER_UID) . -R' diff --git a/README.md b/README.md index 8f11085..f05f2a5 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ To launch unit tests, run the following command: ```php vendor/atoum/atoum/bin/atoum -c coverage.php -d tests/units/``` +OR + +```make test``` (docker and docker-compose are required) + **php xdebug extension must be installed for code coverage report to be generated** ## Documentation diff --git a/docker-compose.yml.dist b/docker-compose.yml.dist new file mode 100644 index 0000000..2923fd5 --- /dev/null +++ b/docker-compose.yml.dist @@ -0,0 +1,10 @@ +web_test: + image: nginx + volumes: + - "./codeCoverage:/usr/share/nginx/html:ro" + ports: + - "8080:80" +test: + build: docker/test + volumes: + - ".:/data" diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile new file mode 100644 index 0000000..9593f4b --- /dev/null +++ b/docker/test/Dockerfile @@ -0,0 +1,12 @@ +FROM php:7 + +RUN pecl install xdebug +RUN docker-php-ext-enable xdebug +RUN curl -sS https://getcomposer.org/installer | php && \ + mv composer.phar /usr/local/bin/composer +RUN apt-get update && apt-get install -y \ + git + +COPY ./ssh/ssh_config /etc/ssh/ssh_config + +WORKDIR /data \ No newline at end of file diff --git a/docker/test/ssh/ssh_config b/docker/test/ssh/ssh_config new file mode 100644 index 0000000..64779c2 --- /dev/null +++ b/docker/test/ssh/ssh_config @@ -0,0 +1,2 @@ +Host * + StrictHostKeyChecking no \ No newline at end of file diff --git a/src/PriorityHandler/StandardPriorityHandler.php b/src/PriorityHandler/StandardPriorityHandler.php index 15c2102..5393b68 100644 --- a/src/PriorityHandler/StandardPriorityHandler.php +++ b/src/PriorityHandler/StandardPriorityHandler.php @@ -65,7 +65,7 @@ public function remove(Priority $priority) } $default = $this->getDefault(); unset($this->priorities[$priority->getLevel()]); - if ($priority === $default) { + if ($priority->getLevel() === $default->getLevel()) { $this->defaultIndex = 0; } else { $this->setDefault($default); @@ -122,7 +122,6 @@ public function getDefault() */ public function setDefault(Priority $priority) { - if (!isset($this->priorities[$priority->getLevel()])) { throw new PriorityLevelException('Level ' . $priority->getLevel() . ' doesn\'t exist.'); } @@ -137,19 +136,13 @@ public function setDefault(Priority $priority) */ public function getPriorityByName($name) { - $returnPriority = null; foreach ($this->priorities as $priority) { if ($priority->getName() === $name) { - $returnPriority = $priority; - break; + return $priority; } } - if (null === $returnPriority) { - throw new \InvalidArgumentException('Level name' . $name . ' doesn\'t exist.'); - } - - return $returnPriority; + throw new \InvalidArgumentException('Level name' . $name . ' doesn\'t exist.'); } /** @@ -180,7 +173,13 @@ public function getHighest() */ public function getLowest() { - return end(array_values($this->priorities)); + $lowest = end(array_values($this->priorities)); + + if (false === $lowest) { + return new Priority('', 0); + } + + return $lowest; } /** @@ -199,9 +198,6 @@ public function getBefore(Priority $priority) while ($searchPriority = next($this->priorities)) { if ($searchPriority->getLevel() === $priority->getLevel()) { $prevPriority = prev($this->priorities); - if (false === $prevPriority) { - return $searchPriority; - } return $prevPriority; } } @@ -224,7 +220,7 @@ public function getAfter(Priority $priority) if (false === $nextPriority) { return $searchPriority; } - return $searchPriority; + return $nextPriority; } while ($searchPriority = next($this->priorities)) { if ($searchPriority->getLevel() === $priority->getLevel()) { diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index 108717a..2eb0a5e 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -27,7 +27,7 @@ public function testFileAdapterClass() public function testFileAdapter__construct() { - $this->object($this->newTestedInstance('/tmp/test/')); + $this->object(new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/')); } public function testFileAdapter__constructWithFilesystemError(Filesystem $fs, Finder $finder, LockHandlerFactory $lockHandlerFactory) @@ -1387,9 +1387,7 @@ public function testFileAdapterRenameQueue() $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = function ($queue) { - static $i = 0; - if ($i < 3) { - $i++; + if (strstr($queue, 'new')) { return false; } return true; diff --git a/tests/units/PriorityHandler/StandardPriorityHandler.php b/tests/units/PriorityHandler/StandardPriorityHandler.php new file mode 100644 index 0000000..24df4ef --- /dev/null +++ b/tests/units/PriorityHandler/StandardPriorityHandler.php @@ -0,0 +1,330 @@ +add(new Priority('testPriority', 100)); + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->add(new Priority('testPriorityTwo', 100)); + }); + } + + public function testStandardPriorityHandlerAddWithAddPriorityWithNameAlreadyExists() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->add(new Priority('testPriority', 200)); + }); + } + + public function testStandardPriorityHandlerAdd() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $this->given($standardPriorityHandler) + ->class($standardPriorityHandler->add(new Priority('testPriority', 100)))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $this->given($standardPriorityHandler) + ->array($standardPriorityHandler->getAll())->isEqualTo([0 => new Priority('', 0, $standardPriorityHandler), 100 => new Priority('testPriority', 100, $standardPriorityHandler)]); + } + + public function testStandardPriorityHandlerRemoveWithNoPriority() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->remove(new Priority('testPriority', 100)); + }); + } + + public function testStandardPriorityHandlerRemoveWithDefaultValue() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $standardPriorityHandler->setDefault(new Priority('testPriority', 100)); + $this->given($standardPriorityHandler) + ->class($standardPriorityHandler->remove(new Priority('testPriority', 100)))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $this->given($standardPriorityHandler) + ->array($standardPriorityHandler->getAll())->isEqualTo([0 => new Priority('', 0, $standardPriorityHandler)]); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getDefault()->getName())->isIdenticalTo(''); + } + + public function testStandardPriorityHandlerRemove() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $this->given($standardPriorityHandler) + ->class($standardPriorityHandler->remove(new Priority('testPriority', 100)))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $this->given($standardPriorityHandler) + ->array($standardPriorityHandler->getAll())->isEqualTo([0 => new Priority('', 0, $standardPriorityHandler)]); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getDefault()->getName())->isEqualTo(''); + } + + public function testStandardPriorityHandlerClear() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $standardPriorityHandler->add(new Priority('testPriorityTwo', 200)); + $this->given($standardPriorityHandler) + ->class($standardPriorityHandler->clear())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $this->given($standardPriorityHandler) + ->array($standardPriorityHandler->getAll())->isEqualTo([0 => new Priority('', 0, $standardPriorityHandler)]); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getDefault()->getName())->isIdenticalTo(''); + } + + public function testStandardPriorityHandlerHas() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $this->given($standardPriorityHandler) + ->boolean($standardPriorityHandler->has('testPriority'))->isTrue(); + $this->given($standardPriorityHandler) + ->boolean($standardPriorityHandler->has($standardPriorityHandler->getDefault()->getName()))->isTrue(); + $this->given($standardPriorityHandler) + ->boolean($standardPriorityHandler->has('wrongPriority'))->isFalse(); + } + + public function testStandardPriorityHandlerGetPriorityByLevelWithWrongLevel() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->getPriorityByLevel(100); + }); + } + + public function testStandardPriorityHandlerGetPriorityByLevel() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $standardPriorityHandler->add(new Priority('testPriorityTwo', 200)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getPriorityByLevel(200)->getName())->isIdenticalTo('testPriorityTwo'); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getPriorityByLevel(100)->getName())->isIdenticalTo('testPriority'); + } + + public function testStandardPriorityHandlerGetPriorityByNameWithWrongLevel() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->getPriorityByName('WrongPriorityName'); + }); + } + + public function testStandardPriorityHandlerGetPriorityByName() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $standardPriorityHandler->add(new Priority('testPriorityTwo', 200)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getPriorityByName('testPriorityTwo')->getName())->isIdenticalTo('testPriorityTwo'); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getPriorityByName('testPriority')->getName())->isIdenticalTo('testPriority'); + } + + public function testStandardPriorityHandlerGetDefaultWithEmptyPriority() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->remove(new Priority('', 0)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getDefault()->getName())->isIdenticalTo(''); + } + + public function testStandardPriorityHandlerSetDefaultWithEmptyPriority() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->remove(new Priority('', 0)); + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->setDefault(new Priority('testPriority', 100)); + }); + } + + public function testStandardPriorityHandlerSetDefaultWithUndefinedValue() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->setDefault(new Priority('wrongPriority', 500)); + }); + } + + public function testStandardPriorityHandlerSetDefault() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $standardPriorityHandler->setDefault(new Priority('testPriority', 100)); + $this->given($standardPriorityHandler) + ->class($standardPriorityHandler->setDefault(new Priority('testPriority', 100)))->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getDefault()->getName())->isEqualTo('testPriority'); + } + + public function testStandardPriorityHandlerGetHighestWithEmptyPriority() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->remove(new Priority('', 0)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getHighest()->getName())->isIdenticalTo(''); + } + + public function testStandardPriorityHandlerGetHighest() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->remove(new Priority('', 0)); + $standardPriorityHandler->add(new Priority('testPriorityLow', 500)); + $standardPriorityHandler->add(new Priority('testPriorityHigh', 100)); + $this->given($standardPriorityHandler) + ->array($standardPriorityHandler->getAll())->isEqualTo([100 => new Priority('testPriorityHigh', 100, $standardPriorityHandler), 500 => new Priority('testPriorityLow', 500, $standardPriorityHandler)]); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getHighest()->getName())->isIdenticalTo('testPriorityHigh'); + } + + public function testStandardPriorityHandlerGetLowestWithEmptyPriority() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->remove(new Priority('', 0)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getLowest()->getName())->isIdenticalTo(''); + } + + public function testStandardPriorityHandlerGetLowest() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriorityHigh', 100)); + $standardPriorityHandler->add(new Priority('testPriorityLow', 200)); + $this->given($standardPriorityHandler) + ->array($standardPriorityHandler->getAll())->isEqualTo([0 => new Priority('', 0, $standardPriorityHandler), 100 => new Priority('testPriorityHigh', 100, $standardPriorityHandler), 200 => new Priority('testPriorityLow', 200, $standardPriorityHandler)]); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getLowest()->getName())->isIdenticalTo('testPriorityLow'); + } + + public function testStandardPriorityHandlerGetBeforeWithFirstValue() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriorityLow', 300)); + $standardPriorityHandler->add(new Priority('testPriorityHigh', 100)); + $standardPriorityHandler->add(new Priority('testPriorityMid', 200)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getBefore(new Priority('testPriorityMid', 200))->getName())->isIdenticalTo('testPriorityHigh'); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getBefore(new Priority('testPriorityHigh', 100))->getName())->isIdenticalTo(''); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getBefore(new Priority('testPriorityLow', 300))->getName())->isIdenticalTo('testPriorityMid'); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getBefore(new Priority('', 0))->getName())->isIdenticalTo(''); + } + + public function testStandardPriorityHandlerGetBeforeWithUndefinedValue() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->getBefore(new Priority('wrongPriority', 100)); + }); + } + + public function testStandardPriorityHandlerGetBefore() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getBefore(new Priority('testPriority', 100))->getName())->isIdenticalTo(''); + } + + public function testStandardPriorityHandlerGetAfterWithFirstValue() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getAfter(new Priority('', 0))->getName())->isIdenticalTo('testPriority'); + } + + public function testStandardPriorityHandlerGetAfterWithOneValue() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getAfter(new Priority('', 0))->getName())->isIdenticalTo(''); + } + + public function testStandardPriorityHandlerGetAfterWithLastValue() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getAfter(new Priority('testPriority', 100))->getName())->isIdenticalTo('testPriority'); + } + + public function testStandardPriorityHandlerGetAfterWithUndefinedValue() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $this->exception(function() use($standardPriorityHandler) { + $standardPriorityHandler->getAfter(new Priority('wrongPriority', 500)); + }); + } + + public function testStandardPriorityHandlerGetAfter() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriorityTwo', 200)); + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $this->given($standardPriorityHandler) + ->string($standardPriorityHandler->getAfter(new Priority('testPriority', 100))->getName())->isIdenticalTo('testPriorityTwo'); + } + + public function testStandardPriorityHandlerGetAll() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $standardPriorityHandler->add(new Priority('testPriorityTwo', 200)); + $this->given($standardPriorityHandler) + ->array($standardPriorityHandler->getAll())->isEqualTo([0 => new Priority('', 0, $standardPriorityHandler), 100 => new Priority('testPriority', 100, $standardPriorityHandler), 200 => new Priority('testPriorityTwo', 200, $standardPriorityHandler)]); + } + + public function testStandardPriorityHandlerCount() + { + $standardPriorityHandler = new \ReputationVIP\QueueClient\PriorityHandler\StandardPriorityHandler(); + + $standardPriorityHandler->remove(new Priority('', 0)); + $this->given($standardPriorityHandler) + ->integer($standardPriorityHandler->count())->isEqualTo(0); + $standardPriorityHandler->add(new Priority('testPriority', 100)); + $standardPriorityHandler->add(new Priority('testPriorityTwo', 200)); + $this->given($standardPriorityHandler) + ->integer($standardPriorityHandler->count())->isEqualTo(2); + } +} \ No newline at end of file From c6ed88be8c8bca5ea480b28d0daff3fc4c0ae816 Mon Sep 17 00:00:00 2001 From: "nicolas.couet" Date: Fri, 11 Mar 2016 16:51:51 +0100 Subject: [PATCH 38/51] fix FileAdapter tests --- .../StandardPriorityHandler.php | 7 +- tests/units/Adapter/FileAdapter.php | 657 ++++++++++++------ 2 files changed, 463 insertions(+), 201 deletions(-) diff --git a/src/PriorityHandler/StandardPriorityHandler.php b/src/PriorityHandler/StandardPriorityHandler.php index 5393b68..33b6bd8 100644 --- a/src/PriorityHandler/StandardPriorityHandler.php +++ b/src/PriorityHandler/StandardPriorityHandler.php @@ -173,13 +173,12 @@ public function getHighest() */ public function getLowest() { - $lowest = end(array_values($this->priorities)); - - if (false === $lowest) { + if (empty($this->priorities)) { return new Priority('', 0); } - return $lowest; + $priorityNames = array_values($this->priorities); + return $priorityNames[count($priorityNames) - 1]; } /** diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index 2eb0a5e..c16a44a 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -10,13 +10,16 @@ use Symfony\Component\Finder\Finder; use ReputationVIP\QueueClient\Utils\LockHandlerFactory; -class MockIOExceptionInterface extends \Exception implements IOExceptionInterface { +class MockIOExceptionInterface extends \Exception implements IOExceptionInterface +{ public function getPath() { return ''; } -}; +} + +; class FileAdapter extends atoum\test { @@ -32,26 +35,28 @@ public function testFileAdapter__construct() public function testFileAdapter__constructWithFilesystemError(Filesystem $fs, Finder $finder, LockHandlerFactory $lockHandlerFactory) { - $this->exception(function () use($fs, $finder, $lockHandlerFactory) { - $this->newTestedInstance('', null, $fs, $finder, $lockHandlerFactory); - }); + $this->exception(function () use ($fs, $finder, $lockHandlerFactory) { + $this->newTestedInstance('', null, $fs, $finder, $lockHandlerFactory); + }); $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, $lockHandlerFactory) { + $this->newTestedInstance('/tmp/test/', null, $fs, $finder, $lockHandlerFactory); + }); } public function testFileAdapterDeleteQueue() { + $this->mockGenerator->shuntParentClassCalls(); $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->calling($mockFs)->exists = true; - $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { + $this->calling($mockLockHandlerFactory)->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -63,59 +68,67 @@ public function testFileAdapterDeleteQueue() public function testFileAdapterDeleteQueueWithEmptyQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->deleteQueue(''); }); } public function testFileAdapterDeleteQueueWithNoQueueFile() { + $this->mockGenerator->shuntParentClassCalls(); $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->calling($mockFs)->exists = false; - $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { + $this->calling($mockLockHandlerFactory)->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->deleteQueue('testQueue'); }); } public function testFileAdapterDeleteQueueWithLockFailed() { + $this->mockGenerator->shuntParentClassCalls(); $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->calling($mockFs)->exists = true; - $this->calling($mockLockHandlerFactory)->getLockHandler = function($repository) { + $this->calling($mockLockHandlerFactory)->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->deleteQueue('testQueue'); }); } public function testFileAdapterCreateQueue() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -128,90 +141,102 @@ public function testFileAdapterCreateQueue() public function testFileAdapterCreateQueueWithFsException() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; $mockFs->getMockController()->exists = false; - $mockFs->getMockController()->dumpFile = function($repository) { + $mockFs->getMockController()->dumpFile = function ($repository) { throw new \Exception('test exception'); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->createQueue('testQueue'); }); } public function testFileAdapterCreateQueueWithLockFailed() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $mockFs->getMockController()->exists = false; - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->createQueue('testQueue'); }); } public function testFileAdapterCreateQueueWithEmptyQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->createQueue(''); }); } public function testFileAdapterCreateQueueWithExistingQueue() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->createQueue('testQueue'); }); } public function testFileAdapterCreateQueueWithSpaceIngQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->createQueue('test Queue'); }); } public function testFileAdapterPurgeQueue() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -220,16 +245,24 @@ public function testFileAdapterPurgeQueue() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"queue":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -241,54 +274,64 @@ public function testFileAdapterPurgeQueue() public function testFileAdapterPurgeQueueWithNoQueueFile() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter) { + $this->exception(function () use ($FileAdapter) { $FileAdapter->purgeQueue('testQueue'); }); } public function testFileAdapterPurgeQueueWithEmptyQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->purgeQueue(''); }); } - public function testFileAdapterPurgeQueueWithLockFailed() { + public function testFileAdapterPurgeQueueWithLockFailed() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->purgeQueue('testQueue'); }); } - public function testFileAdapterPurgeQueueWithEmptyQueueContent() { + public function testFileAdapterPurgeQueueWithEmptyQueueContent() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -297,34 +340,45 @@ public function testFileAdapterPurgeQueueWithEmptyQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return ''; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return ''; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->purgeQueue('testQueue'); }); } - public function testFileAdapterPurgeQueueWithBadQueueContent() { + public function testFileAdapterPurgeQueueWithBadQueueContent() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -333,35 +387,45 @@ public function testFileAdapterPurgeQueueWithBadQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"bad":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"bad":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->purgeQueue('testQueue'); }); } public function testFileAdapterIsEmptyWithEmptyQueue() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -370,16 +434,24 @@ public function testFileAdapterIsEmptyWithEmptyQueue() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"queue":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -394,13 +466,15 @@ public function testFileAdapterIsEmptyWithEmptyQueue() public function testFileAdapterIsEmptyWithNoEmptyQueue() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -409,7 +483,7 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -432,38 +506,44 @@ public function testFileAdapterIsEmptyWithNoEmptyQueue() public function testFileAdapterIsEmptyWithEmptyQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->isEmpty(''); }); } public function testFileAdapterIsEmptyWithNoQueueFile() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->isEmpty('testQueue'); }); } public function testFileAdapterIsEmptyWithEmptyQueueContent() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -472,35 +552,45 @@ public function testFileAdapterIsEmptyWithEmptyQueueContent() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return ''; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return ''; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->isEmpty('testQueue'); }); } public function testFileAdapterIsEmptyWithBadQueueContent() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -509,29 +599,39 @@ public function testFileAdapterIsEmptyWithBadQueueContent() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"bad":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"bad":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->isEmpty('testQueue'); }); } public function testFileAdapterListQueues() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; @@ -540,17 +640,21 @@ public function testFileAdapterListQueues() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'prefixTestTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'testTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'testThreeQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testOneQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'prefixTestTwoQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testTwoQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testThreeQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -564,7 +668,9 @@ public function testFileAdapterListQueues() public function testFileAdapterListQueuesWithPrefix() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; @@ -573,17 +679,21 @@ public function testFileAdapterListQueuesWithPrefix() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'prefixTestTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'testTwoQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; - $files[] = 'prefixTestOneQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testOneQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'prefixTestTwoQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testTwoQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'prefixTestOneQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -597,7 +707,9 @@ public function testFileAdapterListQueuesWithPrefix() public function testFileAdapterListQueuesWithEmptyQueue() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; @@ -613,13 +725,15 @@ public function testFileAdapterListQueuesWithEmptyQueue() public function testFileAdapterAddMessage() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -628,16 +742,24 @@ public function testFileAdapterAddMessage() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"queue":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"queue":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); @@ -687,72 +809,84 @@ public function testFileAdapterAddMessageWithDelay() public function testFileAdapterAddMessageWithEmptyQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->addMessage('', ''); }); } public function testFileAdapterAddMessageWithNoQueueFile() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->addMessage('testQueue', ''); }); } public function testFileAdapterAddMessageWithEmptyMessage() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { - $fileAdapter->addMessage('testQueue', ''); + $this->exception(function () use ($fileAdapter) { + $fileAdapter->addMessage('testQueue', ''); }); } - public function testFileAdapterAddMessageLockFailed() { + public function testFileAdapterAddMessageLockFailed() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->addMessage('testQueue', 'test message'); }); } - public function testFileAdapterAddMessageWithEmptyQueueContent() { + public function testFileAdapterAddMessageWithEmptyQueueContent() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -761,34 +895,45 @@ public function testFileAdapterAddMessageWithEmptyQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return ''; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return ''; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->addMessage('testQueue', 'test message'); }); } - public function testFileAdapterAddMessageWithBadQueueContent() { + public function testFileAdapterAddMessageWithBadQueueContent() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -797,76 +942,94 @@ public function testFileAdapterAddMessageWithBadQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"bad":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"bad":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->addMessage('testQueue', 'test message'); }); } public function testFileAdapterGetNumberMessagesWithEmptyQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getNumberMessages(''); }); } public function testFileAdapterGetNumberMessagesWithNoQueueFile() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getNumberMessages('testQueue'); }); } - public function testFileAdapterGetNumberMessagesLockFailed() { + public function testFileAdapterGetNumberMessagesLockFailed() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getNumberMessages('testQueue'); }); } - public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() { + public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -875,34 +1038,45 @@ public function testFileAdapterGetNumberMessagesWithEmptyQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return ''; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return ''; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getNumberMessages('testQueue'); }); } - public function testFileAdapterGetNumberMessagesWithBadQueueContent() { + public function testFileAdapterGetNumberMessagesWithBadQueueContent() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -911,34 +1085,45 @@ public function testFileAdapterGetNumberMessagesWithBadQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"bad":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"bad":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getNumberMessages('testQueue'); }); } - public function testFileAdapterGetNumberMessages() { + public function testFileAdapterGetNumberMessages() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -947,7 +1132,7 @@ public function testFileAdapterGetNumberMessages() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -968,93 +1153,107 @@ public function testFileAdapterGetNumberMessages() { public function testFileAdapterGetMessagesWithEmptyQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getMessages('', 1); }); } public function testFileAdapterGetMessagesWithNoQueueFile() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getMessages('testQueue', 1); }); } public function testFileAdapterAddMessagesWithNoNumericNbrMsg() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getMessages('testQueue', 'toto'); }); } public function testFileAdapterGetMessagesWithNotValidNumericNbrMsg() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getMessages('testQueue', -5); }); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getMessages('testQueue', (\ReputationVIP\QueueClient\Adapter\FileAdapter::MAX_NB_MESSAGES + 1)); }); } - public function testFileAdapterGetMessagesLockFailed() { + public function testFileAdapterGetMessagesLockFailed() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getMessages('testQueue'); }); } - public function testFileAdapterGetMessagesWithEmptyQueueContent() { + public function testFileAdapterGetMessagesWithEmptyQueueContent() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -1063,34 +1262,45 @@ public function testFileAdapterGetMessagesWithEmptyQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return ''; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return ''; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getMessages('testQueue'); }); } - public function testFileAdapterGetMessagesWithBadQueueContent() { + public function testFileAdapterGetMessagesWithBadQueueContent() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -1099,34 +1309,45 @@ public function testFileAdapterGetMessagesWithBadQueueContent() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"bad":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"bad":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->getMessages('testQueue'); }); } - public function testFileAdapterGetMessages() { + public function testFileAdapterGetMessages() + { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -1135,7 +1356,7 @@ public function testFileAdapterGetMessages() { $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1158,111 +1379,127 @@ public function testFileAdapterGetMessages() { public function testFileAdapterDeleteMessageWithEmptyQueueName() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->deleteMessage('', []); }); } public function testFileAdapterDeleteMessageWithNoQueueFile() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter, $priorityHandler) { + $this->exception(function () use ($fileAdapter, $priorityHandler) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } public function testFileAdapterDeleteMessageWithNoMessage() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->deleteMessage('testQueue', []); }); } public function testFileAdapterDeleteMessageWithNoIdField() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; $FileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($FileAdapter, $priorityHandler) { + $this->exception(function () use ($FileAdapter, $priorityHandler) { $FileAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest()->getLevel()]); }); } public function testFileAdapterDeleteMessageWithNotPriorityField() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915']); }); } public function testFileAdapterDeleteMessageWithBadMessageType() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $mockFs->getMockController()->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->deleteMessage('testQueue', 'message'); }); } public function testFileAdapterDeleteMessageLockFailed() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = false; return $mockLockHandler; }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter, $priorityHandler) { + $this->exception(function () use ($fileAdapter, $priorityHandler) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } public function testFileAdapterDeleteMessageWithEmptyQueueContent() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -1271,35 +1508,45 @@ public function testFileAdapterDeleteMessageWithEmptyQueueContent() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return ''; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return ''; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter, $priorityHandler) { + $this->exception(function () use ($fileAdapter, $priorityHandler) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } public function testFileAdapterDeleteMessageWithBadQueueContent() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -1308,35 +1555,45 @@ public function testFileAdapterDeleteMessageWithBadQueueContent() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { $mockSplFileInfo = new \mock\Symfony\Component\Finder\SplFileInfo('', '', ''); - $mockSplFileInfo->getMockController()->getExtension = function () { return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; }; - $mockSplFileInfo->getMockController()->getRelativePathname = function () use($file) { return $file; }; - $mockSplFileInfo->getMockController()->getPathname = function () use($file) { return '/tmp/test/' . $file; }; - $mockSplFileInfo->getMockController()->getContents = function () use($file) { return '{"bad":[]}'; }; + $mockSplFileInfo->getMockController()->getExtension = function () { + return \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + }; + $mockSplFileInfo->getMockController()->getRelativePathname = function () use ($file) { + return $file; + }; + $mockSplFileInfo->getMockController()->getPathname = function () use ($file) { + return '/tmp/test/' . $file; + }; + $mockSplFileInfo->getMockController()->getContents = function () use ($file) { + return '{"bad":[]}'; + }; $mocksSplFileInfo[] = $mockSplFileInfo; } return new ArrayIterator($mocksSplFileInfo); }; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', $priorityHandler, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter, $priorityHandler) { + $this->exception(function () use ($fileAdapter, $priorityHandler) { $fileAdapter->deleteMessage('testQueue', ['id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest()->getLevel()]); }); } public function testFileAdapterDeleteMessage() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $priorityHandler = new ThreeLevelPriorityHandler(); $mockFs->getMockController()->exists = true; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -1345,7 +1602,7 @@ public function testFileAdapterDeleteMessage() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1366,22 +1623,26 @@ public function testFileAdapterDeleteMessage() public function testFileAdapterRenameQueueWithEmptyParameter() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->renameQueue('', 'newTestQueue'); }); - $this->exception(function() use($fileAdapter) { + $this->exception(function () use ($fileAdapter) { $fileAdapter->renameQueue('testQueue', ''); }); } public function testFileAdapterRenameQueue() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; @@ -1392,7 +1653,7 @@ public function testFileAdapterRenameQueue() } return true; }; - $mockLockHandlerFactory->getMockController()->getLockHandler = function($repository) { + $mockLockHandlerFactory->getMockController()->getLockHandler = function ($repository) { $mockLockHandler = new \mock\Symfony\Component\Filesystem\LockHandler($repository); $mockLockHandler->getMockController()->lock = true; return $mockLockHandler; @@ -1401,7 +1662,7 @@ public function testFileAdapterRenameQueue() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue' . \ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR . $priority->getName() . '.' . \ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { @@ -1422,7 +1683,9 @@ public function testFileAdapterRenameQueue() public function testFileAdapterGetPriorityHandler() { + $this->mockGenerator->shuntParentClassCalls(); $mockFs = new \mock\Symfony\Component\Filesystem\Filesystem; + $this->mockGenerator->unshuntParentClassCalls(); $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; From 7e57338323a077e6ca9051308cdf38df39c50263 Mon Sep 17 00:00:00 2001 From: "nicolas.couet" Date: Mon, 14 Mar 2016 10:01:08 +0100 Subject: [PATCH 39/51] Update test --- tests/units/Adapter/FileAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index c16a44a..4092126 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -787,7 +787,7 @@ public function testFileAdapterAddMessageWithDelay() $files = []; $priorities = $priorityHandler->getAll(); foreach ($priorities as $priority) { - $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority.'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; + $files[] = 'testQueue'.\ReputationVIP\QueueClient\Adapter\FileAdapter::PRIORITY_SEPARATOR.$priority->getName().'.'.\ReputationVIP\QueueClient\Adapter\FileAdapter::QUEUE_FILE_EXTENSION; } $mocksSplFileInfo = []; foreach ($files as $file) { From 202b4894c779e7b3fd477a65bac3b20c6d646d5d Mon Sep 17 00:00:00 2001 From: "nicolas.couet" Date: Mon, 14 Mar 2016 11:11:45 +0100 Subject: [PATCH 40/51] fix tests --- tests/units/Adapter/FileAdapter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index 4092126..e141a36 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -190,6 +190,7 @@ public function testFileAdapterCreateQueueWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->calling($mockFs)->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { $fileAdapter->createQueue(''); From db53044b6b61eb14dffa141d2a4c514787c42369 Mon Sep 17 00:00:00 2001 From: "nicolas.couet" Date: Mon, 14 Mar 2016 14:30:48 +0100 Subject: [PATCH 41/51] Update test --- tests/units/Adapter/FileAdapter.php | 4 +- tests/units/Adapter/SQSAdapter.php | 224 ++++++++++++++++++++++++++++ 2 files changed, 227 insertions(+), 1 deletion(-) diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index e141a36..d1329c2 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -74,6 +74,7 @@ public function testFileAdapterDeleteQueueWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $this->calling($mockFs)->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { $fileAdapter->deleteQueue(''); @@ -513,6 +514,7 @@ public function testFileAdapterIsEmptyWithEmptyQueueName() $mockFinder = new \mock\Symfony\Component\Finder\Finder; $mockLockHandlerFactory = new \mock\ReputationVIP\QueueClient\Utils\LockHandlerFactory; + $mockFs->getMockController()->exists = true; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { $fileAdapter->isEmpty(''); @@ -833,7 +835,7 @@ public function testFileAdapterAddMessageWithNoQueueFile() $mockFs->getMockController()->exists = false; $fileAdapter = new \ReputationVIP\QueueClient\Adapter\FileAdapter('/tmp/test/', null, $mockFs, $mockFinder, $mockLockHandlerFactory); $this->exception(function () use ($fileAdapter) { - $fileAdapter->addMessage('testQueue', ''); + $fileAdapter->addMessage('testQueue', 'test Message one'); }); } diff --git a/tests/units/Adapter/SQSAdapter.php b/tests/units/Adapter/SQSAdapter.php index f3989bc..91c523c 100644 --- a/tests/units/Adapter/SQSAdapter.php +++ b/tests/units/Adapter/SQSAdapter.php @@ -31,6 +31,28 @@ public function testSQSAdapterAddMessageWithEmptyMessage() }); } + public function testSQSAdapterAddMessageWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->sendMessage = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->addMessage('testQueue', 'test message'); + }); + } + public function testSQSAdapterAddMessage() { $this->mockGenerator->orphanize('__construct'); @@ -89,6 +111,28 @@ public function testSQSAdapterAddMessagesWithEmptyQueueName() }); } + public function testSQSAdapterAddMessagesWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->sendMessageBatch = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->addMessages('testQueue', array_fill(0, 11, 'test message')); + }); + } + public function testSQSAdapterGetMessagesWithEmptyQueueName() { $this->mockGenerator->orphanize('__construct'); @@ -142,6 +186,28 @@ public function testSQSAdapterGetMessagesWithNoMessage() ->array($sqsAdapter->getMessages('testQueue', 5))->isEmpty(); } + public function testSQSAdapterGetMessagesWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->receiveMessage = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->getMessages('testQueue'); + }); + } + public function testSQSAdapterGetMessages() { $this->mockGenerator->orphanize('__construct'); @@ -225,6 +291,32 @@ public function testSQSAdapterDeleteMessageWithNoMessagePriority() }); } + public function testSQSAdapterDeleteMessageWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $priorityHandler = new ThreeLevelPriorityHandler(); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockQueueUrlModel->getMockController()->get = function () use($mockQueueUrlModel) { + return null; + }; + $mockSqsClient->getMockController()->deleteMessage = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter, $priorityHandler) { + $sqsAdapter->deleteMessage('testQueue', ['priority' => $priorityHandler->getHighest()->getLevel(), 'ReceiptHandle' => 'testReceiptHandle']); + }); + } + public function testSQSAdapterDeleteMessage() { $this->mockGenerator->orphanize('__construct'); @@ -281,6 +373,29 @@ public function testSQSAdapterIsEmptyWithEmptyQueue() ->boolean($sqsAdapter->isEmpty('testQueue'))->IsTrue(); } + public function testSQSAdapterIsEmptyWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->getQueueAttributes = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->isEmpty('testQueue'); + }); + } + + public function testSQSAdapterIsEmpty() { $this->mockGenerator->orphanize('__construct'); @@ -337,6 +452,28 @@ public function testSQSAdapterGetNumberMessagesWithEmptyQueue() ->integer($sqsAdapter->getNumberMessages('testQueue'))->IsEqualTo(0); } + public function testSQSAdapterGetNumberMessagesWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->getQueueAttributes = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->getNumberMessages('testQueue'); + }); + } + public function testSQSAdapterGetNumberMessages() { $this->mockGenerator->orphanize('__construct'); @@ -372,6 +509,28 @@ public function testSQSAdapterDeleteQueueWithEmptyQueueName() }); } + public function testSQSAdapterDeleteQueueWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->deleteQueue = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->deleteQueue('testQueue'); + }); + } + public function testSQSAdapterDeleteQueue() { $this->mockGenerator->orphanize('__construct'); @@ -406,6 +565,28 @@ public function testSQSAdapterCreateQueueWithEmptyQueueName() }); } + public function testSQSAdapterCreateQueueWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->createQueue = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->createQueue('testQueue'); + }); + } + public function testSQSAdapterCreateQueue() { $this->mockGenerator->orphanize('__construct'); @@ -439,6 +620,27 @@ public function testSQSAdapterPurgeQueueWithEmptyQueueName() $sqsAdapter->purgeQueue(''); }); } + public function testSQSAdapterPurgeQueueWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->purgeQueue = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->purgeQueue('testQueue'); + }); + } public function testSQSAdapterPurgeQueue() { @@ -485,6 +687,28 @@ public function testSQSAdapterListQueuesWithPrefix() ->array($sqsAdapter->listQueues('prefix'))->containsValues(['prefixTestQueueOne', 'prefixTestQueueTwo']); } + public function testSQSAdapterListQueuesWithSqsException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient); + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $sqsException = new \mock\Aws\Sqs\Exception\SqsException; + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockSqsClient->getMockController()->listQueues = function () use ($sqsException) { + throw $sqsException; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->listQueues(); + }); + } + public function testSQSAdapterListQueues() { $this->mockGenerator->orphanize('__construct'); From 0b0a28be74574bb12c692403c094ea5895931f0a Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Mon, 6 Jun 2016 15:27:44 +0200 Subject: [PATCH 42/51] Handle message in exception --- .../Exception/InvalidMessageException.php | 26 ++++++++++++++++++- src/Adapter/FileAdapter.php | 10 +++---- src/Adapter/MemoryAdapter.php | 10 +++---- src/Adapter/SQSAdapter.php | 12 ++++----- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/Adapter/Exception/InvalidMessageException.php b/src/Adapter/Exception/InvalidMessageException.php index fc55786..e8658fc 100644 --- a/src/Adapter/Exception/InvalidMessageException.php +++ b/src/Adapter/Exception/InvalidMessageException.php @@ -4,4 +4,28 @@ use ReputationVIP\QueueClient\Exception\QueueClientException; -class InvalidMessageException extends \InvalidArgumentException implements QueueClientException {} +class InvalidMessageException extends \InvalidArgumentException implements QueueClientException +{ + /** @var null|array */ + protected $queueMessage; + + /** + * @param null|array $queueMessage + * @param string $message + * @param int $code + * @param \Exception|null $previous + */ + public function __construct($queueMessage, $message = "", $code = 0, $previous = null) + { + $this->queueMessage = $queueMessage; + parent::__construct($message, $code, $previous); + } + + /** + * @return array|null + */ + public function getQueueMessage() + { + return $this->queueMessage; + } +} diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 254f5e3..5ad6a16 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -260,7 +260,7 @@ public function addMessage($queueName, $message, Priority $priority = null, $del } if (empty($message)) { - throw new InvalidMessageException('Message empty or not defined.'); + throw new InvalidMessageException($message, 'Message empty or not defined.'); } if (null === $priority) { @@ -453,19 +453,19 @@ public function deleteMessage($queueName, $message) } if (empty($message)) { - throw new InvalidMessageException('Message empty or not defined.'); + throw new InvalidMessageException($message, 'Message empty or not defined.'); } if (!is_array($message)) { - throw new InvalidMessageException('Message must be an array.'); + throw new InvalidMessageException($message, 'Message must be an array.'); } if (!isset($message['id'])) { - throw new InvalidMessageException('Message id not found in message.'); + throw new InvalidMessageException($message, 'Message id not found in message.'); } if (!isset($message['priority'])) { - throw new InvalidMessageException('Message priority not found in message.'); + throw new InvalidMessageException($message, 'Message priority not found in message.'); } $priority = $this->priorityHandler->getPriorityByLevel($message['priority']); diff --git a/src/Adapter/MemoryAdapter.php b/src/Adapter/MemoryAdapter.php index 4998525..4182cf7 100644 --- a/src/Adapter/MemoryAdapter.php +++ b/src/Adapter/MemoryAdapter.php @@ -57,7 +57,7 @@ public function addMessage($queueName, $message, Priority $priority = null, $del } if (empty($message)) { - throw new InvalidMessageException('Message empty or not defined.'); + throw new InvalidMessageException($message, 'Message empty or not defined.'); } if (null === $priority) { @@ -99,19 +99,19 @@ public function deleteMessage($queueName, $message) } if (empty($message)) { - throw new InvalidMessageException('Message empty or not defined.'); + throw new InvalidMessageException($message, 'Message empty or not defined.'); } if (!is_array($message)) { - throw new InvalidMessageException('Message must be an array.'); + throw new InvalidMessageException($message, 'Message must be an array.'); } if (!isset($message['id'])) { - throw new InvalidMessageException('Message id not found in message.'); + throw new InvalidMessageException($message, 'Message id not found in message.'); } if (!isset($message['priority'])) { - throw new InvalidMessageException('Message priority not found in message.'); + throw new InvalidMessageException($message, 'Message priority not found in message.'); } if (isset($this->queues[$queueName][$message['priority']])) { diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index eec921b..89efee1 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -78,7 +78,7 @@ public function addMessages($queueName, $messages, Priority $priority = null) foreach ($messages as $index => $message) { if (empty($message)) { - throw new InvalidMessageException('Message empty or not defined.'); + throw new InvalidMessageException($message, 'Message empty or not defined.'); } $messageData = [ @@ -122,7 +122,7 @@ public function addMessage($queueName, $message, Priority $priority = null, $del } if (empty($message)) { - throw new InvalidMessageException('Message empty or not defined.'); + throw new InvalidMessageException($message, 'Message empty or not defined.'); } if (null === $priority) { @@ -213,16 +213,16 @@ public function deleteMessage($queueName, $message) } if (empty($message)) { - throw new InvalidMessageException('Message empty or not defined.'); + throw new InvalidMessageException($message, 'Message empty or not defined.'); } if (!is_array($message)) { - throw new InvalidMessageException('Message must be an array.'); + throw new InvalidMessageException($message, 'Message must be an array.'); } if (!isset($message['ReceiptHandle'])) { - throw new InvalidMessageException('ReceiptHandle not found in message.'); + throw new InvalidMessageException($message, 'ReceiptHandle not found in message.'); } if (!isset($message['priority'])) { - throw new InvalidMessageException('Priority not found in message.'); + throw new InvalidMessageException($message, 'Priority not found in message.'); } $priority = $this->priorityHandler->getPriorityByLevel($message['priority']); From 5029407d2a789b8b8590ff05cb39d17bad6c0a2b Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Mon, 6 Jun 2016 15:35:21 +0200 Subject: [PATCH 43/51] Add exception when an error is raised unserializing message --- src/Adapter/Exception/MalformedMessageException.php | 7 +++++++ src/Adapter/SQSAdapter.php | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/Adapter/Exception/MalformedMessageException.php diff --git a/src/Adapter/Exception/MalformedMessageException.php b/src/Adapter/Exception/MalformedMessageException.php new file mode 100644 index 0000000..6e2a1e8 --- /dev/null +++ b/src/Adapter/Exception/MalformedMessageException.php @@ -0,0 +1,7 @@ + $message) { - $messages[$messageId]['Body'] = unserialize($message['Body']); + try { + $messages[$messageId]['Body'] = unserialize($message['Body']); + } catch (\Exception $e) { + $message['priority'] = $priority->getLevel(); + + throw new MalformedMessageException($message, 'Message seems to be malformed.'); + } $messages[$messageId]['priority'] = $priority->getLevel(); } From 5104c5713346490f10c48223bc33fe40fdd54d7f Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Mon, 6 Jun 2016 16:31:29 +0200 Subject: [PATCH 44/51] Fix unit tests and problems with namespace --- .../Exception/MalformedMessageException.php | 4 +--- src/Adapter/SQSAdapter.php | 9 ++++++- tests/units/Adapter/SQSAdapter.php | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Adapter/Exception/MalformedMessageException.php b/src/Adapter/Exception/MalformedMessageException.php index 6e2a1e8..2f6784d 100644 --- a/src/Adapter/Exception/MalformedMessageException.php +++ b/src/Adapter/Exception/MalformedMessageException.php @@ -1,7 +1,5 @@ $message) { try { $messages[$messageId]['Body'] = unserialize($message['Body']); + + // for php 7 compatibility + if (false === $messages[$messageId]['Body']) { + $message['priority'] = $priority->getLevel(); + + throw new MalformedMessageException($message, 'Message seems to be malformed.'); + } } catch (\Exception $e) { $message['priority'] = $priority->getLevel(); diff --git a/tests/units/Adapter/SQSAdapter.php b/tests/units/Adapter/SQSAdapter.php index 0c2d567..4a109a9 100644 --- a/tests/units/Adapter/SQSAdapter.php +++ b/tests/units/Adapter/SQSAdapter.php @@ -827,4 +827,28 @@ public function testSQSAdapterGetPrioritiesHandler() $this->given($sqsAdapter) ->class($sqsAdapter->getPriorityHandler())->hasInterface('\ReputationVIP\QueueClient\PriorityHandler\PriorityHandlerInterface'); } + + public function testMalformedMessageException() + { + $this->mockGenerator->orphanize('__construct'); + $this->mockGenerator->shuntParentClassCalls(); + $mockSqsClient = new \mock\Aws\Sqs\SqsClient; + $mockQueueUrlModel = new \mock\Guzzle\Service\Resource\Model; + $priorityHandler = new ThreeLevelPriorityHandler(); + $sqsAdapter = new \ReputationVIP\QueueClient\Adapter\SQSAdapter($mockSqsClient, $priorityHandler); + + $mockSqsClient->getMockController()->getQueueUrl = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $mockQueueUrlModel->getMockController()->get = function () use($mockQueueUrlModel) { + return [['Body' => 'test message one']]; + }; + $mockSqsClient->getMockController()->receiveMessage = function () use($mockQueueUrlModel) { + return $mockQueueUrlModel; + }; + $this->exception(function() use($sqsAdapter) { + $sqsAdapter->getMessages('testQueue', 1); + })->isInstanceOf('\ReputationVIP\QueueClient\Adapter\Exception\MalformedMessageException'); + } + } From 6cce32af3f322cc0117a6e51bcf7eeccfdc90cf4 Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Mon, 6 Jun 2016 17:32:27 +0200 Subject: [PATCH 45/51] Avoid php notice with unserialize Because test server is in PHP7 and won't catch exception --- src/Adapter/SQSAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/SQSAdapter.php b/src/Adapter/SQSAdapter.php index 9da19b4..2db2ea8 100644 --- a/src/Adapter/SQSAdapter.php +++ b/src/Adapter/SQSAdapter.php @@ -195,7 +195,7 @@ public function getMessages($queueName, $nbMsg = 1, Priority $priority = null) } foreach ($messages as $messageId => $message) { try { - $messages[$messageId]['Body'] = unserialize($message['Body']); + $messages[$messageId]['Body'] = @unserialize($message['Body']); // for php 7 compatibility if (false === $messages[$messageId]['Body']) { From 391d84cfae1b44475cee577f6dda39d2cfc7904a Mon Sep 17 00:00:00 2001 From: Nicolas COUET Date: Tue, 7 Jun 2016 17:36:22 +0200 Subject: [PATCH 46/51] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de9829..44f2c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Queue Client Changelog +## v1.0.3 + +- Use Priority objects instead of string +- Throw execption when receive malformed message + ## v1.0.2 - Fix bulk send action with SQS From e4e5c2eb0919e745bc57e095f37073ad8c0c69e8 Mon Sep 17 00:00:00 2001 From: Olivier Balais Date: Wed, 6 Dec 2017 10:40:14 +0100 Subject: [PATCH 47/51] Make use of new Symfony/Lock component --- composer.json | 5 +- src/Adapter/FileAdapter.php | 58 +++++++++++------------ src/Utils/LockHandlerFactory.php | 16 ------- src/Utils/LockHandlerFactoryInterface.php | 17 ------- 4 files changed, 32 insertions(+), 64 deletions(-) delete mode 100644 src/Utils/LockHandlerFactory.php delete mode 100644 src/Utils/LockHandlerFactoryInterface.php diff --git a/composer.json b/composer.json index fd73bd7..8ffe487 100644 --- a/composer.json +++ b/composer.json @@ -8,8 +8,9 @@ } ], "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": { diff --git a/src/Adapter/FileAdapter.php b/src/Adapter/FileAdapter.php index 5ad6a16..4fdabea 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.'); @@ -62,7 +62,7 @@ public function __construct($repository, PriorityHandlerInterface $priorityHandl } if (null === $lockHandlerFactory) { - $lockHandlerFactory = new LockHandlerFactory(); + $lockHandlerFactory = new Factory(new FlockStore()); } if (null === $priorityHandler) { @@ -126,8 +126,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 +148,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 +170,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 +182,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 +205,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 +239,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 +291,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 +335,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 +399,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 +431,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 +570,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 +579,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 @@ - Date: Wed, 6 Dec 2017 10:40:28 +0100 Subject: [PATCH 48/51] Prepare 2.0 release --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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 From 3624b5fe37220038a689bad942d6bc8b4e7099e3 Mon Sep 17 00:00:00 2001 From: Olivier Balais Date: Wed, 6 Dec 2017 11:41:55 +0100 Subject: [PATCH 49/51] Fix tests --- .travis.yml | 4 +- composer.json | 2 +- docker/test/Dockerfile | 4 +- src/Adapter/FileAdapter.php | 9 +- tests/units/Adapter/FileAdapter.php | 408 ++++++++++++++++------------ 5 files changed, 245 insertions(+), 182 deletions(-) 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/composer.json b/composer.json index 8ffe487..e039a3e 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "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 4fdabea..3415369 100644 --- a/src/Adapter/FileAdapter.php +++ b/src/Adapter/FileAdapter.php @@ -61,15 +61,12 @@ public function __construct($repository, PriorityHandlerInterface $priorityHandl $finder = new Finder(); } - if (null === $lockHandlerFactory) { - $lockHandlerFactory = new Factory(new FlockStore()); - } - 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; diff --git a/tests/units/Adapter/FileAdapter.php b/tests/units/Adapter/FileAdapter.php index d1329c2..840824d 100644 --- a/tests/units/Adapter/FileAdapter.php +++ b/tests/units/Adapter/FileAdapter.php @@ -8,19 +8,16 @@ use Symfony\Component\Filesystem\Exception\IOExceptionInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; -use ReputationVIP\QueueClient\Utils\LockHandlerFactory; +use Symfony\Component\Lock\Factory; class MockIOExceptionInterface extends \Exception implements IOExceptionInterface { - public function getPath() { return ''; } } -; - class FileAdapter extends atoum\test { public function testFileAdapterClass() @@ -33,17 +30,20 @@ public function testFileAdapter__construct() $this->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) From f99790d17961d7e983b938137721bf767fd8cdb4 Mon Sep 17 00:00:00 2001 From: Olivier Balais Date: Thu, 7 Dec 2017 10:18:57 +0100 Subject: [PATCH 50/51] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f05f2a5..1b7ce37 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ OR ### Requirements -- PHP 5.5 or above. +- PHP 7.1.3 or above. ### Submitting bugs and feature requests @@ -87,7 +87,7 @@ Bugs and feature requests are tracked on [GitHub](https://github.com/ReputationV ### Framework Integrations -- [Symfony2](http://symfony.com) with its own [Queue Client Bundle](https://github.com/ReputationVIP/queue-client-bundle). +- [Symfony](http://symfony.com) with its own [Queue Client Bundle](https://github.com/ReputationVIP/queue-client-bundle). ### Author From ed63df5201b4c974063a8872a83b75d752580ebf Mon Sep 17 00:00:00 2001 From: victorynox Date: Mon, 26 Mar 2018 16:26:53 +0300 Subject: [PATCH 51/51] Fixed dependencies version --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index e039a3e..533c25d 100644 --- a/composer.json +++ b/composer.json @@ -8,10 +8,10 @@ } ], "require": { - "symfony/filesystem": ">=3.4", - "symfony/finder": ">=3.4", - "symfony/lock": ">=3.4", - "aws/aws-sdk-php": ">=2.7" + "symfony/filesystem": "^3.4", + "symfony/finder": "^3.4", + "symfony/lock": "^3.4", + "aws/aws-sdk-php": "^2.7" }, "require-dev": { "atoum/atoum": "~3.1",