Esempio n. 1
0
 public function testSQSAdapterRenameQueue()
 {
     $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;
     };
     $mockSqsClient->getMockController()->listQueues = function () use($mockQueueUrlModel) {
         return $mockQueueUrlModel;
     };
     $mockSqsClient->getMockController()->sendMessage = function () use($mockQueueUrlModel) {
     };
     $mockQueueUrlModel->getMockController()->get = function ($attr) use($mockQueueUrlModel, $priorityHandler) {
         if ($attr === 'Messages') {
             static $i = true;
             if ($i) {
                 $i = false;
                 return [['priority' => $priorityHandler->getHighest(), 'ReceiptHandle' => 'testReceiptHandle', 'Body' => serialize('test message one')], ['priority' => $priorityHandler->getHighest(), 'ReceiptHandle' => 'testReceiptHandle', 'Body' => serialize('test message two')]];
             } else {
                 $i = true;
                 return [];
             }
         }
         return null;
     };
     $mockSqsClient->getMockController()->receiveMessage = function () use($mockQueueUrlModel) {
         return $mockQueueUrlModel;
     };
     $mockSqsClient->getMockController()->deleteMessage = function () use($mockQueueUrlModel) {
     };
     $mockSqsClient->getMockController()->createQueue = function () use($mockQueueUrlModel) {
     };
     $mockSqsClient->getMockController()->deleteQueue = function () use($mockQueueUrlModel) {
     };
     $this->given($sqsAdapter)->class($sqsAdapter->renameQueue('sourceQueue', 'targetQueue'))->hasInterface('\\ReputationVIP\\QueueClient\\Adapter\\AdapterInterface');
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 public function testFileAdapterDeleteMessage()
 {
     $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":[{"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\\";"}]}';
             };
             $mocksSplFileInfo[] = $mockSplFileInfo;
         }
         return new ArrayIterator($mocksSplFileInfo);
     };
     $this->given($FileAdapter)->class($FileAdapter->deleteMessage('testQueue', array('id' => 'testQueue-HIGH559f77704e87c5.40358915', 'priority' => $priorityHandler->getHighest())))->hasInterface('\\ReputationVIP\\QueueClient\\Adapter\\AdapterInterface');
 }