upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -1 +0,0 @@
github: sebastianbergmann

View File

@@ -1,6 +0,0 @@
/.idea
/vendor
/composer.lock
/composer.phar
/.php_cs.cache
/.phpunit.result.cache

View File

@@ -1,199 +0,0 @@
<?php
$header = <<<'EOF'
This file is part of sebastian/environment.
(c) Sebastian Bergmann <sebastian@phpunit.de>
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(
[
'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,
'combine_nested_dirname' => 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,
'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' => true,
'native_function_casing' => true,
'native_function_invocation' => true,
'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' => 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' => 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_trim_consecutive_blank_line_separation' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => true,
'phpdoc_var_without_name' => true,
'pow_to_exponentiation' => true,
'protected_to_private' => true,
'random_api_migration' => 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' => 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,
'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,
]
)
->setFinder(
PhpCsFixer\Finder::create()
->files()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
);

View File

@@ -1,28 +0,0 @@
language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
env:
matrix:
- DRIVER="phpdbg"
- DRIVER="xdebug"
before_install:
- composer clear-cache
install:
- travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest
script:
- if [[ "$DRIVER" = 'phpdbg' ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ "$DRIVER" != 'phpdbg' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml; fi
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
email: false

View File

@@ -2,27 +2,69 @@
All notable changes in `sebastianbergmann/environment` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [4.2.4] - 2020-11-30
## [5.1.4] - 2022-04-03
### Fixed
* [#63](https://github.com/sebastianbergmann/environment/pull/63): `Runtime::getCurrentSettings()` does not correctly process INI settings
## [5.1.3] - 2020-09-28
### Changed
* Changed PHP version constraint in `composer.json` from `^7.1` to `>=7.1`
* 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
* Implemented [#50](https://github.com/sebastianbergmann/environment/pull/50): Windows improvements to console capabilities
* [#50](https://github.com/sebastianbergmann/environment/pull/50): Windows improvements to console capabilities
### Fixed
* Fixed [#49](https://github.com/sebastianbergmann/environment/issues/49): Detection how OpCache handles docblocks does not work correctly when PHPDBG is used
* [#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
* Fixed [#44](https://github.com/sebastianbergmann/environment/pull/44): `TypeError` in `Console::getNumberOfColumnsInteractive()`
* [#44](https://github.com/sebastianbergmann/environment/pull/44): `TypeError` in `Console::getNumberOfColumnsInteractive()`
## [4.2.1] - 2019-04-25
@@ -34,20 +76,20 @@ All notable changes in `sebastianbergmann/environment` are documented in this fi
### Added
* Implemented [#36](https://github.com/sebastianbergmann/environment/pull/36): `Runtime::getCurrentSettings()`
* [#36](https://github.com/sebastianbergmann/environment/pull/36): `Runtime::getCurrentSettings()`
## [4.1.0] - 2019-02-01
### Added
* Implemented `Runtime::getNameWithVersionAndCodeCoverageDriver()` method
* Implemented [#34](https://github.com/sebastianbergmann/environment/pull/34): Support for PCOV extension
* [#34](https://github.com/sebastianbergmann/environment/pull/34): Support for PCOV extension
## [4.0.2] - 2019-01-28
### Fixed
* Fixed [#33](https://github.com/sebastianbergmann/environment/issues/33): `Runtime::discardsComments()` returns true too eagerly
* [#33](https://github.com/sebastianbergmann/environment/issues/33): `Runtime::discardsComments()` returns true too eagerly
### Removed
@@ -57,13 +99,13 @@ All notable changes in `sebastianbergmann/environment` are documented in this fi
### Fixed
* Fixed [#31](https://github.com/sebastianbergmann/environment/issues/31): Regressions in `Console` class
* [#31](https://github.com/sebastianbergmann/environment/issues/31): Regressions in `Console` class
## [4.0.0] - 2018-10-23 [YANKED]
### Fixed
* Fixed [#25](https://github.com/sebastianbergmann/environment/pull/25): `Console::hasColorSupport()` does not work on Windows
* [#25](https://github.com/sebastianbergmann/environment/pull/25): `Console::hasColorSupport()` does not work on Windows
### Removed
@@ -73,25 +115,25 @@ All notable changes in `sebastianbergmann/environment` are documented in this fi
### Added
* Implemented [#21](https://github.com/sebastianbergmann/environment/issues/21): Equivalent of `PHP_OS_FAMILY` (for PHP < 7.2)
* [#21](https://github.com/sebastianbergmann/environment/issues/21): Equivalent of `PHP_OS_FAMILY` (for PHP < 7.2)
## [3.0.4] - 2017-06-20
### Fixed
* Fixed [#20](https://github.com/sebastianbergmann/environment/pull/20): PHP 7 mode of HHVM not forced
* [#20](https://github.com/sebastianbergmann/environment/pull/20): PHP 7 mode of HHVM not forced
## [3.0.3] - 2017-05-18
### Fixed
* Fixed [#18](https://github.com/sebastianbergmann/environment/issues/18): `Uncaught TypeError: preg_match() expects parameter 2 to be string, null given`
* [#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
* Fixed [#17](https://github.com/sebastianbergmann/environment/issues/17): `Uncaught TypeError: trim() expects parameter 1 to be string, boolean given`
* [#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
@@ -109,19 +151,26 @@ All notable changes in `sebastianbergmann/environment` are documented in this fi
* This component is no longer supported on PHP 5.6
[4.2.4]: https://github.com/sebastianbergmann/phpunit/compare/4.2.3...4.2.4
[4.2.3]: https://github.com/sebastianbergmann/phpunit/compare/4.2.2...4.2.3
[4.2.2]: https://github.com/sebastianbergmann/phpunit/compare/4.2.1...4.2.2
[4.2.1]: https://github.com/sebastianbergmann/phpunit/compare/4.2.0...4.2.1
[4.2.0]: https://github.com/sebastianbergmann/phpunit/compare/4.1.0...4.2.0
[4.1.0]: https://github.com/sebastianbergmann/phpunit/compare/4.0.2...4.1.0
[4.0.2]: https://github.com/sebastianbergmann/phpunit/compare/4.0.1...4.0.2
[4.0.1]: https://github.com/sebastianbergmann/phpunit/compare/66691f8e2dc4641909166b275a9a4f45c0e89092...4.0.1
[4.0.0]: https://github.com/sebastianbergmann/phpunit/compare/3.1.0...66691f8e2dc4641909166b275a9a4f45c0e89092
[3.1.0]: https://github.com/sebastianbergmann/phpunit/compare/3.0...3.1.0
[3.0.4]: https://github.com/sebastianbergmann/phpunit/compare/3.0.3...3.0.4
[3.0.3]: https://github.com/sebastianbergmann/phpunit/compare/3.0.2...3.0.3
[3.0.2]: https://github.com/sebastianbergmann/phpunit/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/sebastianbergmann/phpunit/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/phpunit/compare/2.0...3.0.0
[5.1.4]: https://github.com/sebastianbergmann/environment/compare/5.1.3...5.1.4
[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

View File

@@ -1,6 +1,6 @@
sebastian/environment
Copyright (c) 2014-2019, Sebastian Bergmann <sebastian@phpunit.de>.
Copyright (c) 2014-2022, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -1,17 +1,21 @@
# sebastian/environment
This component provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths.
[![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/)
[![Build Status](https://travis-ci.org/sebastianbergmann/environment.svg?branch=master)](https://travis-ci.org/sebastianbergmann/environment)
[![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
```
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
```
composer require --dev sebastian/environment
```

View File

@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="environment" default="setup">
<target name="setup" depends="clean,composer"/>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.lock"/>
</target>
<target name="composer" depends="clean" description="Install dependencies with Composer">
<exec executable="composer" taskname="composer">
<arg value="update"/>
<arg value="--no-interaction"/>
<arg value="--no-progress"/>
<arg value="--no-ansi"/>
<arg value="--no-suggest"/>
</exec>
</target>
</project>

View File

@@ -11,15 +11,18 @@
}
],
"config": {
"platform": {
"php": "7.3.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"prefer-stable": true,
"require": {
"php": ">=7.1"
"php": ">=7.3"
},
"require-dev": {
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^9.3"
},
"suggest": {
"ext-posix": "*"
@@ -31,7 +34,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
"dev-master": "5.1-dev"
}
}
}

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -9,12 +9,32 @@
*/
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;
public const STDIN = 0;
/**
* @var int
@@ -34,26 +54,26 @@ final class Console
*/
public function hasColorSupport(): bool
{
if ('Hyper' === \getenv('TERM_PROGRAM')) {
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');
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')) {
if (!defined('STDOUT')) {
// @codeCoverageIgnoreStart
return false;
// @codeCoverageIgnoreEnd
}
return $this->isInteractive(\STDOUT);
return $this->isInteractive(STDOUT);
}
/**
@@ -63,7 +83,7 @@ final class Console
*/
public function getNumberOfColumns(): int
{
if (!$this->isInteractive(\defined('STDIN') ? \STDIN : self::STDIN)) {
if (!$this->isInteractive(defined('STDIN') ? STDIN : self::STDIN)) {
return 80;
}
@@ -84,23 +104,28 @@ final class Console
*/
public function isInteractive($fileDescriptor = self::STDOUT): bool
{
if (\is_resource($fileDescriptor)) {
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)) {
if (function_exists('stream_isatty') && @stream_isatty($fileDescriptor)) {
return true;
}
$stat = @\fstat(\STDOUT);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
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);
return function_exists('posix_isatty') && @posix_isatty($fileDescriptor);
}
private function isWindows(): bool
{
return \DIRECTORY_SEPARATOR === '\\';
return DIRECTORY_SEPARATOR === '\\';
}
/**
@@ -108,13 +133,13 @@ final class Console
*/
private function getNumberOfColumnsInteractive(): int
{
if (\function_exists('shell_exec') && \preg_match('#\d+ (\d+)#', \shell_exec('stty size') ?: '', $match) === 1) {
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 (function_exists('shell_exec') && preg_match('#columns = (\d+);#', shell_exec('stty') ?: '', $match) === 1) {
if ((int) $match[1] > 0) {
return (int) $match[1];
}
@@ -128,13 +153,13 @@ final class Console
*/
private function getNumberOfColumnsWindows(): int
{
$ansicon = \getenv('ANSICON');
$ansicon = getenv('ANSICON');
$columns = 80;
if (\is_string($ansicon) && \preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', \trim($ansicon), $matches)) {
$columns = $matches[1];
} elseif (\function_exists('proc_open')) {
$process = \proc_open(
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'],
@@ -146,15 +171,15 @@ final class Console
['suppress_errors' => true]
);
if (\is_resource($process)) {
$info = \stream_get_contents($pipes[1]);
if (is_resource($process)) {
$info = stream_get_contents($pipes[1]);
\fclose($pipes[1]);
\fclose($pipes[2]);
\proc_close($process);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
if (\preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
$columns = $matches[2];
if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
$columns = (int) $matches[2];
}
}
}

View File

@@ -9,6 +9,11 @@
*/
namespace SebastianBergmann\Environment;
use const DIRECTORY_SEPARATOR;
use const PHP_OS;
use const PHP_OS_FAMILY;
use function defined;
final class OperatingSystem
{
/**
@@ -17,15 +22,15 @@ final class OperatingSystem
*/
public function getFamily(): string
{
if (\defined('PHP_OS_FAMILY')) {
return \PHP_OS_FAMILY;
if (defined('PHP_OS_FAMILY')) {
return PHP_OS_FAMILY;
}
if (\DIRECTORY_SEPARATOR === '\\') {
if (DIRECTORY_SEPARATOR === '\\') {
return 'Windows';
}
switch (\PHP_OS) {
switch (PHP_OS) {
case 'Darwin':
return 'Darwin';

View File

@@ -9,6 +9,27 @@
*/
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.
*/
@@ -29,27 +50,41 @@ final class Runtime
}
/**
* Returns true when Zend OPcache is loaded, enabled, and is configured to discard comments.
* Returns true when Zend OPcache is loaded, enabled,
* and is configured to discard comments.
*/
public function discardsComments(): bool
{
if (!\extension_loaded('Zend OPcache')) {
if (!$this->isOpcacheActive()) {
return false;
}
if (\ini_get('opcache.save_comments') !== '0') {
if (ini_get('opcache.save_comments') !== '0') {
return false;
}
if ((\PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg') && \ini_get('opcache.enable_cli') === '1') {
return true;
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 (\PHP_SAPI !== 'cli' && \PHP_SAPI !== 'phpdbg' && \ini_get('opcache.enable') === '1') {
return true;
if (!$this->isOpcacheActive()) {
return false;
}
return false;
if (strpos(ini_get('opcache.jit'), '0') === 0) {
return false;
}
return true;
}
/**
@@ -61,30 +96,30 @@ final class Runtime
// HHVM
if (self::$binary === null && $this->isHHVM()) {
// @codeCoverageIgnoreStart
if ((self::$binary = \getenv('PHP_BINARY')) === false) {
self::$binary = \PHP_BINARY;
if ((self::$binary = getenv('PHP_BINARY')) === false) {
self::$binary = PHP_BINARY;
}
self::$binary = \escapeshellarg(self::$binary) . ' --php' .
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 && 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',
PHP_BINDIR . '/php',
PHP_BINDIR . '/php-cli.exe',
PHP_BINDIR . '/php.exe',
];
foreach ($possibleBinaryLocations as $binary) {
if (\is_readable($binary)) {
self::$binary = \escapeshellarg($binary);
if (is_readable($binary)) {
self::$binary = escapeshellarg($binary);
break;
}
@@ -112,19 +147,19 @@ final class Runtime
return $this->getNameWithVersion();
}
if ($this->hasXdebug()) {
return \sprintf(
'%s with Xdebug %s',
if ($this->hasPCOV()) {
return sprintf(
'%s with PCOV %s',
$this->getNameWithVersion(),
\phpversion('xdebug')
phpversion('pcov')
);
}
if ($this->hasPCOV()) {
return \sprintf(
'%s with PCOV %s',
if ($this->hasXdebug()) {
return sprintf(
'%s with Xdebug %s',
$this->getNameWithVersion(),
\phpversion('pcov')
phpversion('xdebug')
);
}
}
@@ -165,7 +200,7 @@ final class Runtime
// @codeCoverageIgnoreEnd
}
return \PHP_VERSION;
return PHP_VERSION;
}
/**
@@ -173,7 +208,7 @@ final class Runtime
*/
public function hasXdebug(): bool
{
return ($this->isPHP() || $this->isHHVM()) && \extension_loaded('xdebug');
return ($this->isPHP() || $this->isHHVM()) && extension_loaded('xdebug');
}
/**
@@ -181,7 +216,7 @@ final class Runtime
*/
public function isHHVM(): bool
{
return \defined('HHVM_VERSION');
return defined('HHVM_VERSION');
}
/**
@@ -197,7 +232,7 @@ final class Runtime
*/
public function isPHPDBG(): bool
{
return \PHP_SAPI === 'phpdbg' && !$this->isHHVM();
return PHP_SAPI === 'phpdbg' && !$this->isHHVM();
}
/**
@@ -210,11 +245,11 @@ final class Runtime
}
/**
* Returns true when the runtime used is PHP with PCOV loaded and enabled
* 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');
return $this->isPHP() && extension_loaded('pcov') && ini_get('pcov.enabled');
}
/**
@@ -234,32 +269,53 @@ final class Runtime
$diff = [];
$files = [];
if ($file = \php_ini_loaded_file()) {
if ($file = php_ini_loaded_file()) {
$files[] = $file;
}
if ($scanned = \php_ini_scanned_files()) {
$files = \array_merge(
if ($scanned = php_ini_scanned_files()) {
$files = array_merge(
$files,
\array_map(
array_map(
'trim',
\explode(",\n", $scanned)
explode(",\n", $scanned)
)
);
}
foreach ($files as $ini) {
$config = \parse_ini_file($ini, true);
$config = parse_ini_file($ini, true);
foreach ($values as $value) {
$set = \ini_get($value);
$set = ini_get($value);
if (isset($config[$value]) && $set != $config[$value]) {
$diff[] = \sprintf('%s=%s', $value, $set);
if (empty($set)) {
continue;
}
if ((!isset($config[$value]) || ($set !== $config[$value]))) {
$diff[$value] = 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;
}
}

View File

@@ -1,64 +0,0 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/environment.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Environment;
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());
}
}

View File

@@ -1,60 +0,0 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/environment.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Environment;
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());
}
}

View File

@@ -1,165 +0,0 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/environment.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Environment;
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';
}
}