pax_global_header00006660000000000000000000000064137351114440014515gustar00rootroot0000000000000052 comment=ee85000e3727c7e7132a63086494d1efe6f094ef phpunit-environment-5.1.3/000077500000000000000000000000001373511144400155545ustar00rootroot00000000000000phpunit-environment-5.1.3/.github/000077500000000000000000000000001373511144400171145ustar00rootroot00000000000000phpunit-environment-5.1.3/.github/FUNDING.yml000066400000000000000000000000321373511144400207240ustar00rootroot00000000000000github: sebastianbergmann phpunit-environment-5.1.3/.github/workflows/000077500000000000000000000000001373511144400211515ustar00rootroot00000000000000phpunit-environment-5.1.3/.github/workflows/ci.yml000066400000000000000000000052221373511144400222700ustar00rootroot00000000000000# https://help.github.com/en/categories/automating-your-workflow-with-github-actions on: - "pull_request" - "push" name: "CI" jobs: coding-guidelines: name: "Coding Guidelines" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Run friendsofphp/php-cs-fixer" run: "php7.3 ./tools/php-cs-fixer fix --diff-format=udiff --dry-run --show-progress=dots --using-cache=no --verbose" type-checker: name: "Type Checker" runs-on: "ubuntu-latest" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Update dependencies with composer" run: "php7.3 ./tools/composer update --no-ansi --no-interaction --no-progress" - name: "Run vimeo/psalm" run: "php7.3 ./tools/psalm --config=.psalm/config.xml --no-progress --shepherd --show-info=false --stats" backward-compatibility: name: Backward Compatibility runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Fetch tags run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: php-version: 7.4 coverage: none extensions: intl - name: Run roave/backward-compatibility-check run: ./tools/roave-backward-compatibility-check --from=5.0.0 tests: name: "Tests" runs-on: "ubuntu-latest" strategy: fail-fast: false matrix: php-version: - "7.3" - "7.4" - "8.0" steps: - name: "Checkout" uses: "actions/checkout@v2" - name: "Install PHP with extensions" uses: "shivammathur/setup-php@v1" with: php-version: "${{ matrix.php-version }}" coverage: "pcov" - name: "Cache dependencies installed with composer" uses: "actions/cache@v1" with: path: "~/.composer/cache" key: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}" restore-keys: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" - name: "Install dependencies with composer" run: "./tools/composer update --no-ansi --no-interaction --no-progress" - name: "Run tests with phpunit/phpunit" run: "vendor/bin/phpunit --coverage-clover=coverage.xml" - name: "Send code coverage report to Codecov.io" env: CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}" run: "bash <(curl -s https://codecov.io/bash) || true" phpunit-environment-5.1.3/.gitignore000066400000000000000000000001331373511144400175410ustar00rootroot00000000000000/.idea /.php_cs /.php_cs.cache /.phpunit.result.cache /.psalm/cache /composer.lock /vendor phpunit-environment-5.1.3/.phive/000077500000000000000000000000001373511144400167455ustar00rootroot00000000000000phpunit-environment-5.1.3/.phive/phars.xml000066400000000000000000000006701373511144400206070ustar00rootroot00000000000000 phpunit-environment-5.1.3/.php_cs.dist000066400000000000000000000173751373511144400200100ustar00rootroot00000000000000 For the full copyright and license information, please view the LICENSE file that was distributed with this source code. EOF; $finder = PhpCsFixer\Finder::create() ->files() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests'); return PhpCsFixer\Config::create() ->setFinder($finder) ->setRiskyAllowed(true) ->setRules([ 'align_multiline_comment' => true, 'array_indentation' => true, 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => [ 'operators' => [ '=' => 'align', '=>' => 'align', ], ], 'blank_line_after_namespace' => true, 'blank_line_before_statement' => [ 'statements' => [ 'break', 'continue', 'declare', 'do', 'for', 'foreach', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', ], ], 'braces' => true, 'cast_spaces' => true, 'class_attributes_separation' => ['elements' => ['const', 'method', 'property']], 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, '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, 'global_namespace_import' => [ 'import_classes' => true, 'import_constants' => true, 'import_functions' => true, ], 'header_comment' => ['header' => $header, 'separate' => 'none'], 'indentation_type' => true, 'is_null' => true, 'line_ending' => true, 'list_syntax' => ['syntax' => 'short'], 'logical_operators' => true, 'lowercase_cast' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'lowercase_static_reference' => true, 'magic_constant_casing' => true, 'method_argument_space' => ['ensure_fully_multiline' => true], 'modernize_types_casting' => true, 'multiline_comment_opening_closing' => true, 'multiline_whitespace_before_semicolons' => true, 'native_constant_invocation' => false, 'native_function_casing' => false, 'native_function_invocation' => false, 'new_with_braces' => false, 'no_alias_functions' => true, 'no_alternative_syntax' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_blank_lines_before_namespace' => true, 'no_closing_tag' => true, 'no_empty_comment' => true, 'no_empty_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_blank_lines' => true, 'no_homoglyph_names' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => ['use' => 'print'], 'no_multiline_whitespace_around_double_arrow' => true, 'no_null_property_initialization' => true, 'no_php4_constructor' => 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_superfluous_phpdoc_tags' => [ 'allow_mixed' => 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_unset_on_property' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => 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_static', 'property_protected_static', 'property_private_static', 'property_public', 'property_protected', 'property_private', 'method_public_static', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private', 'method_protected_static', 'method_private_static', ], ], 'ordered_imports' => [ 'imports_order' => [ PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_CONST, PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_FUNCTION, PhpCsFixer\Fixer\Import\OrderedImportsFixer::IMPORT_TYPE_CLASS, ] ], 'ordered_interfaces' => [ 'direction' => 'ascend', 'order' => 'alpha', ], 'phpdoc_add_missing_param_annotation' => false, '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_summary' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_trim_consecutive_blank_line_separation' => true, 'phpdoc_types' => ['groups' => ['simple', 'meta']], 'phpdoc_types_order' => true, 'phpdoc_var_without_name' => true, 'pow_to_exponentiation' => true, 'protected_to_private' => true, 'return_assignment' => true, 'return_type_declaration' => ['space_before' => 'none'], 'self_accessor' => true, 'semicolon_after_instruction' => true, 'set_type_to_cast' => true, 'short_scalar_cast' => true, 'simplified_null_return' => false, '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, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, 'visibility_required' => [ 'elements' => [ 'const', 'method', 'property', ], ], 'void_return' => true, 'whitespace_after_comma_in_array' => true, ]); phpunit-environment-5.1.3/.psalm/000077500000000000000000000000001373511144400167465ustar00rootroot00000000000000phpunit-environment-5.1.3/.psalm/baseline.xml000066400000000000000000000010171373511144400212510ustar00rootroot00000000000000 shell_exec('stty size') shell_exec('stty') string HHVM_VERSION phpunit-environment-5.1.3/.psalm/config.xml000066400000000000000000000036261373511144400207440ustar00rootroot00000000000000 phpunit-environment-5.1.3/ChangeLog.md000066400000000000000000000122741373511144400177330ustar00rootroot00000000000000# Changes in sebastianbergmann/environment All notable changes in `sebastianbergmann/environment` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## [5.1.3] - 2020-09-28 ### Changed * Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3` ## [5.1.2] - 2020-06-26 ### Added * This component is now supported on PHP 8 ## [5.1.1] - 2020-06-15 ### Changed * Tests etc. are now ignored for archive exports ## [5.1.0] - 2020-04-14 ### Added * `Runtime::performsJustInTimeCompilation()` returns `true` if PHP 8's JIT is active, `false` otherwise ## [5.0.2] - 2020-03-31 ### Fixed * [#55](https://github.com/sebastianbergmann/environment/issues/55): `stty` command is executed even if no tty is available ## [5.0.1] - 2020-02-19 ### Changed * `Runtime::getNameWithVersionAndCodeCoverageDriver()` now prioritizes PCOV over Xdebug when both extensions are loaded (just like php-code-coverage does) ## [5.0.0] - 2020-02-07 ### Removed * This component is no longer supported on PHP 7.1 and PHP 7.2 ## [4.2.3] - 2019-11-20 ### Changed * [#50](https://github.com/sebastianbergmann/environment/pull/50): Windows improvements to console capabilities ### Fixed * [#49](https://github.com/sebastianbergmann/environment/issues/49): Detection how OpCache handles docblocks does not work correctly when PHPDBG is used ## [4.2.2] - 2019-05-05 ### Fixed * [#44](https://github.com/sebastianbergmann/environment/pull/44): `TypeError` in `Console::getNumberOfColumnsInteractive()` ## [4.2.1] - 2019-04-25 ### Fixed * Fixed an issue in `Runtime::getCurrentSettings()` ## [4.2.0] - 2019-04-25 ### Added * [#36](https://github.com/sebastianbergmann/environment/pull/36): `Runtime::getCurrentSettings()` ## [4.1.0] - 2019-02-01 ### Added * Implemented `Runtime::getNameWithVersionAndCodeCoverageDriver()` method * [#34](https://github.com/sebastianbergmann/environment/pull/34): Support for PCOV extension ## [4.0.2] - 2019-01-28 ### Fixed * [#33](https://github.com/sebastianbergmann/environment/issues/33): `Runtime::discardsComments()` returns true too eagerly ### Removed * Removed support for Zend Optimizer+ in `Runtime::discardsComments()` ## [4.0.1] - 2018-11-25 ### Fixed * [#31](https://github.com/sebastianbergmann/environment/issues/31): Regressions in `Console` class ## [4.0.0] - 2018-10-23 [YANKED] ### Fixed * [#25](https://github.com/sebastianbergmann/environment/pull/25): `Console::hasColorSupport()` does not work on Windows ### Removed * This component is no longer supported on PHP 7.0 ## [3.1.0] - 2017-07-01 ### Added * [#21](https://github.com/sebastianbergmann/environment/issues/21): Equivalent of `PHP_OS_FAMILY` (for PHP < 7.2) ## [3.0.4] - 2017-06-20 ### Fixed * [#20](https://github.com/sebastianbergmann/environment/pull/20): PHP 7 mode of HHVM not forced ## [3.0.3] - 2017-05-18 ### Fixed * [#18](https://github.com/sebastianbergmann/environment/issues/18): `Uncaught TypeError: preg_match() expects parameter 2 to be string, null given` ## [3.0.2] - 2017-04-21 ### Fixed * [#17](https://github.com/sebastianbergmann/environment/issues/17): `Uncaught TypeError: trim() expects parameter 1 to be string, boolean given` ## [3.0.1] - 2017-04-21 ### Fixed * Fixed inverted logic in `Runtime::discardsComments()` ## [3.0.0] - 2017-04-21 ### Added * Implemented `Runtime::discardsComments()` for querying whether the PHP runtime discards annotations ### Removed * This component is no longer supported on PHP 5.6 [5.1.3]: https://github.com/sebastianbergmann/environment/compare/5.1.2...5.1.3 [5.1.2]: https://github.com/sebastianbergmann/environment/compare/5.1.1...5.1.2 [5.1.1]: https://github.com/sebastianbergmann/environment/compare/5.1.0...5.1.1 [5.1.0]: https://github.com/sebastianbergmann/environment/compare/5.0.2...5.1.0 [5.0.2]: https://github.com/sebastianbergmann/environment/compare/5.0.1...5.0.2 [5.0.1]: https://github.com/sebastianbergmann/environment/compare/5.0.0...5.0.1 [5.0.0]: https://github.com/sebastianbergmann/environment/compare/4.2.3...5.0.0 [4.2.3]: https://github.com/sebastianbergmann/environment/compare/4.2.2...4.2.3 [4.2.2]: https://github.com/sebastianbergmann/environment/compare/4.2.1...4.2.2 [4.2.1]: https://github.com/sebastianbergmann/environment/compare/4.2.0...4.2.1 [4.2.0]: https://github.com/sebastianbergmann/environment/compare/4.1.0...4.2.0 [4.1.0]: https://github.com/sebastianbergmann/environment/compare/4.0.2...4.1.0 [4.0.2]: https://github.com/sebastianbergmann/environment/compare/4.0.1...4.0.2 [4.0.1]: https://github.com/sebastianbergmann/environment/compare/66691f8e2dc4641909166b275a9a4f45c0e89092...4.0.1 [4.0.0]: https://github.com/sebastianbergmann/environment/compare/3.1.0...66691f8e2dc4641909166b275a9a4f45c0e89092 [3.1.0]: https://github.com/sebastianbergmann/environment/compare/3.0...3.1.0 [3.0.4]: https://github.com/sebastianbergmann/environment/compare/3.0.3...3.0.4 [3.0.3]: https://github.com/sebastianbergmann/environment/compare/3.0.2...3.0.3 [3.0.2]: https://github.com/sebastianbergmann/environment/compare/3.0.1...3.0.2 [3.0.1]: https://github.com/sebastianbergmann/environment/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/sebastianbergmann/environment/compare/2.0...3.0.0 phpunit-environment-5.1.3/LICENSE000066400000000000000000000030241373511144400165600ustar00rootroot00000000000000sebastian/environment Copyright (c) 2014-2020, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. phpunit-environment-5.1.3/README.md000066400000000000000000000021371373511144400170360ustar00rootroot00000000000000# sebastian/environment [![Latest Stable Version](https://img.shields.io/packagist/v/sebastian/environment.svg?style=flat-square)](https://packagist.org/packages/sebastian/environment) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg?style=flat-square)](https://php.net/) [![CI Status](https://github.com/sebastianbergmann/environment/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/environment/actions) [![Type Coverage](https://shepherd.dev/github/sebastianbergmann/environment/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/environment) This component provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths. ## Installation You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): ``` composer require sebastian/environment ``` 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 sebastian/environment ``` phpunit-environment-5.1.3/build.xml000066400000000000000000000020551373511144400173770ustar00rootroot00000000000000 phpunit-environment-5.1.3/composer.json000066400000000000000000000016071373511144400203020ustar00rootroot00000000000000{ "name": "sebastian/environment", "description": "Provides functionality to handle HHVM/PHP environments", "keywords": ["environment","hhvm","xdebug"], "homepage": "http://www.github.com/sebastianbergmann/environment", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" } ], "config": { "platform": { "php": "7.3.0" }, "optimize-autoloader": true, "sort-packages": true }, "prefer-stable": true, "require": { "php": ">=7.3" }, "require-dev": { "phpunit/phpunit": "^9.3" }, "suggest": { "ext-posix": "*" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "5.1-dev" } } } phpunit-environment-5.1.3/phpunit.xml000066400000000000000000000014561373511144400177730ustar00rootroot00000000000000 tests src phpunit-environment-5.1.3/src/000077500000000000000000000000001373511144400163435ustar00rootroot00000000000000phpunit-environment-5.1.3/src/Console.php000066400000000000000000000121331373511144400204560ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Environment; use const DIRECTORY_SEPARATOR; use const STDIN; use const STDOUT; use function defined; use function fclose; use function fstat; use function function_exists; use function getenv; use function is_resource; use function is_string; use function posix_isatty; use function preg_match; use function proc_close; use function proc_open; use function sapi_windows_vt100_support; use function shell_exec; use function stream_get_contents; use function stream_isatty; use function trim; final class Console { /** * @var int */ public const STDIN = 0; /** * @var int */ public const STDOUT = 1; /** * @var int */ public const STDERR = 2; /** * Returns true if STDOUT supports colorization. * * This code has been copied and adapted from * Symfony\Component\Console\Output\StreamOutput. */ public function hasColorSupport(): bool { if ('Hyper' === getenv('TERM_PROGRAM')) { return true; } if ($this->isWindows()) { // @codeCoverageIgnoreStart return (defined('STDOUT') && function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT)) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); // @codeCoverageIgnoreEnd } if (!defined('STDOUT')) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd } return $this->isInteractive(STDOUT); } /** * Returns the number of columns of the terminal. * * @codeCoverageIgnore */ public function getNumberOfColumns(): int { if (!$this->isInteractive(defined('STDIN') ? STDIN : self::STDIN)) { return 80; } if ($this->isWindows()) { return $this->getNumberOfColumnsWindows(); } return $this->getNumberOfColumnsInteractive(); } /** * Returns if the file descriptor is an interactive terminal or not. * * Normally, we want to use a resource as a parameter, yet sadly it's not always awailable, * eg when running code in interactive console (`php -a`), STDIN/STDOUT/STDERR constants are not defined. * * @param int|resource $fileDescriptor */ public function isInteractive($fileDescriptor = self::STDOUT): bool { if (is_resource($fileDescriptor)) { // These functions require a descriptor that is a real resource, not a numeric ID of it if (function_exists('stream_isatty') && @stream_isatty($fileDescriptor)) { return true; } // Check if formatted mode is S_IFCHR if (function_exists('fstat') && @stream_isatty($fileDescriptor)) { $stat = @fstat(STDOUT); return $stat ? 0020000 === ($stat['mode'] & 0170000) : false; } return false; } return function_exists('posix_isatty') && @posix_isatty($fileDescriptor); } private function isWindows(): bool { return DIRECTORY_SEPARATOR === '\\'; } /** * @codeCoverageIgnore */ private function getNumberOfColumnsInteractive(): int { if (function_exists('shell_exec') && preg_match('#\d+ (\d+)#', shell_exec('stty size') ?: '', $match) === 1) { if ((int) $match[1] > 0) { return (int) $match[1]; } } if (function_exists('shell_exec') && preg_match('#columns = (\d+);#', shell_exec('stty') ?: '', $match) === 1) { if ((int) $match[1] > 0) { return (int) $match[1]; } } return 80; } /** * @codeCoverageIgnore */ private function getNumberOfColumnsWindows(): int { $ansicon = getenv('ANSICON'); $columns = 80; if (is_string($ansicon) && preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim($ansicon), $matches)) { $columns = (int) $matches[1]; } elseif (function_exists('proc_open')) { $process = proc_open( 'mode CON', [ 1 => ['pipe', 'w'], 2 => ['pipe', 'w'], ], $pipes, null, null, ['suppress_errors' => true] ); if (is_resource($process)) { $info = stream_get_contents($pipes[1]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) { $columns = (int) $matches[2]; } } } return $columns - 1; } } phpunit-environment-5.1.3/src/OperatingSystem.php000066400000000000000000000023421373511144400222120ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Environment; use const DIRECTORY_SEPARATOR; use const PHP_OS; use const PHP_OS_FAMILY; use function defined; final class OperatingSystem { /** * Returns PHP_OS_FAMILY (if defined (which it is on PHP >= 7.2)). * Returns a string (compatible with PHP_OS_FAMILY) derived from PHP_OS otherwise. */ public function getFamily(): string { if (defined('PHP_OS_FAMILY')) { return PHP_OS_FAMILY; } if (DIRECTORY_SEPARATOR === '\\') { return 'Windows'; } switch (PHP_OS) { case 'Darwin': return 'Darwin'; case 'DragonFly': case 'FreeBSD': case 'NetBSD': case 'OpenBSD': return 'BSD'; case 'Linux': return 'Linux'; case 'SunOS': return 'Solaris'; default: return 'Unknown'; } } } phpunit-environment-5.1.3/src/Runtime.php000066400000000000000000000177571373511144400205200ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Environment; use const PHP_BINARY; use const PHP_BINDIR; use const PHP_MAJOR_VERSION; use const PHP_SAPI; use const PHP_VERSION; use function array_map; use function array_merge; use function defined; use function escapeshellarg; use function explode; use function extension_loaded; use function getenv; use function ini_get; use function is_readable; use function parse_ini_file; use function php_ini_loaded_file; use function php_ini_scanned_files; use function phpversion; use function sprintf; use function strpos; /** * Utility class for HHVM/PHP environment handling. */ final class Runtime { /** * @var string */ private static $binary; /** * Returns true when Xdebug or PCOV is available or * the runtime used is PHPDBG. */ public function canCollectCodeCoverage(): bool { return $this->hasXdebug() || $this->hasPCOV() || $this->hasPHPDBGCodeCoverage(); } /** * Returns true when Zend OPcache is loaded, enabled, * and is configured to discard comments. */ public function discardsComments(): bool { if (!$this->isOpcacheActive()) { return false; } if (ini_get('opcache.save_comments') !== '0') { return false; } return true; } /** * Returns true when Zend OPcache is loaded, enabled, * and is configured to perform just-in-time compilation. */ public function performsJustInTimeCompilation(): bool { if (PHP_MAJOR_VERSION < 8) { return false; } if (!$this->isOpcacheActive()) { return false; } if (strpos(ini_get('opcache.jit'), '0') === 0) { return false; } return true; } /** * Returns the path to the binary of the current runtime. * Appends ' --php' to the path when the runtime is HHVM. */ public function getBinary(): string { // HHVM if (self::$binary === null && $this->isHHVM()) { // @codeCoverageIgnoreStart if ((self::$binary = getenv('PHP_BINARY')) === false) { self::$binary = PHP_BINARY; } self::$binary = escapeshellarg(self::$binary) . ' --php' . ' -d hhvm.php7.all=1'; // @codeCoverageIgnoreEnd } if (self::$binary === null && PHP_BINARY !== '') { self::$binary = escapeshellarg(PHP_BINARY); } if (self::$binary === null) { // @codeCoverageIgnoreStart $possibleBinaryLocations = [ PHP_BINDIR . '/php', PHP_BINDIR . '/php-cli.exe', PHP_BINDIR . '/php.exe', ]; foreach ($possibleBinaryLocations as $binary) { if (is_readable($binary)) { self::$binary = escapeshellarg($binary); break; } } // @codeCoverageIgnoreEnd } if (self::$binary === null) { // @codeCoverageIgnoreStart self::$binary = 'php'; // @codeCoverageIgnoreEnd } return self::$binary; } public function getNameWithVersion(): string { return $this->getName() . ' ' . $this->getVersion(); } public function getNameWithVersionAndCodeCoverageDriver(): string { if (!$this->canCollectCodeCoverage() || $this->hasPHPDBGCodeCoverage()) { return $this->getNameWithVersion(); } if ($this->hasPCOV()) { return sprintf( '%s with PCOV %s', $this->getNameWithVersion(), phpversion('pcov') ); } if ($this->hasXdebug()) { return sprintf( '%s with Xdebug %s', $this->getNameWithVersion(), phpversion('xdebug') ); } } public function getName(): string { if ($this->isHHVM()) { // @codeCoverageIgnoreStart return 'HHVM'; // @codeCoverageIgnoreEnd } if ($this->isPHPDBG()) { // @codeCoverageIgnoreStart return 'PHPDBG'; // @codeCoverageIgnoreEnd } return 'PHP'; } public function getVendorUrl(): string { if ($this->isHHVM()) { // @codeCoverageIgnoreStart return 'http://hhvm.com/'; // @codeCoverageIgnoreEnd } return 'https://secure.php.net/'; } public function getVersion(): string { if ($this->isHHVM()) { // @codeCoverageIgnoreStart return HHVM_VERSION; // @codeCoverageIgnoreEnd } return PHP_VERSION; } /** * Returns true when the runtime used is PHP and Xdebug is loaded. */ public function hasXdebug(): bool { return ($this->isPHP() || $this->isHHVM()) && extension_loaded('xdebug'); } /** * Returns true when the runtime used is HHVM. */ public function isHHVM(): bool { return defined('HHVM_VERSION'); } /** * Returns true when the runtime used is PHP without the PHPDBG SAPI. */ public function isPHP(): bool { return !$this->isHHVM() && !$this->isPHPDBG(); } /** * Returns true when the runtime used is PHP with the PHPDBG SAPI. */ public function isPHPDBG(): bool { return PHP_SAPI === 'phpdbg' && !$this->isHHVM(); } /** * Returns true when the runtime used is PHP with the PHPDBG SAPI * and the phpdbg_*_oplog() functions are available (PHP >= 7.0). */ public function hasPHPDBGCodeCoverage(): bool { return $this->isPHPDBG(); } /** * Returns true when the runtime used is PHP with PCOV loaded and enabled. */ public function hasPCOV(): bool { return $this->isPHP() && extension_loaded('pcov') && ini_get('pcov.enabled'); } /** * Parses the loaded php.ini file (if any) as well as all * additional php.ini files from the additional ini dir for * a list of all configuration settings loaded from files * at startup. Then checks for each php.ini setting passed * via the `$values` parameter whether this setting has * been changed at runtime. Returns an array of strings * where each string has the format `key=value` denoting * the name of a changed php.ini setting with its new value. * * @return string[] */ public function getCurrentSettings(array $values): array { $diff = []; $files = []; if ($file = php_ini_loaded_file()) { $files[] = $file; } if ($scanned = php_ini_scanned_files()) { $files = array_merge( $files, array_map( 'trim', explode(",\n", $scanned) ) ); } foreach ($files as $ini) { $config = parse_ini_file($ini, true); foreach ($values as $value) { $set = ini_get($value); if (isset($config[$value]) && $set != $config[$value]) { $diff[] = sprintf('%s=%s', $value, $set); } } } return $diff; } private function isOpcacheActive(): bool { if (!extension_loaded('Zend OPcache')) { return false; } if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') && ini_get('opcache.enable_cli') === '1') { return true; } if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' && ini_get('opcache.enable') === '1') { return true; } return false; } } phpunit-environment-5.1.3/tests/000077500000000000000000000000001373511144400167165ustar00rootroot00000000000000phpunit-environment-5.1.3/tests/ConsoleTest.php000066400000000000000000000034261373511144400216760ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Environment; use const STDOUT; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Environment\Console */ final class ConsoleTest extends TestCase { /** * @var \SebastianBergmann\Environment\Console */ private $console; protected function setUp(): void { $this->console = new Console; } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testCanDetectIfStdoutIsInteractiveByDefault(): void { $this->assertIsBool($this->console->isInteractive()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testCanDetectIfFileDescriptorIsInteractive(): void { $this->assertIsBool($this->console->isInteractive(STDOUT)); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testCanDetectColorSupport(): void { $this->assertIsBool($this->console->hasColorSupport()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testCanDetectNumberOfColumns(): void { $this->assertIsInt($this->console->getNumberOfColumns()); } } phpunit-environment-5.1.3/tests/OperatingSystemTest.php000066400000000000000000000026321373511144400234270ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Environment; use const PHP_OS_FAMILY; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Environment\OperatingSystem */ final class OperatingSystemTest extends TestCase { /** * @var \SebastianBergmann\Environment\OperatingSystem */ private $os; protected function setUp(): void { $this->os = new OperatingSystem; } /** * @requires OS Linux */ public function testFamilyCanBeRetrieved(): void { $this->assertEquals('Linux', $this->os->getFamily()); } /** * @requires OS Darwin */ public function testFamilyReturnsDarwinWhenRunningOnDarwin(): void { $this->assertEquals('Darwin', $this->os->getFamily()); } /** * @requires OS Windows */ public function testGetFamilyReturnsWindowsWhenRunningOnWindows(): void { $this->assertSame('Windows', $this->os->getFamily()); } /** * @requires PHP 7.2.0 */ public function testGetFamilyReturnsPhpOsFamilyWhenRunningOnPhp72AndGreater(): void { $this->assertSame(PHP_OS_FAMILY, $this->os->getFamily()); } } phpunit-environment-5.1.3/tests/RuntimeTest.php000066400000000000000000000076521373511144400217240ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Environment; use const PHP_SAPI; use const PHP_VERSION; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Environment\Runtime */ final class RuntimeTest extends TestCase { /** * @var \SebastianBergmann\Environment\Runtime */ private $env; protected function setUp(): void { $this->env = new Runtime; } /** * @requires extension xdebug */ public function testCanCollectCodeCoverageWhenXdebugExtensionIsEnabled(): void { $this->assertTrue($this->env->canCollectCodeCoverage()); } /** * @requires extension pcov */ public function testCanCollectCodeCoverageWhenPcovExtensionIsEnabled(): void { $this->assertTrue($this->env->canCollectCodeCoverage()); } public function testCanCollectCodeCoverageWhenRunningOnPhpdbg(): void { $this->markTestSkippedWhenNotRunningOnPhpdbg(); $this->assertTrue($this->env->canCollectCodeCoverage()); } public function testBinaryCanBeRetrieved(): void { $this->assertNotEmpty($this->env->getBinary()); } /** * @requires PHP */ public function testIsHhvmReturnsFalseWhenRunningOnPhp(): void { $this->assertFalse($this->env->isHHVM()); } /** * @requires PHP */ public function testIsPhpReturnsTrueWhenRunningOnPhp(): void { $this->markTestSkippedWhenRunningOnPhpdbg(); $this->assertTrue($this->env->isPHP()); } /** * @requires extension pcov */ public function testPCOVCanBeDetected(): void { $this->assertTrue($this->env->hasPCOV()); } public function testPhpdbgCanBeDetected(): void { $this->markTestSkippedWhenNotRunningOnPhpdbg(); $this->assertTrue($this->env->hasPHPDBGCodeCoverage()); } /** * @requires extension xdebug */ public function testXdebugCanBeDetected(): void { $this->markTestSkippedWhenRunningOnPhpdbg(); $this->assertTrue($this->env->hasXdebug()); } public function testNameAndVersionCanBeRetrieved(): void { $this->assertNotEmpty($this->env->getNameWithVersion()); } public function testGetNameReturnsPhpdbgWhenRunningOnPhpdbg(): void { $this->markTestSkippedWhenNotRunningOnPhpdbg(); $this->assertSame('PHPDBG', $this->env->getName()); } /** * @requires PHP */ public function testGetNameReturnsPhpdbgWhenRunningOnPhp(): void { $this->markTestSkippedWhenRunningOnPhpdbg(); $this->assertSame('PHP', $this->env->getName()); } public function testNameAndCodeCoverageDriverCanBeRetrieved(): void { $this->assertNotEmpty($this->env->getNameWithVersionAndCodeCoverageDriver()); } /** * @requires PHP */ public function testGetVersionReturnsPhpVersionWhenRunningPhp(): void { $this->assertSame(PHP_VERSION, $this->env->getVersion()); } /** * @requires PHP */ public function testGetVendorUrlReturnsPhpDotNetWhenRunningPhp(): void { $this->assertSame('https://secure.php.net/', $this->env->getVendorUrl()); } private function markTestSkippedWhenNotRunningOnPhpdbg(): void { if ($this->isRunningOnPhpdbg()) { return; } $this->markTestSkipped('PHPDBG is required.'); } private function markTestSkippedWhenRunningOnPhpdbg(): void { if (!$this->isRunningOnPhpdbg()) { return; } $this->markTestSkipped('Cannot run on PHPDBG'); } private function isRunningOnPhpdbg(): bool { return PHP_SAPI === 'phpdbg'; } }