diff -Nru php-invoker-1.1.4/build.xml php-invoker-2.0.0/build.xml --- php-invoker-1.1.4/build.xml 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/build.xml 2018-01-27 06:52:17.000000000 +0000 @@ -1,29 +1,19 @@ - - + + - - - - + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + - diff -Nru php-invoker-1.1.4/composer.json php-invoker-2.0.0/composer.json --- php-invoker-1.1.4/composer.json 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/composer.json 2018-01-27 06:52:17.000000000 +0000 @@ -1,6 +1,6 @@ { "name": "phpunit/php-invoker", - "description": "Utility class for invoking callables with a timeout.", + "description": "Invoke callables with a timeout", "type": "library", "keywords": [ "process" @@ -17,13 +17,17 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-invoker/issues" }, + "prefer-stable": true, + "config": { + "optimize-autoloader": true, + "sort-packages": true + }, "require": { - "php": ">=5.3.3", - "phpunit/php-timer": ">=1.0.6", + "php": "^7.1", "ext-pcntl": "*" }, "require-dev": { - "phpunit/phpunit": "~4" + "phpunit/phpunit": "^6.5" }, "autoload": { "classmap": [ @@ -34,6 +38,11 @@ "classmap": [ "tests/" ] + }, + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } } } diff -Nru php-invoker-1.1.4/debian/Autoload.php.tpl php-invoker-2.0.0/debian/Autoload.php.tpl --- php-invoker-1.1.4/debian/Autoload.php.tpl 2016-03-19 20:44:47.000000000 +0000 +++ php-invoker-2.0.0/debian/Autoload.php.tpl 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ - Thu, 29 Mar 2018 10:33:58 -1000 + php-invoker (1.1.4-3) unstable; urgency=medium * Team upload diff -Nru php-invoker-1.1.4/debian/control php-invoker-2.0.0/debian/control --- php-invoker-1.1.4/debian/control 2016-03-19 20:35:05.000000000 +0000 +++ php-invoker-2.0.0/debian/control 2018-03-29 20:32:07.000000000 +0000 @@ -2,16 +2,16 @@ Section: php Priority: optional Maintainer: Debian PHP PEAR Maintainers -Uploaders: Luis Uribe , Thomas Goirand +Uploaders: David Prévot Build-Depends: ant, debhelper (>= 8), phpab, phpunit, pkg-php-tools (>= 1.7~) -Standards-Version: 3.9.7 +Standards-Version: 4.1.3 Homepage: https://github.com/sebastianbergmann/php-invoker -Vcs-Git: git://anonscm.debian.org/pkg-php/php-invoker.git -Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-php/php-invoker.git +Vcs-Git: https://salsa.debian.org/php-team/pear/php-invoker.git +Vcs-Browser: https://salsa.debian.org/php-team/pear/php-invoker Package: php-invoker Architecture: all diff -Nru php-invoker-1.1.4/debian/copyright php-invoker-2.0.0/debian/copyright --- php-invoker-1.1.4/debian/copyright 2015-06-29 22:23:56.000000000 +0000 +++ php-invoker-2.0.0/debian/copyright 2018-03-29 20:18:04.000000000 +0000 @@ -1,10 +1,10 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: PHP_Invoker Upstream-Contact: Sebastian Bergmann Source: https://github.com/sebastianbergmann/php-invoker/ Files: * -Copyright: 2011-2015, Sebastian Bergmann +Copyright: 2011-2018, Sebastian Bergmann License: BSD-3-clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions diff -Nru php-invoker-1.1.4/debian/rules php-invoker-2.0.0/debian/rules --- php-invoker-1.1.4/debian/rules 2016-03-19 20:43:40.000000000 +0000 +++ php-invoker-2.0.0/debian/rules 2018-03-29 20:22:16.000000000 +0000 @@ -5,7 +5,6 @@ override_dh_auto_build: phpab \ --output src/Autoload.php \ - --template debian/Autoload.php.tpl \ src mkdir --parents PHP vendor ln -s ../src PHP/Invoker @@ -15,7 +14,7 @@ tests override_dh_auto_clean: - rm -rf PHP + rm -rf PHP vendor override_dh_auto_test: ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS))) diff -Nru php-invoker-1.1.4/.gitignore php-invoker-2.0.0/.gitignore --- php-invoker-1.1.4/.gitignore 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/.gitignore 2018-01-27 06:52:17.000000000 +0000 @@ -1,6 +1,6 @@ -/composer.lock -/composer.phar /.idea +/.php_cs +/.php_cs.cache +/composer.lock /vendor -/phpunit.xml diff -Nru php-invoker-1.1.4/LICENSE php-invoker-2.0.0/LICENSE --- php-invoker-1.1.4/LICENSE 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/LICENSE 2018-01-27 06:52:17.000000000 +0000 @@ -1,6 +1,6 @@ -PHP_Invoker +php-invoker -Copyright (c) 2011-2015, Sebastian Bergmann . +Copyright (c) 2011-2018, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without diff -Nru php-invoker-1.1.4/.php_cs.dist php-invoker-2.0.0/.php_cs.dist --- php-invoker-1.1.4/.php_cs.dist 1970-01-01 00:00:00.000000000 +0000 +++ php-invoker-2.0.0/.php_cs.dist 2018-01-27 06:52:17.000000000 +0000 @@ -0,0 +1,149 @@ + + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +EOF; + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules( + [ + 'array_syntax' => ['syntax' => 'short'], + 'binary_operator_spaces' => [ + 'align_double_arrow' => true, + 'align_equals' => true + ], + 'blank_line_after_namespace' => true, + 'blank_line_before_statement' => [ + 'statements' => [ + 'break', + 'continue', + 'return', + 'throw', + 'try', + ], + ], + 'braces' => true, + 'cast_spaces' => true, + 'class_attributes_separation' => ['elements' => ['method']], + 'compact_nullable_typehint' => true, + 'concat_space' => ['spacing' => 'one'], + 'declare_equal_normalize' => ['space' => 'none'], + 'declare_strict_types' => true, + 'dir_constant' => true, + 'elseif' => true, + 'encoding' => true, + 'full_opening_tag' => true, + 'function_declaration' => true, + 'header_comment' => ['header' => $header, 'separate' => 'none'], + 'indentation_type' => true, + 'line_ending' => true, + 'list_syntax' => ['syntax' => 'short'], + 'lowercase_cast' => true, + 'lowercase_constants' => true, + 'lowercase_keywords' => true, + 'magic_constant_casing' => true, + 'method_argument_space' => ['ensure_fully_multiline' => true], + 'modernize_types_casting' => true, + 'native_function_casing' => true, + 'native_function_invocation' => true, + 'no_alias_functions' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_closing_tag' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_consecutive_blank_lines' => true, + 'no_homoglyph_names' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => ['use' => 'print'], + 'no_null_property_initialization' => true, + 'no_short_bool_cast' => true, + 'no_short_echo_tag' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_inside_parenthesis' => true, + 'no_superfluous_elseif' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unneeded_curly_braces' => true, + 'no_unneeded_final_method' => true, + 'no_unreachable_default_argument_value' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'non_printable_character' => true, + 'normalize_index_brace' => true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + 'constant_public', + 'constant_protected', + 'constant_private', + 'property_public', + 'property_protected', + 'property_private', + 'construct', + 'destruct', + 'magic', + 'phpunit', + 'method_public', + 'method_protected', + 'method_private', + ], + ], + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_align' => true, + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_indent' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_empty_return' => true, + 'phpdoc_no_package' => true, + 'phpdoc_order' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_to_comment' => true, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'phpdoc_types_order' => true, + 'phpdoc_var_without_name' => true, + 'pow_to_exponentiation' => true, + 'protected_to_private' => true, + 'return_type_declaration' => ['space_before' => 'none'], + 'self_accessor' => true, + 'short_scalar_cast' => true, + 'simplified_null_return' => true, + 'single_blank_line_at_eof' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'single_quote' => true, + 'standardize_not_equals' => true, + 'ternary_to_null_coalescing' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'visibility_required' => true, + 'void_return' => true, + 'whitespace_after_comma_in_array' => true, + ] + ) + ->setFinder( + PhpCsFixer\Finder::create() + ->files() + ->in(__DIR__ . '/src') + ->in(__DIR__ . '/tests') + ->name('*.php') + ); diff -Nru php-invoker-1.1.4/phpunit.xml php-invoker-2.0.0/phpunit.xml --- php-invoker-1.1.4/phpunit.xml 1970-01-01 00:00:00.000000000 +0000 +++ php-invoker-2.0.0/phpunit.xml 2018-01-27 06:52:17.000000000 +0000 @@ -0,0 +1,19 @@ + + + + tests + + + + + src + + + diff -Nru php-invoker-1.1.4/phpunit.xml.dist php-invoker-2.0.0/phpunit.xml.dist --- php-invoker-1.1.4/phpunit.xml.dist 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/phpunit.xml.dist 1970-01-01 00:00:00.000000000 +0000 @@ -1,18 +0,0 @@ - - - - - tests - - - - - - src - - - - diff -Nru php-invoker-1.1.4/README.md php-invoker-2.0.0/README.md --- php-invoker-1.1.4/README.md 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/README.md 2018-01-27 06:52:17.000000000 +0000 @@ -1,14 +1,13 @@ -# PHP_Invoker +# php-invoker -`PHP_Invoker` is an utility class for invoking callables with a timeout. +`php-invoker` provides the means to invoke a callable with a timeout. ## Installation -To add `PHP_Invoker` as a local, per-project dependency to your project, simply add a dependency on `phpunit/php-invoker` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on `PHP_Invoker` 1.1: +You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): - { - "require": { - "phpunit/php-invoker": "1.1.*" - } - } + composer require phpunit/php-invoker +If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: + + composer require --dev phpunit/php-invoker diff -Nru php-invoker-1.1.4/src/Exception.php php-invoker-2.0.0/src/Exception.php --- php-invoker-1.1.4/src/Exception.php 1970-01-01 00:00:00.000000000 +0000 +++ php-invoker-2.0.0/src/Exception.php 2018-01-27 06:52:17.000000000 +0000 @@ -0,0 +1,15 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SebastianBergmann\Invoker; + +interface Exception +{ +} diff -Nru php-invoker-1.1.4/src/Invoker.php php-invoker-2.0.0/src/Invoker.php --- php-invoker-1.1.4/src/Invoker.php 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/src/Invoker.php 2018-01-27 06:52:17.000000000 +0000 @@ -1,6 +1,6 @@ - * @@ -8,69 +8,49 @@ * file that was distributed with this source code. */ -declare(ticks = 1); +namespace SebastianBergmann\Invoker; -/** - * Utility class for invoking callables with a timeout. - * - * @since Class available since Release 1.0.0 - */ -class PHP_Invoker +final class Invoker { /** * @var int */ - protected $timeout; + private $timeout; /** - * Invokes a callable and raises an exception when the execution does not - * finish before the specified timeout. - * - * @param callable $callable - * @param array $arguments - * @param int $timeout in seconds - * @return mixed - * @throws InvalidArgumentException + * @throws \Throwable */ - public function invoke($callable, array $arguments, $timeout) + public function invoke(callable $callable, array $arguments, int $timeout) { - if (!is_callable($callable)) { - throw new InvalidArgumentException; - } - - if (!is_integer($timeout)) { - throw new InvalidArgumentException; - } - - pcntl_signal(SIGALRM, array($this, 'callback'), TRUE); - pcntl_alarm($timeout); + \pcntl_signal( + \SIGALRM, + function (): void { + throw new TimeoutException( + \sprintf( + 'Execution aborted after %d second%s', + $this->timeout, + $this->timeout === 1 ? '' : 's' + ) + ); + }, + true + ); $this->timeout = $timeout; + \pcntl_async_signals(true); + \pcntl_alarm($timeout); + try { - $result = call_user_func_array($callable, $arguments); - } + $result = \call_user_func_array($callable, $arguments); + } catch (\Throwable $t) { + \pcntl_alarm(0); - catch (Exception $e) { - pcntl_alarm(0); - throw $e; + throw $t; } - pcntl_alarm(0); + \pcntl_alarm(0); return $result; } - - /** - * Invoked by pcntl_signal() when a SIGALRM occurs. - */ - public function callback() - { - throw new PHP_Invoker_TimeoutException( - sprintf( - 'Execution aborted after %s', - PHP_Timer::secondsToTimeString($this->timeout) - ) - ); - } } diff -Nru php-invoker-1.1.4/src/TimeoutException.php php-invoker-2.0.0/src/TimeoutException.php --- php-invoker-1.1.4/src/TimeoutException.php 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/src/TimeoutException.php 2018-01-27 06:52:17.000000000 +0000 @@ -1,6 +1,6 @@ - * @@ -8,9 +8,8 @@ * file that was distributed with this source code. */ -/** - * @since Class available since Release 1.0.0 - */ -class PHP_Invoker_TimeoutException extends RuntimeException +namespace SebastianBergmann\Invoker; + +final class TimeoutException extends \RuntimeException implements Exception { } diff -Nru php-invoker-1.1.4/tests/_fixture/TestCallable.php php-invoker-2.0.0/tests/_fixture/TestCallable.php --- php-invoker-1.1.4/tests/_fixture/TestCallable.php 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/tests/_fixture/TestCallable.php 2018-01-27 06:52:17.000000000 +0000 @@ -1,9 +1,19 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + class TestCallable { - public function test($sleep) + public function test(int $sleep): bool { - sleep($sleep); - return TRUE; + \sleep($sleep); + + return true; } } diff -Nru php-invoker-1.1.4/tests/InvokerTest.php php-invoker-2.0.0/tests/InvokerTest.php --- php-invoker-1.1.4/tests/InvokerTest.php 2015-06-21 13:32:55.000000000 +0000 +++ php-invoker-2.0.0/tests/InvokerTest.php 2018-01-27 06:52:17.000000000 +0000 @@ -1,6 +1,6 @@ - * @@ -8,60 +8,43 @@ * file that was distributed with this source code. */ -declare(ticks = 1); +namespace SebastianBergmann\Invoker; -if (!defined('FIXTURE_PATH')) { - define( - 'FIXTURE_PATH', - dirname(__FILE__) . DIRECTORY_SEPARATOR . - '_fixture' . DIRECTORY_SEPARATOR - ); -} +use PHPUnit\Framework\TestCase; /** - * Tests for PHP_Invoker. - * - * @since Class available since Release 1.0.0 + * @covers \SebastianBergmann\Invoker\Invoker */ -class PHP_InvokerTest extends PHPUnit_Framework_TestCase +class InvokerTest extends TestCase { - protected $callable; - protected $invoker; + /** + * @var \TestCallable + */ + private $callable; - protected function setUp() + /** + * @var Invoker + */ + private $invoker; + + protected function setUp(): void { - $this->callable = new TestCallable; - $this->invoker = new PHP_Invoker; + $this->callable = new \TestCallable; + $this->invoker = new Invoker; } - public function testCallableIsCorrectlyInvoked() + public function testExecutionOfCallableIsNotAbortedWhenTimeoutIsNotReached(): void { $this->assertTrue( - $this->invoker->invoke(array($this->callable, 'test'), array(0), 1) + $this->invoker->invoke([$this->callable, 'test'], [0], 1) ); } - /** - * @expectedException PHP_Invoker_TimeoutException - */ - public function testExceptionIsRaisedOnTimeout() - { - $this->invoker->invoke(array($this->callable, 'test'), array(2), 1); - } - - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsRaisedOnInvalidCallable() + public function testExecutionOfCallableIsAbortedWhenTimeoutIsReached(): void { - $this->invoker->invoke(NULL, array(), 1); - } + $this->expectException(TimeoutException::class); + $this->expectExceptionMessage('Execution aborted after 1 second'); - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionIsRaisedOnInvalidTimeout() - { - $this->invoker->invoke(array($this->callable, 'test'), array(), NULL); + $this->invoker->invoke([$this->callable, 'test'], [2], 1); } } diff -Nru php-invoker-1.1.4/.travis.yml php-invoker-2.0.0/.travis.yml --- php-invoker-1.1.4/.travis.yml 1970-01-01 00:00:00.000000000 +0000 +++ php-invoker-2.0.0/.travis.yml 2018-01-27 06:52:17.000000000 +0000 @@ -0,0 +1,25 @@ +language: php + +php: + - 7.1 + - 7.2 + - master + +sudo: false + +before_install: + - composer self-update + - composer clear-cache + +install: + - travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest + +script: + - ./vendor/bin/phpunit --coverage-clover=coverage.xml + +after_success: + - bash <(curl -s https://codecov.io/bash) + +notifications: + email: false +