pax_global_header00006660000000000000000000000064131256611640014517gustar00rootroot0000000000000052 comment=cd0871b3975fb7fc44d11314fd1ee20925fce4f5 environment-3.1.0/000077500000000000000000000000001312566116400140645ustar00rootroot00000000000000environment-3.1.0/.gitignore000066400000000000000000000000741312566116400160550ustar00rootroot00000000000000/.idea /vendor /composer.lock /composer.phar /.php_cs.cache environment-3.1.0/.php_cs000066400000000000000000000056471312566116400153550ustar00rootroot00000000000000 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_return' => true, 'braces' => true, 'cast_spaces' => true, 'concat_space' => ['spacing' => 'one'], 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, 'function_declaration' => true, #'header_comment' => ['header' => $header, 'separate' => 'none'], 'indentation_type' => true, 'line_ending' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'method_argument_space' => 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_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_consecutive_blank_lines' => true, 'no_leading_namespace_whitespace' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_after_function_name' => true, 'no_spaces_inside_parenthesis' => true, 'no_trailing_comma_in_list_call' => true, 'no_trailing_whitespace' => true, 'no_unused_imports' => true, 'no_whitespace_in_blank_line' => true, 'phpdoc_align' => true, 'phpdoc_indent' => true, 'phpdoc_no_access' => true, 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_types' => true, 'phpdoc_var_without_name' => true, 'self_accessor' => true, 'simplified_null_return' => true, 'single_blank_line_at_eof' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, 'single_quote' => true, 'ternary_operator_spaces' => true, 'trim_array_spaces' => true, 'visibility_required' => true, ] ) ->setFinder( PhpCsFixer\Finder::create() ->files() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests') ->name('*.php') ); environment-3.1.0/.travis.yml000066400000000000000000000011061312566116400161730ustar00rootroot00000000000000language: php sudo: false before_install: - composer self-update install: - travis_retry composer install --no-interaction --prefer-source php: - 7.0 - 7.0snapshot - 7.1 - 7.1snapshot - master sudo: false before_install: - composer self-update - composer clear-cache install: - travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable script: - ./vendor/bin/phpunit --coverage-clover=coverage.xml after_success: - bash <(curl -s https://codecov.io/bash) notifications: email: false environment-3.1.0/ChangeLog.md000066400000000000000000000031411312566116400162340ustar00rootroot00000000000000# Changes in sebastianbergmann/environment All notable changes in `sebastianbergmann/environment` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## [3.1.0] - 2017-07-01 ### Added * Implemented [#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 ## [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` ## [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` ## [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 [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 environment-3.1.0/LICENSE000066400000000000000000000030241312566116400150700ustar00rootroot00000000000000sebastian/environment Copyright (c) 2014-2017, 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. environment-3.1.0/README.md000066400000000000000000000016751312566116400153540ustar00rootroot00000000000000# 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.0-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) ## 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 environment-3.1.0/build.xml000066400000000000000000000012561312566116400157110ustar00rootroot00000000000000 environment-3.1.0/composer.json000066400000000000000000000013011312566116400166010ustar00rootroot00000000000000{ "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" } ], "prefer-stable": true, "require": { "php": "^7.0" }, "require-dev": { "phpunit/phpunit": "^6.1" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "3.1.x-dev" } } } environment-3.1.0/phpunit.xml000066400000000000000000000012051312566116400162730ustar00rootroot00000000000000 tests src environment-3.1.0/src/000077500000000000000000000000001312566116400146535ustar00rootroot00000000000000environment-3.1.0/src/Console.php000066400000000000000000000071201312566116400167660ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace SebastianBergmann\Environment; final class Console { /** * @var int */ const STDIN = 0; /** * @var int */ const STDOUT = 1; /** * @var int */ const STDERR = 2; /** * Returns true if STDOUT supports colorization. * * This code has been copied and adapted from * Symfony\Component\Console\Output\OutputStream. */ public function hasColorSupport(): bool { if ($this->isWindows()) { // @codeCoverageIgnoreStart return 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->isWindows()) { return $this->getNumberOfColumnsWindows(); } if (!$this->isInteractive(self::STDIN)) { return 80; } return $this->getNumberOfColumnsInteractive(); } /** * Returns if the file descriptor is an interactive terminal or not. * * @param int|resource $fileDescriptor */ public function isInteractive($fileDescriptor = self::STDOUT): bool { 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 = $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 = $matches[2]; } } } return $columns - 1; } } environment-3.1.0/src/OperatingSystem.php000066400000000000000000000022041312566116400205170ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace SebastianBergmann\Environment; 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'; } } } environment-3.1.0/src/Runtime.php000066400000000000000000000112241312566116400170070ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace SebastianBergmann\Environment; /** * Utility class for HHVM/PHP environment handling. */ final class Runtime { /** * @var string */ private static $binary; /** * Returns true when Xdebug is supported or * the runtime used is PHPDBG. */ public function canCollectCodeCoverage(): bool { return $this->hasXdebug() || $this->hasPHPDBGCodeCoverage(); } /** * Returns true when OPcache is loaded and opcache.save_comments=0 is set. * * Code taken from Doctrine\Common\Annotations\AnnotationReader::__construct(). */ public function discardsComments(): bool { if (\extension_loaded('Zend Optimizer+') && (\ini_get('zend_optimizerplus.save_comments') === '0' || \ini_get('opcache.save_comments') === '0')) { return true; } if (\extension_loaded('Zend OPcache') && \ini_get('opcache.save_comments') == 0) { return true; } return false; } /** * 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 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). * * @codeCoverageIgnore */ public function hasPHPDBGCodeCoverage(): bool { return $this->isPHPDBG(); } } environment-3.1.0/tests/000077500000000000000000000000001312566116400152265ustar00rootroot00000000000000environment-3.1.0/tests/ConsoleTest.php000066400000000000000000000035371312566116400202110ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); 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->assertInternalType('boolean', $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->assertInternalType('boolean', $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->assertInternalType('boolean', $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->assertInternalType('integer', $this->console->getNumberOfColumns()); } } environment-3.1.0/tests/OperatingSystemTest.php000066400000000000000000000014701312566116400217360ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); 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()); } } environment-3.1.0/tests/RuntimeTest.php000066400000000000000000000063261312566116400202310ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); 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; } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testAbilityToCollectCodeCoverageCanBeAssessed()/*: void*/ { $this->assertInternalType('boolean', $this->env->canCollectCodeCoverage()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testBinaryCanBeRetrieved()/*: void*/ { $this->assertInternalType('string', $this->env->getBinary()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testCanBeDetected()/*: void*/ { $this->assertInternalType('boolean', $this->env->isHHVM()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testCanBeDetected2()/*: void*/ { $this->assertInternalType('boolean', $this->env->isPHP()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testXdebugCanBeDetected()/*: void*/ { $this->assertInternalType('boolean', $this->env->hasXdebug()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testNameAndVersionCanBeRetrieved()/*: void*/ { $this->assertInternalType('string', $this->env->getNameWithVersion()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testNameCanBeRetrieved()/*: void*/ { $this->assertInternalType('string', $this->env->getName()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testVersionCanBeRetrieved()/*: void*/ { $this->assertInternalType('string', $this->env->getVersion()); } /** * @todo Now that this component is PHP 7-only and uses return type declarations * this test makes even less sense than before */ public function testVendorUrlCanBeRetrieved()/*: void*/ { $this->assertInternalType('string', $this->env->getVendorUrl()); } }