diff --git a/.travis.yml b/.travis.yml index 6ea278b..56c0543 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,18 @@ +sudo: false + language: php -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 +cache: + directories: + - $HOME/.composer/cache + - vendor + +matrix: + fast_finish: true + include: + - php: 5.5 + - php: 5.6 + - php: 7 before_script: - composer self-update diff --git a/CHANGELOG.md b/CHANGELOG.md index fbaedf2..a300247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.5.0 + +- [BC] Minimum dependency has been raised to PHP 5.5 +- Project has been migrated to PSR-4 + # 0.4.2 - Jobs (and execution result) weren't removed from the (reused) WorkerEvent until a new job was processed. These diff --git a/Module.php b/Module.php index 9fadfa1..715e604 100644 --- a/Module.php +++ b/Module.php @@ -3,29 +3,13 @@ namespace SlmQueue; use Zend\Loader; -use Zend\ModuleManager\Feature; +use Zend\ModuleManager\Feature\ConfigProviderInterface; /** * SlmQueue */ -class Module implements - Feature\AutoloaderProviderInterface, - Feature\ConfigProviderInterface +class Module implements ConfigProviderInterface { - /** - * {@inheritDoc} - */ - public function getAutoloaderConfig() - { - return array( - Loader\AutoloaderFactory::STANDARD_AUTOLOADER => array( - Loader\StandardAutoloader::LOAD_NS => array( - __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, - ), - ), - ); - } - /** * {@inheritDoc} */ diff --git a/composer.json b/composer.json index 65fe720..b8e09f1 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } ], "require": { - "php": ">=5.3.3", + "php": ">=5.5", "zendframework/zend-servicemanager": "~2.2", "zendframework/zend-stdlib": "~2.2" }, @@ -42,11 +42,16 @@ } }, "autoload": { - "psr-0": { - "SlmQueue": "src/" + "psr-4": { + "SlmQueue\\": "src/" }, "classmap": [ "./Module.php" ] + }, + "autoload-dev": { + "psr-4": { + "SlmQueueTest\\": "tests/" + } } } diff --git a/config/module.config.php b/config/module.config.php index 6273125..de5bbba 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,69 +1,87 @@ array( - 'factories' => array( - 'SlmQueue\Job\JobPluginManager' => 'SlmQueue\Factory\JobPluginManagerFactory', - 'SlmQueue\Listener\StrategyPluginManager' => 'SlmQueue\Factory\StrategyPluginManagerFactory', - 'SlmQueue\Queue\QueuePluginManager' => 'SlmQueue\Factory\QueuePluginManagerFactory' - ), - ), +use SlmQueue\Factory\JobPluginManagerFactory; +use SlmQueue\Factory\QueueControllerPluginFactory; +use SlmQueue\Factory\QueuePluginManagerFactory; +use SlmQueue\Factory\StrategyPluginManagerFactory; +use SlmQueue\Job\JobPluginManager; +use SlmQueue\Queue\QueuePluginManager; +use SlmQueue\Strategy\AttachQueueListenersStrategy; +use SlmQueue\Strategy\Factory\AttachQueueListenersStrategyFactory; +use SlmQueue\Strategy\Factory\LogJobStrategyFactory; +use SlmQueue\Strategy\FileWatchStrategy; +use SlmQueue\Strategy\InterruptStrategy; +use SlmQueue\Strategy\LogJobStrategy; +use SlmQueue\Strategy\MaxMemoryStrategy; +use SlmQueue\Strategy\MaxPollingFrequencyStrategy; +use SlmQueue\Strategy\MaxRunsStrategy; +use SlmQueue\Strategy\ProcessQueueStrategy; +use SlmQueue\Strategy\StrategyPluginManager; - 'controller_plugins' => array( - 'factories' => array( - 'queue' => 'SlmQueue\Factory\QueueControllerPluginFactory' - ), - ), +return [ + 'service_manager' => [ + 'factories' => [ + JobPluginManager::class => JobPluginManagerFactory::class, + StrategyPluginManager::class => StrategyPluginManagerFactory::class, + QueuePluginManager::class => QueuePluginManagerFactory::class + ], + ], - 'slm_queue' => array( + 'controller_plugins' => [ + 'factories' => [ + 'queue' => QueueControllerPluginFactory::class + ], + ], + + 'slm_queue' => [ /** * Worker Strategies */ - 'worker_strategies' => array( - 'default' => array( // per worker - 'SlmQueue\Strategy\AttachQueueListenersStrategy', // attaches strategies per queue - 'SlmQueue\Strategy\MaxRunsStrategy' => array('max_runs' => 100000), - 'SlmQueue\Strategy\MaxMemoryStrategy' => array('max_memory' => 100 * 1024 * 1024), - 'SlmQueue\Strategy\InterruptStrategy', - ), - 'queues' => array( // per queue - 'default' => array( - 'SlmQueue\Strategy\ProcessQueueStrategy', - ) - ), - ), + 'worker_strategies' => [ + 'default' => [ // per worker + AttachQueueListenersStrategy::class, // attaches strategies per queue + MaxRunsStrategy::class => ['max_runs' => 100000], + MaxMemoryStrategy::class => ['max_memory' => 100 * 1024 * 1024], + InterruptStrategy::class, + ], + 'queues' => [ // per queue + 'default' => [ + ProcessQueueStrategy::class, + ] + ], + ], /** * Queue configuration */ - 'queues' => array(), + 'queues' => [], /** * Job manager configuration */ - 'job_manager' => array(), + 'job_manager' => [], /** * Queue manager configuration */ - 'queue_manager' => array(), + 'queue_manager' => [], /** * Strategy manager configuration */ - 'strategy_manager' => array( - 'invokables' => array( - 'SlmQueue\Strategy\ProcessQueueStrategy' => 'SlmQueue\Strategy\ProcessQueueStrategy', - 'SlmQueue\Strategy\InterruptStrategy' => 'SlmQueue\Strategy\InterruptStrategy', - 'SlmQueue\Strategy\MaxRunsStrategy' => 'SlmQueue\Strategy\MaxRunsStrategy', - 'SlmQueue\Strategy\MaxMemoryStrategy' => 'SlmQueue\Strategy\MaxMemoryStrategy', - 'SlmQueue\Strategy\FileWatchStrategy' => 'SlmQueue\Strategy\FileWatchStrategy', - 'SlmQueue\Strategy\MaxPollingFrequencyStrategy' => 'SlmQueue\Strategy\MaxPollingFrequencyStrategy', - ), - 'factories' => array( - 'SlmQueue\Strategy\AttachQueueListenersStrategy' => 'SlmQueue\Strategy\Factory\AttachQueueListenersStrategyFactory', - 'SlmQueue\Strategy\LogJobStrategy' => 'SlmQueue\Strategy\Factory\LogJobStrategyFactory', - ) - ), - ) -); + 'strategy_manager' => [ + 'invokables' => [ + ProcessQueueStrategy::class => ProcessQueueStrategy::class, + InterruptStrategy::class => InterruptStrategy::class, + MaxRunsStrategy::class => MaxRunsStrategy::class, + MaxMemoryStrategy::class => MaxMemoryStrategy::class, + FileWatchStrategy::class => FileWatchStrategy::class, + MaxPollingFrequencyStrategy::class => MaxPollingFrequencyStrategy::class, + ], + 'factories' => [ + AttachQueueListenersStrategy::class => AttachQueueListenersStrategyFactory::class, + LogJobStrategy::class => LogJobStrategyFactory::class, + ] + ], + ] +]; diff --git a/config/slm_queue.global.php.dist b/config/slm_queue.global.php.dist index 7a31cc2..d4a649d 100644 --- a/config/slm_queue.global.php.dist +++ b/config/slm_queue.global.php.dist @@ -5,14 +5,18 @@ * forget to remove the .dist extension from the file), and configure it as you want */ -return array( - 'slm_queue' => array( +use SlmQueue\Strategy\LogJobStrategy; +use SlmQueue\Strategy\MaxMemoryStrategy; +use SlmQueue\Strategy\ProcessQueueStrategy; + +return [ + 'slm_queue' => [ /** * Allow to configure a specific queue. * * Available options depends on the queue factory */ - 'queues' => array(), + 'queues' => [], /** * This block is use to register and configure strategies to the worker event manager. The default key holds any @@ -22,35 +26,35 @@ return array( * Note that module.config.php defines a few defaults and that configuration where the value is not an array * will be ignored (thus allows you to disable preconfigured strategies). * - * 'worker_strategies' => array( - * 'default' => array( // per worker + * 'worker_strategies' => [ + * 'default' => [ // per worker * // Would disable the pre configured max memory strategy - * 'SlmQueue\Strategy\MaxMemoryStrategy' => null + * MaxMemoryStrategy::class => null * // Reconfigure the pre configured max memory strategy to use 250Mb max - * 'SlmQueue\Strategy\MaxMemoryStrategy' => array('max_memory' => 250 * 1024 * 1024) - * ), - * ), + * MaxMemoryStrategy::class => ['max_memory' => 250 * 1024 * 1024] + * ], + * ], * * As queue processing is handled by strategies it is important that for each queue a ProcessQueueStrategy * (a strategy that listens to WorkerEvent::EVENT_PROCESS) is registered. By default SlmQueue does handles that * for the queue called 'default'. * - * 'worker_strategies' => array( - * 'queues' => array( - * 'my-queue' => array( - * 'SlmQueue\Strategy\ProcessQueueStrategy', - * ) - * ), - * ), + * 'worker_strategies' => [ + * 'queues' => [ + * 'my-queue' => [ + * ProcessQueueStrategy::class, + * ] + * ], + * ], */ - 'worker_strategies' => array( - 'default' => array( // per worker - ), - 'queues' => array( // per queue - 'default' => array( - ), - ), - ), + 'worker_strategies' => [ + 'default' => [ // per worker + ], + 'queues' => [ // per queue + 'default' => [ + ], + ], + ], /** * Allow to configure the plugin manager that manages strategies. This works like any other @@ -58,13 +62,13 @@ return array( * * Add you own or override existing factories * - * 'strategy_manager' => array( - * 'factories' => array( - * 'SlmQueue\Strategy\LogJobStrategy' => 'MyVeryOwn\LogJobStrategyFactory', - * ) - * ), + * 'strategy_manager' => [ + * 'factories' => [ + * LogJobStrategy::class => 'MyVeryOwn\LogJobStrategyFactory', + * ] + * ], */ - 'strategy_manager' => array(), + 'strategy_manager' => [], /** * Allow to configure dependencies for jobs that are pulled from any queue. This works like any other @@ -72,33 +76,33 @@ return array( * a factory, just adds an element into the "factories" array, with the key being the FQCN of the job, * and the value the factory: * - * 'job_manager' => array( - * 'factories' => array( + * 'job_manager' => [ + * 'factories' => [ * 'Application\Job\UserJob' => 'Application\Factory\UserJobFactory' - * ) - * ) + * ] + * ] * * Therefore, the job will be created through the factory (the identifier and content of the job will be * automatically set after creation). Note that this plugin manager is configured as such it automatically * add any unknown classes to the invokables list. This means you should only add factories and/or abstract * factories here. */ - 'job_manager' => array(), + 'job_manager' => [], /** * Allow to add queues. You need to have at least one queue. This works like any other PluginManager in * Zend Framework 2. For instance, if you have a queue whose name is "email", you can add it as an * invokable this way: * - * 'queue_manager' => array( - * 'invokables' => array( + * 'queue_manager' => [ + * 'invokables' => [ * 'email' => 'Application\Queue\MyQueue' - * ) - * ) + * ] + * ] * * Please note that you can find built-in factories for several queue systems (Beanstalk, Amazon Sqs...) * in SlmQueueSqs and SlmQueueBeanstalk */ - 'queue_manager' => array() - ), -); + 'queue_manager' => [] + ], +]; diff --git a/src/SlmQueue/Controller/AbstractWorkerController.php b/src/Controller/AbstractWorkerController.php similarity index 99% rename from src/SlmQueue/Controller/AbstractWorkerController.php rename to src/Controller/AbstractWorkerController.php index f5c7668..b3016ce 100644 --- a/src/SlmQueue/Controller/AbstractWorkerController.php +++ b/src/Controller/AbstractWorkerController.php @@ -63,7 +63,7 @@ public function processAction() * @param array $messages * @return string */ - protected function formatOutput($queueName, array $messages = array()) + protected function formatOutput($queueName, array $messages = []) { $messages = implode("\n", array_map(function ($m) { return sprintf(' - %s', $m); diff --git a/src/SlmQueue/Controller/Exception/QueueNotFoundException.php b/src/Controller/Exception/QueueNotFoundException.php similarity index 100% rename from src/SlmQueue/Controller/Exception/QueueNotFoundException.php rename to src/Controller/Exception/QueueNotFoundException.php diff --git a/src/SlmQueue/Controller/Exception/WorkerProcessException.php b/src/Controller/Exception/WorkerProcessException.php similarity index 100% rename from src/SlmQueue/Controller/Exception/WorkerProcessException.php rename to src/Controller/Exception/WorkerProcessException.php diff --git a/src/SlmQueue/Controller/Plugin/QueuePlugin.php b/src/Controller/Plugin/QueuePlugin.php similarity index 100% rename from src/SlmQueue/Controller/Plugin/QueuePlugin.php rename to src/Controller/Plugin/QueuePlugin.php diff --git a/src/SlmQueue/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php similarity index 100% rename from src/SlmQueue/Exception/BadMethodCallException.php rename to src/Exception/BadMethodCallException.php diff --git a/src/SlmQueue/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php similarity index 100% rename from src/SlmQueue/Exception/ExceptionInterface.php rename to src/Exception/ExceptionInterface.php diff --git a/src/SlmQueue/Exception/RuntimeException.php b/src/Exception/RuntimeException.php similarity index 100% rename from src/SlmQueue/Exception/RuntimeException.php rename to src/Exception/RuntimeException.php diff --git a/src/SlmQueue/Factory/JobPluginManagerFactory.php b/src/Factory/JobPluginManagerFactory.php similarity index 100% rename from src/SlmQueue/Factory/JobPluginManagerFactory.php rename to src/Factory/JobPluginManagerFactory.php diff --git a/src/SlmQueue/Factory/QueueControllerPluginFactory.php b/src/Factory/QueueControllerPluginFactory.php similarity index 70% rename from src/SlmQueue/Factory/QueueControllerPluginFactory.php rename to src/Factory/QueueControllerPluginFactory.php index f3414bd..62b53ec 100644 --- a/src/SlmQueue/Factory/QueueControllerPluginFactory.php +++ b/src/Factory/QueueControllerPluginFactory.php @@ -3,6 +3,8 @@ namespace SlmQueue\Factory; use SlmQueue\Controller\Plugin\QueuePlugin; +use SlmQueue\Job\JobPluginManager; +use SlmQueue\Queue\QueuePluginManager; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -17,8 +19,8 @@ class QueueControllerPluginFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $serviceLocator = $serviceLocator->getServiceLocator(); - $queuePluginManager = $serviceLocator->get('SlmQueue\Queue\QueuePluginManager'); - $jobPluginManager = $serviceLocator->get('SlmQueue\Job\JobPluginManager'); + $queuePluginManager = $serviceLocator->get(QueuePluginManager::class); + $jobPluginManager = $serviceLocator->get(JobPluginManager::class); return new QueuePlugin($queuePluginManager, $jobPluginManager); } diff --git a/src/SlmQueue/Factory/QueuePluginManagerFactory.php b/src/Factory/QueuePluginManagerFactory.php similarity index 100% rename from src/SlmQueue/Factory/QueuePluginManagerFactory.php rename to src/Factory/QueuePluginManagerFactory.php diff --git a/src/SlmQueue/Factory/StrategyPluginManagerFactory.php b/src/Factory/StrategyPluginManagerFactory.php similarity index 100% rename from src/SlmQueue/Factory/StrategyPluginManagerFactory.php rename to src/Factory/StrategyPluginManagerFactory.php diff --git a/src/SlmQueue/Factory/WorkerFactory.php b/src/Factory/WorkerFactory.php similarity index 93% rename from src/SlmQueue/Factory/WorkerFactory.php rename to src/Factory/WorkerFactory.php index 2835376..cdb4f2b 100644 --- a/src/SlmQueue/Factory/WorkerFactory.php +++ b/src/Factory/WorkerFactory.php @@ -28,7 +28,7 @@ public function createService(ServiceLocatorInterface $serviceLocator, $canonica $strategies = $config['slm_queue']['worker_strategies']['default']; $eventManager = $serviceLocator->get('EventManager'); - $listenerPluginManager = $serviceLocator->get('SlmQueue\Listener\StrategyPluginManager'); + $listenerPluginManager = $serviceLocator->get(StrategyPluginManager::class); $this->attachWorkerListeners($eventManager, $listenerPluginManager, $strategies); /** @var WorkerInterface $worker */ @@ -45,13 +45,13 @@ public function createService(ServiceLocatorInterface $serviceLocator, $canonica protected function attachWorkerListeners( EventManagerInterface $eventManager, StrategyPluginManager $listenerPluginManager, - array $strategyConfig = array() + array $strategyConfig = [] ) { foreach ($strategyConfig as $strategy => $options) { // no options given, name stored as value if (is_numeric($strategy) && is_string($options)) { $strategy = $options; - $options = array(); + $options = []; } if (!is_string($strategy) || !is_array($options)) { diff --git a/src/SlmQueue/Job/AbstractJob.php b/src/Job/AbstractJob.php similarity index 100% rename from src/SlmQueue/Job/AbstractJob.php rename to src/Job/AbstractJob.php diff --git a/src/SlmQueue/Job/Exception/RuntimeException.php b/src/Job/Exception/RuntimeException.php similarity index 100% rename from src/SlmQueue/Job/Exception/RuntimeException.php rename to src/Job/Exception/RuntimeException.php diff --git a/src/SlmQueue/Job/JobInterface.php b/src/Job/JobInterface.php similarity index 100% rename from src/SlmQueue/Job/JobInterface.php rename to src/Job/JobInterface.php diff --git a/src/SlmQueue/Job/JobPluginManager.php b/src/Job/JobPluginManager.php similarity index 93% rename from src/SlmQueue/Job/JobPluginManager.php rename to src/Job/JobPluginManager.php index 24dcedc..0d44fe9 100644 --- a/src/SlmQueue/Job/JobPluginManager.php +++ b/src/Job/JobPluginManager.php @@ -22,7 +22,7 @@ class JobPluginManager extends AbstractPluginManager * @param bool $usePeeringServiceManagers * @return JobInterface */ - public function get($name, $options = array(), $usePeeringServiceManagers = true) + public function get($name, $options = [], $usePeeringServiceManagers = true) { // parent::get calls validatePlugin() so we're sure $instance is a JobInterface $instance = parent::get($name, $options, $usePeeringServiceManagers); diff --git a/src/SlmQueue/Queue/AbstractQueue.php b/src/Queue/AbstractQueue.php similarity index 95% rename from src/SlmQueue/Queue/AbstractQueue.php rename to src/Queue/AbstractQueue.php index ace74a6..fcaf34c 100644 --- a/src/SlmQueue/Queue/AbstractQueue.php +++ b/src/Queue/AbstractQueue.php @@ -58,7 +58,7 @@ public function getJobPluginManager() * @param array $metadata * @return \SlmQueue\Job\JobInterface */ - public function unserializeJob($string, array $metadata = array()) + public function unserializeJob($string, array $metadata = []) { $data = json_decode($string, true); $name = $data['metadata']['__name__']; @@ -93,10 +93,10 @@ public function serializeJob(JobInterface $job) { $job->setMetadata('__name__', $job->getMetadata('__name__', get_class($job))); - $data = array( + $data = [ 'content' => serialize($job->getContent()), 'metadata' => $job->getMetadata() - ); + ]; return json_encode($data); } diff --git a/src/SlmQueue/Queue/Exception/RuntimeException.php b/src/Queue/Exception/RuntimeException.php similarity index 100% rename from src/SlmQueue/Queue/Exception/RuntimeException.php rename to src/Queue/Exception/RuntimeException.php diff --git a/src/SlmQueue/Queue/Exception/UnsupportedOperationException.php b/src/Queue/Exception/UnsupportedOperationException.php similarity index 100% rename from src/SlmQueue/Queue/Exception/UnsupportedOperationException.php rename to src/Queue/Exception/UnsupportedOperationException.php diff --git a/src/SlmQueue/Queue/QueueAwareInterface.php b/src/Queue/QueueAwareInterface.php similarity index 100% rename from src/SlmQueue/Queue/QueueAwareInterface.php rename to src/Queue/QueueAwareInterface.php diff --git a/src/SlmQueue/Queue/QueueAwareTrait.php b/src/Queue/QueueAwareTrait.php similarity index 100% rename from src/SlmQueue/Queue/QueueAwareTrait.php rename to src/Queue/QueueAwareTrait.php diff --git a/src/SlmQueue/Queue/QueueInterface.php b/src/Queue/QueueInterface.php similarity index 86% rename from src/SlmQueue/Queue/QueueInterface.php rename to src/Queue/QueueInterface.php index ddf25d7..35900d7 100644 --- a/src/SlmQueue/Queue/QueueInterface.php +++ b/src/Queue/QueueInterface.php @@ -30,7 +30,7 @@ public function getJobPluginManager(); * @param array $options * @return void */ - public function push(JobInterface $job, array $options = array()); + public function push(JobInterface $job, array $options = []); /** * Pop a job from the queue @@ -38,7 +38,7 @@ public function push(JobInterface $job, array $options = array()); * @param array $options * @return JobInterface|null */ - public function pop(array $options = array()); + public function pop(array $options = []); /** * Delete a job from the queue diff --git a/src/SlmQueue/Queue/QueuePluginManager.php b/src/Queue/QueuePluginManager.php similarity index 100% rename from src/SlmQueue/Queue/QueuePluginManager.php rename to src/Queue/QueuePluginManager.php diff --git a/src/SlmQueue/Strategy/AbstractStrategy.php b/src/Strategy/AbstractStrategy.php similarity index 100% rename from src/SlmQueue/Strategy/AbstractStrategy.php rename to src/Strategy/AbstractStrategy.php diff --git a/src/SlmQueue/Strategy/AttachQueueListenersStrategy.php b/src/Strategy/AttachQueueListenersStrategy.php similarity index 96% rename from src/SlmQueue/Strategy/AttachQueueListenersStrategy.php rename to src/Strategy/AttachQueueListenersStrategy.php index 7710781..84a9e9a 100644 --- a/src/SlmQueue/Strategy/AttachQueueListenersStrategy.php +++ b/src/Strategy/AttachQueueListenersStrategy.php @@ -36,7 +36,7 @@ public function attach(EventManagerInterface $events) { $this->listeners[] = $events->attach( WorkerEvent::EVENT_BOOTSTRAP, - array($this, 'attachQueueListeners'), + [$this, 'attachQueueListeners'], PHP_INT_MAX ); } @@ -64,7 +64,7 @@ public function attachQueueListeners(WorkerEvent $e) // no options given, name stored as value if (is_numeric($strategy) && is_string($options)) { $strategy = $options; - $options = array(); + $options = []; } if (!is_string($strategy) || !is_array($options)) { diff --git a/src/SlmQueue/Strategy/Factory/AttachQueueListenersStrategyFactory.php b/src/Strategy/Factory/AttachQueueListenersStrategyFactory.php similarity index 87% rename from src/SlmQueue/Strategy/Factory/AttachQueueListenersStrategyFactory.php rename to src/Strategy/Factory/AttachQueueListenersStrategyFactory.php index 1dbf56b..3dd6cf0 100644 --- a/src/SlmQueue/Strategy/Factory/AttachQueueListenersStrategyFactory.php +++ b/src/Strategy/Factory/AttachQueueListenersStrategyFactory.php @@ -3,6 +3,7 @@ namespace SlmQueue\Strategy\Factory; use SlmQueue\Strategy\AttachQueueListenersStrategy; +use SlmQueue\Strategy\StrategyPluginManager; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -20,7 +21,7 @@ class AttachQueueListenersStrategyFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $sm = $serviceLocator->getServiceLocator(); - $pluginManager = $sm->get('SlmQueue\Listener\StrategyPluginManager'); + $pluginManager = $sm->get(StrategyPluginManager::class); $config = $sm->get('Config'); $strategyConfig = $config['slm_queue']['worker_strategies']['queues']; diff --git a/src/SlmQueue/Strategy/Factory/LogJobStrategyFactory.php b/src/Strategy/Factory/LogJobStrategyFactory.php similarity index 100% rename from src/SlmQueue/Strategy/Factory/LogJobStrategyFactory.php rename to src/Strategy/Factory/LogJobStrategyFactory.php diff --git a/src/SlmQueue/Strategy/FileWatchStrategy.php b/src/Strategy/FileWatchStrategy.php similarity index 93% rename from src/SlmQueue/Strategy/FileWatchStrategy.php rename to src/Strategy/FileWatchStrategy.php index a2afdfa..b8df4f5 100644 --- a/src/SlmQueue/Strategy/FileWatchStrategy.php +++ b/src/Strategy/FileWatchStrategy.php @@ -19,7 +19,7 @@ class FileWatchStrategy extends AbstractStrategy * * @var array */ - protected $files = array(); + protected $files = []; /** * Seconds between checks while idling @@ -41,7 +41,7 @@ class FileWatchStrategy extends AbstractStrategy public function setPattern($pattern) { $this->pattern = $pattern; - $this->files = array(); + $this->files = []; } /** @@ -77,17 +77,17 @@ public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_IDLE, - array($this, 'onStopConditionCheck'), + [$this, 'onStopConditionCheck'], $priority ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_JOB, - array($this, 'onStopConditionCheck'), + [$this, 'onStopConditionCheck'], 1000 ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_STATE, - array($this, 'onReportQueueState'), + [$this, 'onReportQueueState'], $priority ); } diff --git a/src/SlmQueue/Strategy/InterruptStrategy.php b/src/Strategy/InterruptStrategy.php similarity index 84% rename from src/SlmQueue/Strategy/InterruptStrategy.php rename to src/Strategy/InterruptStrategy.php index 69dae6f..ac1cffb 100644 --- a/src/SlmQueue/Strategy/InterruptStrategy.php +++ b/src/Strategy/InterruptStrategy.php @@ -22,8 +22,8 @@ public function __construct(array $options = null) // Conditional because of lack of pcntl_signal on windows if (function_exists('pcntl_signal')) { declare(ticks = 1); - pcntl_signal(SIGTERM, array($this, 'onPCNTLSignal')); - pcntl_signal(SIGINT, array($this, 'onPCNTLSignal')); + pcntl_signal(SIGTERM, [$this, 'onPCNTLSignal']); + pcntl_signal(SIGINT, [$this, 'onPCNTLSignal']); } } @@ -34,17 +34,17 @@ public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_IDLE, - array($this, 'onStopConditionCheck'), + [$this, 'onStopConditionCheck'], $priority ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_QUEUE, - array($this, 'onStopConditionCheck'), + [$this, 'onStopConditionCheck'], -1000 ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_STATE, - array($this, 'onReportQueueState'), + [$this, 'onReportQueueState'], $priority ); } @@ -71,7 +71,7 @@ public function onStopConditionCheck(WorkerEvent $event) */ public function onPCNTLSignal($signo) { - switch($signo) { + switch ($signo) { case SIGTERM: case SIGINT: $this->interrupted = true; diff --git a/src/SlmQueue/Strategy/LogJobStrategy.php b/src/Strategy/LogJobStrategy.php similarity index 93% rename from src/SlmQueue/Strategy/LogJobStrategy.php rename to src/Strategy/LogJobStrategy.php index ae30e0f..ad46b4a 100644 --- a/src/SlmQueue/Strategy/LogJobStrategy.php +++ b/src/Strategy/LogJobStrategy.php @@ -31,12 +31,12 @@ public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_JOB, - array($this, 'onLogJobProcessStart'), + [$this, 'onLogJobProcessStart'], 10000 ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_JOB, - array($this, 'onLogJobProcessDone'), + [$this, 'onLogJobProcessDone'], -1000 ); } diff --git a/src/SlmQueue/Strategy/MaxMemoryStrategy.php b/src/Strategy/MaxMemoryStrategy.php similarity index 90% rename from src/SlmQueue/Strategy/MaxMemoryStrategy.php rename to src/Strategy/MaxMemoryStrategy.php index d32df6c..81be83d 100644 --- a/src/SlmQueue/Strategy/MaxMemoryStrategy.php +++ b/src/Strategy/MaxMemoryStrategy.php @@ -35,17 +35,17 @@ public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_IDLE, - array($this, 'onStopConditionCheck'), + [$this, 'onStopConditionCheck'], $priority ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_QUEUE, - array($this, 'onStopConditionCheck'), + [$this, 'onStopConditionCheck'], -1000 ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_STATE, - array($this, 'onReportQueueState'), + [$this, 'onReportQueueState'], $priority ); } @@ -82,7 +82,7 @@ public function onStopConditionCheck(WorkerEvent $event) */ private function humanFormat($bytes) { - $units = array('b','kB','MB','GB','TB','PB'); + $units = ['b','kB','MB','GB','TB','PB']; return @round($bytes/pow(1024, ($i=floor(log($bytes, 1024)))), 2) . $units[$i]; } } diff --git a/src/SlmQueue/Strategy/MaxPollingFrequencyStrategy.php b/src/Strategy/MaxPollingFrequencyStrategy.php similarity index 96% rename from src/SlmQueue/Strategy/MaxPollingFrequencyStrategy.php rename to src/Strategy/MaxPollingFrequencyStrategy.php index 2dd3900..8e9cdf8 100644 --- a/src/SlmQueue/Strategy/MaxPollingFrequencyStrategy.php +++ b/src/Strategy/MaxPollingFrequencyStrategy.php @@ -25,7 +25,7 @@ public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_QUEUE, - array($this, 'onQueueProcessFinish'), + [$this, 'onQueueProcessFinish'], 1000 ); } diff --git a/src/SlmQueue/Strategy/MaxRunsStrategy.php b/src/Strategy/MaxRunsStrategy.php similarity index 93% rename from src/SlmQueue/Strategy/MaxRunsStrategy.php rename to src/Strategy/MaxRunsStrategy.php index 913edf7..452482b 100644 --- a/src/SlmQueue/Strategy/MaxRunsStrategy.php +++ b/src/Strategy/MaxRunsStrategy.php @@ -45,12 +45,12 @@ public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_QUEUE, - array($this, 'onStopConditionCheck'), + [$this, 'onStopConditionCheck'], -1000 ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_STATE, - array($this, 'onReportQueueState'), + [$this, 'onReportQueueState'], $priority ); } diff --git a/src/SlmQueue/Strategy/ProcessQueueStrategy.php b/src/Strategy/ProcessQueueStrategy.php similarity index 95% rename from src/SlmQueue/Strategy/ProcessQueueStrategy.php rename to src/Strategy/ProcessQueueStrategy.php index 0bc81b1..17cf59b 100644 --- a/src/SlmQueue/Strategy/ProcessQueueStrategy.php +++ b/src/Strategy/ProcessQueueStrategy.php @@ -16,12 +16,12 @@ public function attach(EventManagerInterface $events, $priority = 1) { $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_QUEUE, - array($this, 'onJobPop'), + [$this, 'onJobPop'], $priority ); $this->listeners[] = $events->attach( WorkerEvent::EVENT_PROCESS_JOB, - array($this, 'onJobProcess'), + [$this, 'onJobProcess'], $priority ); } diff --git a/src/SlmQueue/Strategy/StrategyPluginManager.php b/src/Strategy/StrategyPluginManager.php similarity index 100% rename from src/SlmQueue/Strategy/StrategyPluginManager.php rename to src/Strategy/StrategyPluginManager.php diff --git a/src/SlmQueue/Worker/AbstractWorker.php b/src/Worker/AbstractWorker.php similarity index 95% rename from src/SlmQueue/Worker/AbstractWorker.php rename to src/Worker/AbstractWorker.php index 6a1d31e..b657a22 100644 --- a/src/SlmQueue/Worker/AbstractWorker.php +++ b/src/Worker/AbstractWorker.php @@ -21,11 +21,11 @@ abstract class AbstractWorker implements WorkerInterface */ public function __construct(EventManagerInterface $eventManager) { - $eventManager->setIdentifiers(array( + $eventManager->setIdentifiers([ __CLASS__, get_called_class(), 'SlmQueue\Worker\WorkerInterface' - )); + ]); $this->eventManager = $eventManager; } @@ -33,7 +33,7 @@ public function __construct(EventManagerInterface $eventManager) /** * {@inheritDoc} */ - public function processQueue(QueueInterface $queue, array $options = array()) + public function processQueue(QueueInterface $queue, array $options = []) { $eventManager = $this->eventManager; $workerEvent = new WorkerEvent($this, $queue); diff --git a/src/SlmQueue/Worker/WorkerEvent.php b/src/Worker/WorkerEvent.php similarity index 98% rename from src/SlmQueue/Worker/WorkerEvent.php rename to src/Worker/WorkerEvent.php index aca9d12..2596bfb 100644 --- a/src/SlmQueue/Worker/WorkerEvent.php +++ b/src/Worker/WorkerEvent.php @@ -67,7 +67,7 @@ class WorkerEvent extends Event * Array of options * @var array */ - protected $options = array(); + protected $options = []; /** * @param WorkerInterface $target diff --git a/src/SlmQueue/Worker/WorkerInterface.php b/src/Worker/WorkerInterface.php similarity index 98% rename from src/SlmQueue/Worker/WorkerInterface.php rename to src/Worker/WorkerInterface.php index d14fc5b..fa9d65d 100644 --- a/src/SlmQueue/Worker/WorkerInterface.php +++ b/src/Worker/WorkerInterface.php @@ -19,7 +19,7 @@ interface WorkerInterface * @param array $options * @return array description of exit states from strategies that report it */ - public function processQueue(QueueInterface $queue, array $options = array()); + public function processQueue(QueueInterface $queue, array $options = []); /** * Process a job that comes from the given queue diff --git a/tests/SlmQueueTest/Asset/FailingJob.php b/tests/Asset/FailingJob.php similarity index 100% rename from tests/SlmQueueTest/Asset/FailingJob.php rename to tests/Asset/FailingJob.php diff --git a/tests/SlmQueueTest/Asset/QueueAwareJob.php b/tests/Asset/QueueAwareJob.php similarity index 100% rename from tests/SlmQueueTest/Asset/QueueAwareJob.php rename to tests/Asset/QueueAwareJob.php diff --git a/tests/SlmQueueTest/Asset/QueueAwareTraitJob.php b/tests/Asset/QueueAwareTraitJob.php similarity index 100% rename from tests/SlmQueueTest/Asset/QueueAwareTraitJob.php rename to tests/Asset/QueueAwareTraitJob.php diff --git a/tests/SlmQueueTest/Asset/SimpleController.php b/tests/Asset/SimpleController.php similarity index 100% rename from tests/SlmQueueTest/Asset/SimpleController.php rename to tests/Asset/SimpleController.php diff --git a/tests/SlmQueueTest/Asset/SimpleJob.php b/tests/Asset/SimpleJob.php similarity index 100% rename from tests/SlmQueueTest/Asset/SimpleJob.php rename to tests/Asset/SimpleJob.php diff --git a/tests/SlmQueueTest/Asset/SimpleQueue.php b/tests/Asset/SimpleQueue.php similarity index 86% rename from tests/SlmQueueTest/Asset/SimpleQueue.php rename to tests/Asset/SimpleQueue.php index f9fa57d..266bed6 100644 --- a/tests/SlmQueueTest/Asset/SimpleQueue.php +++ b/tests/Asset/SimpleQueue.php @@ -16,7 +16,7 @@ class SimpleQueue extends AbstractQueue /** * {@inheritDoc} */ - public function push(JobInterface $job, array $options = array()) + public function push(JobInterface $job, array $options = []) { $this->jobs[] = $this->serializeJob($job); } @@ -24,7 +24,7 @@ public function push(JobInterface $job, array $options = array()) /** * {@inheritDoc} */ - public function pop(array $options = array()) + public function pop(array $options = []) { $payload = array_pop($this->jobs); if (!$payload) { diff --git a/tests/SlmQueueTest/Asset/SimpleQueueFactory.php b/tests/Asset/SimpleQueueFactory.php similarity index 100% rename from tests/SlmQueueTest/Asset/SimpleQueueFactory.php rename to tests/Asset/SimpleQueueFactory.php diff --git a/tests/SlmQueueTest/Asset/SimpleWorker.php b/tests/Asset/SimpleWorker.php similarity index 100% rename from tests/SlmQueueTest/Asset/SimpleWorker.php rename to tests/Asset/SimpleWorker.php diff --git a/tests/SlmQueueTest/Controller/AbstractControllerTest.php b/tests/Controller/AbstractControllerTest.php similarity index 87% rename from tests/SlmQueueTest/Controller/AbstractControllerTest.php rename to tests/Controller/AbstractControllerTest.php index a93a827..0228b5a 100644 --- a/tests/SlmQueueTest/Controller/AbstractControllerTest.php +++ b/tests/Controller/AbstractControllerTest.php @@ -33,12 +33,12 @@ public function setUp() $worker = new SimpleWorker(); $worker->getEventManager()->attachAggregate(new ProcessQueueStrategy()); - $worker->getEventManager()->attachAggregate(new MaxRunsStrategy(array('max_runs' => 1))); - $config = new Config(array( - 'factories' => array( + $worker->getEventManager()->attachAggregate(new MaxRunsStrategy(['max_runs' => 1])); + $config = new Config([ + 'factories' => [ 'knownQueue' => 'SlmQueueTest\Asset\SimpleQueueFactory' - ), - )); + ], + ]); $this->queuePluginManager = new QueuePluginManager($config); $this->controller = new SimpleController($worker, $this->queuePluginManager); @@ -46,7 +46,7 @@ public function setUp() public function testThrowExceptionIfQueueIsUnknown() { - $routeMatch = new RouteMatch(array('queue' => 'unknownQueue')); + $routeMatch = new RouteMatch(['queue' => 'unknownQueue']); $this->controller->getEvent()->setRouteMatch($routeMatch); $this->setExpectedException('Zend\ServiceManager\Exception\ServiceNotFoundException'); @@ -59,7 +59,7 @@ public function testSimpleJob() $queue = $this->queuePluginManager->get('knownQueue'); $queue->push(new SimpleJob()); - $routeMatch = new RouteMatch(array('queue' => 'knownQueue')); + $routeMatch = new RouteMatch(['queue' => 'knownQueue']); $this->controller->getEvent()->setRouteMatch($routeMatch); $result = $this->controller->processAction(); @@ -73,7 +73,7 @@ public function testFailingJobThrowException() $queue = $this->queuePluginManager->get('knownQueue'); $queue->push(new FailingJob()); - $routeMatch = new RouteMatch(array('queue' => 'knownQueue')); + $routeMatch = new RouteMatch(['queue' => 'knownQueue']); $this->controller->getEvent()->setRouteMatch($routeMatch); $this->setExpectedException('SlmQueue\Controller\Exception\WorkerProcessException'); diff --git a/tests/SlmQueueTest/Controller/Plugin/QueueTest.php b/tests/Controller/Plugin/QueueTest.php similarity index 96% rename from tests/SlmQueueTest/Controller/Plugin/QueueTest.php rename to tests/Controller/Plugin/QueueTest.php index e03435e..45753e4 100644 --- a/tests/SlmQueueTest/Controller/Plugin/QueueTest.php +++ b/tests/Controller/Plugin/QueueTest.php @@ -66,7 +66,7 @@ public function testPluginPushesJobIntoQueue() $jobPluginManager = new JobPluginManager; $name = 'DefaultQueue'; - $queue = $this->getMock('SlmQueueTest\Asset\SimpleQueue', array('push'), array($name, $jobPluginManager)); + $queue = $this->getMock('SlmQueueTest\Asset\SimpleQueue', ['push'], [$name, $jobPluginManager]); $job = new SimpleJob; $queue->expects($this->once()) @@ -89,7 +89,7 @@ public function testPayloadCanBeInjectedViaPlugin() $jobPluginManager = new JobPluginManager; $name = 'DefaultQueue'; - $queue = $this->getMock('SlmQueueTest\Asset\SimpleQueue', array('push'), array($name, $jobPluginManager)); + $queue = $this->getMock('SlmQueueTest\Asset\SimpleQueue', ['push'], [$name, $jobPluginManager]); $job = new SimpleJob; $queue->expects($this->once()) @@ -102,7 +102,7 @@ public function testPayloadCanBeInjectedViaPlugin() $plugin = new QueuePlugin($queuePluginManager, $jobPluginManager); $plugin->__invoke($name); - $payload = array('foo' => 'bar'); + $payload = ['foo' => 'bar']; $result = $plugin->push('SimpleJob', $payload); $this->assertSame($payload, $result->getContent()); diff --git a/tests/SlmQueueTest/Factory/QueueControllerPluginFactoryTest.php b/tests/Factory/QueueControllerPluginFactoryTest.php similarity index 100% rename from tests/SlmQueueTest/Factory/QueueControllerPluginFactoryTest.php rename to tests/Factory/QueueControllerPluginFactoryTest.php diff --git a/tests/SlmQueueTest/Factory/WorkerFactoryTest.php b/tests/Factory/WorkerFactoryTest.php similarity index 100% rename from tests/SlmQueueTest/Factory/WorkerFactoryTest.php rename to tests/Factory/WorkerFactoryTest.php diff --git a/tests/SlmQueueTest/Job/JobPluginManagerTest.php b/tests/Job/JobPluginManagerTest.php similarity index 100% rename from tests/SlmQueueTest/Job/JobPluginManagerTest.php rename to tests/Job/JobPluginManagerTest.php diff --git a/tests/SlmQueueTest/Job/JobTest.php b/tests/Job/JobTest.php similarity index 100% rename from tests/SlmQueueTest/Job/JobTest.php rename to tests/Job/JobTest.php diff --git a/tests/SlmQueueTest/Queue/AbstractQueueTest.php b/tests/Queue/AbstractQueueTest.php similarity index 100% rename from tests/SlmQueueTest/Queue/AbstractQueueTest.php rename to tests/Queue/AbstractQueueTest.php diff --git a/tests/SlmQueueTest/Queue/QueueAwareTraitTest.php b/tests/Queue/QueueAwareTraitTest.php similarity index 100% rename from tests/SlmQueueTest/Queue/QueueAwareTraitTest.php rename to tests/Queue/QueueAwareTraitTest.php diff --git a/tests/SlmQueueTest/Queue/QueuePluginManagerTest.php b/tests/Queue/QueuePluginManagerTest.php similarity index 100% rename from tests/SlmQueueTest/Queue/QueuePluginManagerTest.php rename to tests/Queue/QueuePluginManagerTest.php diff --git a/tests/SlmQueueTest/Queue/QueueTest.php b/tests/Queue/QueueTest.php similarity index 98% rename from tests/SlmQueueTest/Queue/QueueTest.php rename to tests/Queue/QueueTest.php index 8a209f9..de27c47 100644 --- a/tests/SlmQueueTest/Queue/QueueTest.php +++ b/tests/Queue/QueueTest.php @@ -69,7 +69,7 @@ public function testCanPushThenPopWithJobMetadata() $job = $this->queue->pop(); // metadata will have reserved __name__ key with FQCN - $expected = array('Foo' => 'Bar') + array('__name__' => 'SlmQueueTest\Asset\SimpleJob'); + $expected = ['Foo' => 'Bar'] + ['__name__' => 'SlmQueueTest\Asset\SimpleJob']; $this->assertEquals($expected, $job->getMetadata()); $this->assertEquals('Bar', $job->getMetadata('Foo')); diff --git a/tests/SlmQueueTest/Strategy/AttachQueueListenersStrategyTest.php b/tests/Strategy/AttachQueueListenersStrategyTest.php similarity index 81% rename from tests/SlmQueueTest/Strategy/AttachQueueListenersStrategyTest.php rename to tests/Strategy/AttachQueueListenersStrategyTest.php index cb9adab..e24562d 100644 --- a/tests/SlmQueueTest/Strategy/AttachQueueListenersStrategyTest.php +++ b/tests/Strategy/AttachQueueListenersStrategyTest.php @@ -24,12 +24,12 @@ public function setUp() $jobPluginManager = $this->getMock('SlmQueue\Job\JobPluginManager'); $queue = $this->getMock( 'SlmQueue\Queue\AbstractQueue', - array(), - array('queueName', $jobPluginManager) + [], + ['queueName', $jobPluginManager] ); $strategyPluginManager = $this->getMock('SlmQueue\Strategy\StrategyPluginManager'); $eventManager = $this->getMock('Zend\EventManager\EventManager'); - $worker = $this->getMock('SlmQueue\Worker\AbstractWorker', array(), array($eventManager)); + $worker = $this->getMock('SlmQueue\Worker\AbstractWorker', [], [$eventManager]); $strategyMock = $this->getMock('SlmQueue\Strategy\AbstractStrategy'); $queue->expects($this->any())->method('getName')->will($this->returnValue('queueName')); @@ -41,9 +41,9 @@ public function setUp() $event->setJob($job); - $this->listener = new AttachQueueListenersStrategy($strategyPluginManager, array('queueName' => array( + $this->listener = new AttachQueueListenersStrategy($strategyPluginManager, ['queueName' => [ 'SlmQueue\Strategy\SomeStrategy', - ))); + ]]); $this->event = $event; } @@ -58,7 +58,7 @@ public function testListensToCorrectEvents() $evm = $this->getMock('Zend\EventManager\EventManagerInterface'); $evm->expects($this->at(0))->method('attach') - ->with(WorkerEvent::EVENT_BOOTSTRAP, array($this->listener, 'attachQueueListeners')); + ->with(WorkerEvent::EVENT_BOOTSTRAP, [$this->listener, 'attachQueueListeners']); $this->listener->attach($evm); } @@ -69,7 +69,7 @@ public function testAttachQueueListenersDetachedSelfFromEventManager() $eventManagerMock = $workerMock->getEventManager(); $eventManagerMock->expects($this->once())->method('detachAggregate')->with($this->listener); - $eventManagerMock->expects($this->any())->method('getEvents')->will($this->returnValue(array(WorkerEvent::EVENT_PROCESS_QUEUE))); + $eventManagerMock->expects($this->any())->method('getEvents')->will($this->returnValue([WorkerEvent::EVENT_PROCESS_QUEUE])); $eventManagerMock->expects($this->once())->method('trigger'); $this->listener->attachQueueListeners($this->event); @@ -79,17 +79,17 @@ public function testAttachQueueListenerFallbackToDefaultIfQueueNameIsNotMatched( { $workerMock = $this->event->getTarget(); $eventManagerMock = $workerMock->getEventManager(); - $eventManagerMock->expects($this->any())->method('getEvents')->will($this->returnValue(array(WorkerEvent::EVENT_PROCESS_QUEUE))); + $eventManagerMock->expects($this->any())->method('getEvents')->will($this->returnValue([WorkerEvent::EVENT_PROCESS_QUEUE])); $class = new \ReflectionClass('SlmQueue\Strategy\AttachQueueListenersStrategy'); $property = $class->getProperty('strategyConfig'); $property->setAccessible(true); - $property->setValue($this->listener, array( - 'default' => array( + $property->setValue($this->listener, [ + 'default' => [ 'SlmQueue\Strategy\SomeStrategy', - ) - )); + ] + ]); $this->listener->attachQueueListeners($this->event); } @@ -98,27 +98,27 @@ public function testAttachQueueListenersStrategyConfig() { $workerMock = $this->event->getTarget(); $eventManagerMock = $workerMock->getEventManager(); - $eventManagerMock->expects($this->any())->method('getEvents')->will($this->returnValue(array(WorkerEvent::EVENT_PROCESS_QUEUE))); + $eventManagerMock->expects($this->any())->method('getEvents')->will($this->returnValue([WorkerEvent::EVENT_PROCESS_QUEUE])); $class = new \ReflectionClass('SlmQueue\Strategy\AttachQueueListenersStrategy'); $property = $class->getProperty('strategyConfig'); $property->setAccessible(true); - $property->setValue($this->listener, array('queueName' => array( + $property->setValue($this->listener, ['queueName' => [ 'SlmQueue\Strategy\SomeStrategy', - 'SlmQueue\Strategy\OtherStrategy' => array('priority' => 3), - 'SlmQueue\Strategy\FinalStrategy' => array('foo' => 'bar'), + 'SlmQueue\Strategy\OtherStrategy' => ['priority' => 3], + 'SlmQueue\Strategy\FinalStrategy' => ['foo' => 'bar'], 'SlmQueue\Strategy\SomeStrategy' => 'not_an_array', - ))); + ]]); $property = $class->getProperty('pluginManager'); $property->setAccessible(true); $pluginManagerMock = $property->getValue($this->listener); - $pluginManagerMock->expects($this->at(0))->method('get')->with('SlmQueue\Strategy\SomeStrategy', array()); - $pluginManagerMock->expects($this->at(1))->method('get')->with('SlmQueue\Strategy\OtherStrategy', array()); // priority is removed - $pluginManagerMock->expects($this->at(2))->method('get')->with('SlmQueue\Strategy\FinalStrategy', array('foo' => 'bar')); + $pluginManagerMock->expects($this->at(0))->method('get')->with('SlmQueue\Strategy\SomeStrategy', []); + $pluginManagerMock->expects($this->at(1))->method('get')->with('SlmQueue\Strategy\OtherStrategy', []); // priority is removed + $pluginManagerMock->expects($this->at(2))->method('get')->with('SlmQueue\Strategy\FinalStrategy', ['foo' => 'bar']); $strategyMock = $this->getMock('SlmQueue\Strategy\AbstractStrategy'); @@ -133,7 +133,7 @@ public function testAttachQueueListenersThrowsExceptionWhenNoListenersHaveBeenAt { $workerMock = $this->event->getTarget(); $eventManagerMock = $workerMock->getEventManager(); - $eventManagerMock->expects($this->any())->method('getEvents')->will($this->returnValue(array(WorkerEvent::EVENT_PROCESS_IDLE))); + $eventManagerMock->expects($this->any())->method('getEvents')->will($this->returnValue([WorkerEvent::EVENT_PROCESS_IDLE])); $this->setExpectedException('SlmQueue\Exception\RunTimeException'); $this->listener->attachQueueListeners($this->event); diff --git a/tests/SlmQueueTest/Strategy/Factory/LogJobFactoryTest.php b/tests/Strategy/Factory/LogJobFactoryTest.php similarity index 100% rename from tests/SlmQueueTest/Strategy/Factory/LogJobFactoryTest.php rename to tests/Strategy/Factory/LogJobFactoryTest.php diff --git a/tests/SlmQueueTest/Strategy/FileWatchStrategyTest.php b/tests/Strategy/FileWatchStrategyTest.php similarity index 94% rename from tests/SlmQueueTest/Strategy/FileWatchStrategyTest.php rename to tests/Strategy/FileWatchStrategyTest.php index 701bfec..1dd5345 100644 --- a/tests/SlmQueueTest/Strategy/FileWatchStrategyTest.php +++ b/tests/Strategy/FileWatchStrategyTest.php @@ -45,11 +45,11 @@ public function testListensToCorrectEvents() $evm = $this->getMock('Zend\EventManager\EventManagerInterface'); $evm->expects($this->at(0))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_IDLE, array($this->listener, 'onStopConditionCheck')); + ->with(WorkerEvent::EVENT_PROCESS_IDLE, [$this->listener, 'onStopConditionCheck']); $evm->expects($this->at(1))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_JOB, array($this->listener, 'onStopConditionCheck')); + ->with(WorkerEvent::EVENT_PROCESS_JOB, [$this->listener, 'onStopConditionCheck']); $evm->expects($this->at(2))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_STATE, array($this->listener, 'onReportQueueState')); + ->with(WorkerEvent::EVENT_PROCESS_STATE, [$this->listener, 'onReportQueueState']); $this->listener->attach($evm); } diff --git a/tests/SlmQueueTest/Strategy/InterruptStrategyTest.php b/tests/Strategy/InterruptStrategyTest.php similarity index 88% rename from tests/SlmQueueTest/Strategy/InterruptStrategyTest.php rename to tests/Strategy/InterruptStrategyTest.php index dc5be93..e94fc6e 100644 --- a/tests/SlmQueueTest/Strategy/InterruptStrategyTest.php +++ b/tests/Strategy/InterruptStrategyTest.php @@ -45,11 +45,11 @@ public function testListensToCorrectEvents() $evm = $this->getMock('Zend\EventManager\EventManagerInterface'); $evm->expects($this->at(0))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_IDLE, array($this->listener, 'onStopConditionCheck')); + ->with(WorkerEvent::EVENT_PROCESS_IDLE, [$this->listener, 'onStopConditionCheck']); $evm->expects($this->at(1))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_QUEUE, array($this->listener, 'onStopConditionCheck')); + ->with(WorkerEvent::EVENT_PROCESS_QUEUE, [$this->listener, 'onStopConditionCheck']); $evm->expects($this->at(2))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_STATE, array($this->listener, 'onReportQueueState')); + ->with(WorkerEvent::EVENT_PROCESS_STATE, [$this->listener, 'onReportQueueState']); $this->listener->attach($evm); } diff --git a/tests/SlmQueueTest/Strategy/LogJobTest.php b/tests/Strategy/LogJobTest.php similarity index 93% rename from tests/SlmQueueTest/Strategy/LogJobTest.php rename to tests/Strategy/LogJobTest.php index 67b1039..5da3d41 100644 --- a/tests/SlmQueueTest/Strategy/LogJobTest.php +++ b/tests/Strategy/LogJobTest.php @@ -56,9 +56,9 @@ public function testListensToCorrectEvents() $evm = $this->getMock('Zend\EventManager\EventManagerInterface'); $evm->expects($this->at(0))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_JOB, array($this->listener, 'onLogJobProcessStart')); + ->with(WorkerEvent::EVENT_PROCESS_JOB, [$this->listener, 'onLogJobProcessStart']); $evm->expects($this->at(1))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_JOB, array($this->listener, 'onLogJobProcessDone')); + ->with(WorkerEvent::EVENT_PROCESS_JOB, [$this->listener, 'onLogJobProcessDone']); $this->listener->attach($evm); } diff --git a/tests/SlmQueueTest/Strategy/MaxMemoryStrategyTest.php b/tests/Strategy/MaxMemoryStrategyTest.php similarity index 88% rename from tests/SlmQueueTest/Strategy/MaxMemoryStrategyTest.php rename to tests/Strategy/MaxMemoryStrategyTest.php index a8954ed..06c0828 100644 --- a/tests/SlmQueueTest/Strategy/MaxMemoryStrategyTest.php +++ b/tests/Strategy/MaxMemoryStrategyTest.php @@ -57,11 +57,11 @@ public function testListensToCorrectEvents() $evm = $this->getMock('Zend\EventManager\EventManagerInterface'); $evm->expects($this->at(0))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_IDLE, array($this->listener, 'onStopConditionCheck')); + ->with(WorkerEvent::EVENT_PROCESS_IDLE, [$this->listener, 'onStopConditionCheck']); $evm->expects($this->at(1))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_QUEUE, array($this->listener, 'onStopConditionCheck')); + ->with(WorkerEvent::EVENT_PROCESS_QUEUE, [$this->listener, 'onStopConditionCheck']); $evm->expects($this->at(2))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_STATE, array($this->listener, 'onReportQueueState')); + ->with(WorkerEvent::EVENT_PROCESS_STATE, [$this->listener, 'onReportQueueState']); $this->listener->attach($evm); } diff --git a/tests/SlmQueueTest/Strategy/MaxPollingFrequencyStrategyTest.php b/tests/Strategy/MaxPollingFrequencyStrategyTest.php similarity index 94% rename from tests/SlmQueueTest/Strategy/MaxPollingFrequencyStrategyTest.php rename to tests/Strategy/MaxPollingFrequencyStrategyTest.php index 7512430..b9414a4 100644 --- a/tests/SlmQueueTest/Strategy/MaxPollingFrequencyStrategyTest.php +++ b/tests/Strategy/MaxPollingFrequencyStrategyTest.php @@ -52,7 +52,7 @@ public function testListensToCorrectEvents() $evm = $this->getMock('Zend\EventManager\EventManagerInterface'); $evm->expects($this->at(0))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_QUEUE, array($this->listener, 'onQueueProcessFinish')); + ->with(WorkerEvent::EVENT_PROCESS_QUEUE, [$this->listener, 'onQueueProcessFinish']); $this->listener->attach($evm); } diff --git a/tests/SlmQueueTest/Strategy/MaxRunsStrategyTest.php b/tests/Strategy/MaxRunsStrategyTest.php similarity index 92% rename from tests/SlmQueueTest/Strategy/MaxRunsStrategyTest.php rename to tests/Strategy/MaxRunsStrategyTest.php index 4566675..727763b 100644 --- a/tests/SlmQueueTest/Strategy/MaxRunsStrategyTest.php +++ b/tests/Strategy/MaxRunsStrategyTest.php @@ -57,9 +57,9 @@ public function testListensToCorrectEvents() $evm = $this->getMock('Zend\EventManager\EventManagerInterface'); $evm->expects($this->at(0))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_QUEUE, array($this->listener, 'onStopConditionCheck')); + ->with(WorkerEvent::EVENT_PROCESS_QUEUE, [$this->listener, 'onStopConditionCheck']); $evm->expects($this->at(1))->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_STATE, array($this->listener, 'onReportQueueState')); + ->with(WorkerEvent::EVENT_PROCESS_STATE, [$this->listener, 'onReportQueueState']); $this->listener->attach($evm); } diff --git a/tests/SlmQueueTest/Strategy/ProcessQueueStrategyTest.php b/tests/Strategy/ProcessQueueStrategyTest.php similarity index 91% rename from tests/SlmQueueTest/Strategy/ProcessQueueStrategyTest.php rename to tests/Strategy/ProcessQueueStrategyTest.php index 52a568c..1e984b5 100644 --- a/tests/SlmQueueTest/Strategy/ProcessQueueStrategyTest.php +++ b/tests/Strategy/ProcessQueueStrategyTest.php @@ -30,7 +30,7 @@ public function setUp() $event = new WorkerEvent($worker, $queue); $this->job = new SimpleJob(); - $event->setOptions(array('foo' => 'bar')); + $event->setOptions(['foo' => 'bar']); $event->setJob($this->job); $this->listener = new ProcessQueueStrategy(); @@ -50,10 +50,10 @@ public function testListensToCorrectEvents() $evm->expects($this->at(0)) ->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_QUEUE, array($this->listener, 'onJobPop'), $priority); + ->with(WorkerEvent::EVENT_PROCESS_QUEUE, [$this->listener, 'onJobPop'], $priority); $evm->expects($this->at(1)) ->method('attach') - ->with(WorkerEvent::EVENT_PROCESS_JOB, array($this->listener, 'onJobProcess'), $priority); + ->with(WorkerEvent::EVENT_PROCESS_JOB, [$this->listener, 'onJobProcess'], $priority); $this->listener->attach($evm, $priority); } @@ -69,7 +69,7 @@ public function testOnJobPopPopsFromQueueWithOptions() $this->event->getQueue() ->expects($this->once()) ->method('pop') - ->with(array('foo' => 'bar')) + ->with(['foo' => 'bar']) ->will($this->returnValue($this->job)); $called = false; diff --git a/tests/SlmQueueTest/Util/ServiceManagerFactory.php b/tests/Util/ServiceManagerFactory.php similarity index 98% rename from tests/SlmQueueTest/Util/ServiceManagerFactory.php rename to tests/Util/ServiceManagerFactory.php index d44246c..c9bd23b 100644 --- a/tests/SlmQueueTest/Util/ServiceManagerFactory.php +++ b/tests/Util/ServiceManagerFactory.php @@ -50,7 +50,7 @@ public static function setConfig(array $config) public static function getServiceManager() { $serviceManager = new ServiceManager(new ServiceManagerConfig( - isset(static::$config['service_manager']) ? static::$config['service_manager'] : array() + isset(static::$config['service_manager']) ? static::$config['service_manager'] : [] )); $serviceManager->setService('ApplicationConfig', static::$config); $serviceManager->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory'); diff --git a/tests/SlmQueueTest/Worker/AbstractWorkerTest.php b/tests/Worker/AbstractWorkerTest.php similarity index 80% rename from tests/SlmQueueTest/Worker/AbstractWorkerTest.php rename to tests/Worker/AbstractWorkerTest.php index 5d48e71..5571b79 100644 --- a/tests/SlmQueueTest/Worker/AbstractWorkerTest.php +++ b/tests/Worker/AbstractWorkerTest.php @@ -3,8 +3,6 @@ namespace SlmQueueTest\Worker; use PHPUnit_Framework_TestCase as TestCase; -use SlmQueue\Strategy\InterruptStrategy; -use SlmQueue\Strategy\ProcessQueueStrategy; use SlmQueue\Worker\WorkerEvent; use SlmQueue\Strategy\MaxRunsStrategy; use SlmQueueTest\Asset\SimpleWorker; @@ -46,13 +44,13 @@ public function testWorkerLoopEvents($exitedBy, $exitAfter, $expectedCalledEvent $this->exitedBy = $exitedBy; $this->exitAfter = $exitAfter; - $this->actualCalled = array(); + $this->actualCalled = []; - $eventManager->attach(WorkerEvent::EVENT_BOOTSTRAP, array($this, 'callbackWorkerLoopEvents')); - $eventManager->attach(WorkerEvent::EVENT_FINISH, array($this, 'callbackWorkerLoopEvents')); - $eventManager->attach(WorkerEvent::EVENT_PROCESS_IDLE, array($this, 'callbackWorkerLoopEvents')); - $eventManager->attach(WorkerEvent::EVENT_PROCESS_QUEUE, array($this, 'callbackWorkerLoopEvents')); - $eventManager->attach(WorkerEvent::EVENT_PROCESS_STATE, array($this, 'callbackWorkerLoopEvents')); + $eventManager->attach(WorkerEvent::EVENT_BOOTSTRAP, [$this, 'callbackWorkerLoopEvents']); + $eventManager->attach(WorkerEvent::EVENT_FINISH, [$this, 'callbackWorkerLoopEvents']); + $eventManager->attach(WorkerEvent::EVENT_PROCESS_IDLE, [$this, 'callbackWorkerLoopEvents']); + $eventManager->attach(WorkerEvent::EVENT_PROCESS_QUEUE, [$this, 'callbackWorkerLoopEvents']); + $eventManager->attach(WorkerEvent::EVENT_PROCESS_STATE, [$this, 'callbackWorkerLoopEvents']); $this->worker->processQueue($this->queue); @@ -61,20 +59,20 @@ public function testWorkerLoopEvents($exitedBy, $exitAfter, $expectedCalledEvent public function providerWorkerLoopEvents() { - return array( - array(WorkerEvent::EVENT_BOOTSTRAP, 1, array( + return [ + [WorkerEvent::EVENT_BOOTSTRAP, 1, [ WorkerEvent::EVENT_BOOTSTRAP => 1, WorkerEvent::EVENT_FINISH => 1, - WorkerEvent::EVENT_PROCESS_STATE => 1) - ), - array(WorkerEvent::EVENT_PROCESS_QUEUE, 10, array( + WorkerEvent::EVENT_PROCESS_STATE => 1] + ], + [WorkerEvent::EVENT_PROCESS_QUEUE, 10, [ WorkerEvent::EVENT_BOOTSTRAP => 1, WorkerEvent::EVENT_PROCESS_QUEUE => 10, WorkerEvent::EVENT_PROCESS_IDLE => 5, WorkerEvent::EVENT_FINISH => 1, - WorkerEvent::EVENT_PROCESS_STATE => 1) - ) - ); + WorkerEvent::EVENT_PROCESS_STATE => 1] + ] + ]; } /** @@ -113,9 +111,9 @@ public function testProcessQueueSetOptionsOnWorkerEvent() /** @var EventManager $eventManager */ $eventManager = $this->worker->getEventManager(); - $eventManager->attach(WorkerEvent::EVENT_PROCESS_QUEUE, array($this, 'callbackProcessQueueSetOptionsOnWorkerEvent')); + $eventManager->attach(WorkerEvent::EVENT_PROCESS_QUEUE, [$this, 'callbackProcessQueueSetOptionsOnWorkerEvent']); - $options = array('foo' => 'bar'); + $options = ['foo' => 'bar']; $this->worker->processQueue($this->queue, $options); diff --git a/tests/SlmQueueTest/Worker/WorkerEventTest.php b/tests/Worker/WorkerEventTest.php similarity index 100% rename from tests/SlmQueueTest/Worker/WorkerEventTest.php rename to tests/Worker/WorkerEventTest.php diff --git a/tests/testing.config.php b/tests/testing.config.php index d26d9ee..f8362c2 100644 --- a/tests/testing.config.php +++ b/tests/testing.config.php @@ -16,25 +16,25 @@ * and is licensed under the MIT license. For more information, see * . */ -return array( - 'service_manager' => array( - 'factories' => array( +return [ + 'service_manager' => [ + 'factories' => [ 'SlmQueueTest\Asset\SimpleWorker' => 'SlmQueue\Factory\WorkerFactory', - ) - ), - 'slm_queue' => array( + ] + ], + 'slm_queue' => [ /** * Queues config */ - 'queue_manager' => array( - 'factories' => array( + 'queue_manager' => [ + 'factories' => [ 'basic-queue' => function ($locator) { $parentLocator = $locator->getServiceLocator(); $jobPluginManager = $parentLocator->get('SlmQueue\Job\JobPluginManager'); return new \SlmQueueTest\Asset\SimpleQueue('basic-queue', $jobPluginManager); } - ) - ) - ), -); + ] + ] + ], +];