diff --git a/.travis.yml b/.travis.yml index 4a51cdf..0ba9847 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: php dist: trusty +## Cache composer bits cache: directories: - $HOME/.composer/cache/files diff --git a/Makefile b/Makefile index 49f933e..accc86f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SHELL = /bin/sh -DOCKER ?= $(shell which docker) +DOCKER = $(shell which docker) PHP_VER := 7.2 IMAGE := graze/php-alpine:${PHP_VER}-test VOLUME := /srv @@ -9,8 +9,9 @@ DOCKER_RUN := ${DOCKER_RUN_BASE} ${IMAGE} PREFER_LOWEST ?= -.PHONY: install composer clean help run -.PHONY: test lint lint-fix test-unit test-integration test-matrix test-coverage test-coverage-html test-coverage-clover +.PHONY: build build-update composer-% clean help run +.PHONY: lint lint-fix +.PHONY: test test-unit test-integration test-lowest test-matrix test-coverage test-coverage-html test-coverage-clover .SILENT: help @@ -36,7 +37,7 @@ composer-%: ## Run a composer command, `make "composer- [...]"`. # Testing -test: ## Run the unit testsuites. +test: ## Run the unit and integration testsuites. test: lint test-unit lint: ## Run phpcs against the code. @@ -46,7 +47,11 @@ lint-fix: ## Run phpcsf and fix possible lint errors. ${DOCKER_RUN} vendor/bin/phpcbf -p src/ tests/ test-unit: ## Run the unit testsuite. - ${DOCKER_RUN} vendor/bin/phpunit --colors=always --testsuite unit + ${DOCKER_RUN} vendor/bin/phpunit --testsuite unit + +test-lowest: ## Test using the lowest possible versions of the dependencies +test-lowest: PREFER_LOWEST=--prefer-lowest +test-lowest: build-update test test-matrix-lowest: ## Test all version, with the lowest version ${MAKE} test-matrix PREFER_LOWEST=--prefer-lowest @@ -59,13 +64,22 @@ test-matrix: ## Run the unit tests against multiple targets. ${MAKE} PHP_VER="7.2" build-update test test-coverage: ## Run all tests and output coverage to the console. - ${DOCKER_RUN_BASE} ${IMAGE} phpdbg7 -qrr vendor/bin/phpunit --coverage-text + ${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-text test-coverage-html: ## Run all tests and output coverage to html. - ${DOCKER_RUN_BASE} ${IMAGE} phpdbg7 -qrr vendor/bin/phpunit --coverage-html=./tests/report/html + ${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-html=./tests/report/html test-coverage-clover: ## Run all tests and output clover coverage to file. - ${DOCKER_RUN_BASE} ${IMAGE} phpdbg7 -qrr vendor/bin/phpunit --coverage-clover=./tests/report/coverage.clover + ${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-clover=./tests/report/coverage.clover + + +# Examples + +example-lines: ## Run the lines example + ${DOCKER_RUN} php tests/example/lines.php + +example-table: ## Run the table example + ${DOCKER_RUN} php tests/example/table.php # Help diff --git a/README.md b/README.md index 00a7f20..1156e8b 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,16 @@ Run multiple `Synfony\Process`'s at the same time. Via Composer -``` bash +```bash $ composer require graze/parallel-process ``` +If you want to use Tables or Lines to output to the console, include: + +```bash +$ composer require graze/console-diff-renderer +``` + ## Usage ``` php @@ -41,11 +47,12 @@ $pool->run(); // blocking that will run till it finishes Visual output of the parallel processes ```php -$table = new Table($output); +$pool = new \Graze\ParallelProcess\Pool(); for ($i = 0; $i < 5; $i++) { $time = $i + 5; - $table->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' => $time]); + $pool->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' => $time]); } +$table = new \Graze\ParallelProcess\Table($output, $pool); $table->run(); ``` @@ -58,11 +65,11 @@ Write the output of each process to the screen ```php $pool = new \Graze\ParallelProcess\Pool(); $pool->setMaxSimultaneous(3); -$lines = new Lines($output, $pool); for ($i = 0; $i < 5; $i++) { $time = $i + 5; - $lines->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' . $time]); + $pool->add(new Process(sprintf('for i in `seq 1 %d` ; do date ; sleep 1 ; done', $time)), ['sleep' . $time]); } +$lines = new \Graze\ParallelProcess\Lines($output, $pool); $lines->run(); ``` diff --git a/composer.json b/composer.json index c887ade..09269f1 100644 --- a/composer.json +++ b/composer.json @@ -1,56 +1,58 @@ { - "name": "graze/parallel-process", - "description": "run a pool of processes simultaneously", - "keywords": [ - "graze", - "parallel-process" - ], - "homepage": "https://github.com/graze/parallel-process", - "license": "MIT", - "authors": [ - { - "name": "Harry Bragg", - "email": "harry.bragg@graze.com", - "role": "Developer" - }, - { - "name": "Graze Developers", - "email": "developers@graze.com", - "homepage": "http://www.graze.com", - "role": "Development Team" - } - ], - "require": { - "php": "^5.5 | ^7.0", - "symfony/process": "^2.8 | ^3.2 | ^4.0", - "graze/data-structure": "^2.0", - "graze/console-diff-renderer": "^0.6.1" + "name": "graze/parallel-process", + "description": "run a pool of processes simultaneously", + "keywords": [ + "graze", + "parallel-process" + ], + "homepage": "https://github.com/graze/parallel-process", + "license": "MIT", + "authors": [ + { + "name": "Harry Bragg", + "email": "harry.bragg@graze.com", + "role": "Developer" }, - "require-dev": { - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^5.7.21|^6|^7", - "squizlabs/php_codesniffer": "^3", - "graze/standards": "^2", - "symfony/console": "^3.1 | ^4" - }, - "suggest": { - "symfony/console": "To use the Table to print current runs" - }, - "autoload": { - "psr-4": { - "Graze\\ParallelProcess\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "Graze\\ParallelProcess\\Test\\": "tests/src", - "Graze\\ParallelProcess\\Test\\Unit\\": "tests/unit", - "Graze\\ParallelProcess\\Test\\Integration\\": "tests/integration" - } - }, - "config": { - "platform": { - "php": "7.2" - } + { + "name": "Graze Developers", + "email": "developers@graze.com", + "homepage": "http://www.graze.com", + "role": "Development Team" + } + ], + "require": { + "php": "^5.5 | ^7.0", + "symfony/process": "^2.8 | ^3.2 | ^4.0", + "graze/data-structure": "^2.0", + "symfony/event-dispatcher": "^2.8 | ^3.2 | ^4.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^5.7.21|^6|^7", + "squizlabs/php_codesniffer": "^3", + "graze/standards": "^2", + "symfony/console": "^3.1 | ^4", + "graze/console-diff-renderer": "^0.6.1" + }, + "suggest": { + "symfony/console": "To use the Table to print current runs", + "graze/console-diff-renderer": "required to use Table and Lines" + }, + "autoload": { + "psr-4": { + "Graze\\ParallelProcess\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Graze\\ParallelProcess\\Test\\": "tests/src", + "Graze\\ParallelProcess\\Test\\Unit\\": "tests/unit", + "Graze\\ParallelProcess\\Test\\Integration\\": "tests/integration" + } + }, + "config": { + "platform": { + "php": "7.2" } + } } diff --git a/composer.lock b/composer.lock index 72e9bf1..db14ea2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ae209754248dedccd8e204bfe22fb229", + "content-hash": "a51437e8a437b9493423fcf9756db435", "packages": [ { "name": "graze/console-diff-renderer", @@ -342,6 +342,69 @@ "homepage": "https://symfony.com", "time": "2018-05-16T09:05:32+00:00" }, + { + "name": "symfony/event-dispatcher", + "version": "v4.1.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "bfb30c2ad377615a463ebbc875eba64a99f6aa3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/bfb30c2ad377615a463ebbc875eba64a99f6aa3e", + "reference": "bfb30c2ad377615a463ebbc875eba64a99f6aa3e", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "conflict": { + "symfony/dependency-injection": "<3.4" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/expression-language": "~3.4|~4.0", + "symfony/stopwatch": "~3.4|~4.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2018-07-26T09:10:45+00:00" + }, { "name": "symfony/polyfill-mbstring", "version": "v1.8.0", diff --git a/phpcs.xml b/phpcs.xml index 24ef6b9..dc28736 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -2,7 +2,7 @@