PK %Z4;= DF DF phpunit/phpunit.xsdnu [
This Schema file defines the rules by which the XML configuration file of PHPUnit 9.6 may be structured.
Root Element
The main type specifying the document structure
PK %Z& & phpunit/phpunitnu [ #!/usr/bin/env php
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!version_compare(PHP_VERSION, PHP_VERSION, '=')) {
fwrite(
STDERR,
sprintf(
'%s declares an invalid value for PHP_VERSION.' . PHP_EOL .
'This breaks fundamental functionality such as version_compare().' . PHP_EOL .
'Please use a different PHP interpreter.' . PHP_EOL,
PHP_BINARY
)
);
die(1);
}
if (version_compare('7.3.0', PHP_VERSION, '>')) {
fwrite(
STDERR,
sprintf(
'This version of PHPUnit requires PHP >= 7.3.' . PHP_EOL .
'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINARY
)
);
die(1);
}
foreach (['dom', 'json', 'libxml', 'mbstring', 'tokenizer', 'xml', 'xmlwriter'] as $extension) {
if (extension_loaded($extension)) {
continue;
}
fwrite(
STDERR,
sprintf(
'PHPUnit requires the "%s" extension.' . PHP_EOL,
$extension
)
);
die(1);
}
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
if (isset($GLOBALS['_composer_autoload_path'])) {
define('PHPUNIT_COMPOSER_INSTALL', $GLOBALS['_composer_autoload_path']);
unset($GLOBALS['_composer_autoload_path']);
} else {
foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
if (file_exists($file)) {
define('PHPUNIT_COMPOSER_INSTALL', $file);
break;
}
}
unset($file);
}
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
fwrite(
STDERR,
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
' composer install' . PHP_EOL . PHP_EOL .
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
);
die(1);
}
$options = getopt('', array('prepend:'));
if (isset($options['prepend'])) {
require $options['prepend'];
}
unset($options);
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
PK %Z3 phpunit/composer.jsonnu [ {
"name": "phpunit/phpunit",
"description": "The PHP Unit Testing framework.",
"type": "library",
"keywords": [
"phpunit",
"xunit",
"testing"
],
"homepage": "https://phpunit.de/",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues"
},
"prefer-stable": true,
"require": {
"php": ">=7.3",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",
"doctrine/instantiator": "^1.3.1 || ^2",
"myclabs/deep-copy": "^1.10.1",
"phar-io/manifest": "^2.0.3",
"phar-io/version": "^3.0.2",
"phpunit/php-code-coverage": "^9.2.13",
"phpunit/php-file-iterator": "^3.0.5",
"phpunit/php-invoker": "^3.1.1",
"phpunit/php-text-template": "^2.0.3",
"phpunit/php-timer": "^5.0.2",
"sebastian/cli-parser": "^1.0.1",
"sebastian/code-unit": "^1.0.6",
"sebastian/comparator": "^4.0.8",
"sebastian/diff": "^4.0.3",
"sebastian/environment": "^5.1.3",
"sebastian/exporter": "^4.0.5",
"sebastian/global-state": "^5.0.1",
"sebastian/object-enumerator": "^4.0.3",
"sebastian/resource-operations": "^3.0.3",
"sebastian/type": "^3.2",
"sebastian/version": "^3.0.2"
},
"config": {
"platform": {
"php": "7.3.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"suggest": {
"ext-soap": "To be able to generate mocks based on WSDL files",
"ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage"
},
"bin": [
"phpunit"
],
"autoload": {
"classmap": [
"src/"
],
"files": [
"src/Framework/Assert/Functions.php"
]
},
"autoload-dev": {
"classmap": [
"tests/"
],
"files": [
"tests/_files/CoverageNamespacedFunctionTest.php",
"tests/_files/CoveredFunction.php",
"tests/_files/NamespaceCoveredFunction.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "9.6-dev"
}
}
}
PK %Z=߸6 6 phpunit/ChangeLog-8.5.mdnu [ # Changes in PHPUnit 8.5
All notable changes of the PHPUnit 8.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [8.5.33] - 2023-02-27
### Fixed
* [#5186](https://github.com/sebastianbergmann/phpunit/issues/5186): SBOM does not validate
## [8.5.32] - 2023-01-26
### Fixed
* [#5120](https://github.com/sebastianbergmann/phpunit/issues/5120): Test Runner incorrectly treats `--testsuite` and `--list-tests` as not combinable options
## [8.5.31] - 2022-10-28
### Fixed
* [#5076](https://github.com/sebastianbergmann/phpunit/issues/5076): Test Runner does not warn about conflicting options
## [8.5.30] - 2022-09-25
### Changed
* The configuration generator now asks for a cache directory
### Fixed
* [#4913](https://github.com/sebastianbergmann/phpunit/issues/4913): Failed `assert()` should show a backtrace
* [#4966](https://github.com/sebastianbergmann/phpunit/issues/4966): `TestCase::assertSame()` (and related exact comparisons) must compare `float` exactly
## [8.5.29] - 2022-08-22
### Changed
* [#5033](https://github.com/sebastianbergmann/phpunit/issues/5033): Do not depend on phpspec/prophecy
## [8.5.28] - 2022-07-29
### Fixed
* [#5015](https://github.com/sebastianbergmann/phpunit/pull/5015): Ukraine banner unreadable on black background
* [#5016](https://github.com/sebastianbergmann/phpunit/issues/5016): PHPUnit 8.5.27 does not work on PHP 7.2.0-7.2.18 and PHP 7.3.0-7.3.5
## [8.5.27] - 2022-06-19
### Fixed
* [#4950](https://github.com/sebastianbergmann/phpunit/issues/4950): False error on `atMost()` invocation rule without call
* [#4962](https://github.com/sebastianbergmann/phpunit/issues/4962): Ukraine banner unreadable on white background
## [8.5.26] - 2022-04-01
### Fixed
* [#4938](https://github.com/sebastianbergmann/phpunit/issues/4938): Test Double code generator does not handle `void` return type declaration on `__clone()` methods
## [8.5.25] - 2022-03-16
### Fixed
* [#4934](https://github.com/sebastianbergmann/phpunit/issues/4934): Code Coverage does not work with PHPUnit 8.5.24 PHAR on PHP 7
## [8.5.24] - 2022-03-05 - #StandWithUkraine
### Changed
* [#4874](https://github.com/sebastianbergmann/phpunit/pull/4874): `PHP_FLOAT_EPSILON` is now used instead of hardcoded `0.0000000001` in `PHPUnit\Framework\Constraint\IsIdentical`
### Fixed
* When the HTML code coverage report's configured low upper bound is larger than the high lower bound then the default values are used instead
## [8.5.23] - 2022-01-21
### Fixed
* [#4799](https://github.com/sebastianbergmann/phpunit/pull/4799): Memory leaks in `PHPUnit\Framework\TestSuite` class
* [#4857](https://github.com/sebastianbergmann/phpunit/pull/4857): Result of `debug_backtrace()` is not used correctly
## [8.5.22] - 2021-12-25
### Changed
* [#4812](https://github.com/sebastianbergmann/phpunit/issues/4812): Do not enforce time limits when a debugging session through DBGp is active
* [#4835](https://github.com/sebastianbergmann/phpunit/issues/4835): Support for `$GLOBALS['_composer_autoload_path']` introduced in Composer 2.2
### Fixed
* [#4840](https://github.com/sebastianbergmann/phpunit/pull/4840): TestDox prettifying for class names does not correctly handle diacritics
* [#4846](https://github.com/sebastianbergmann/phpunit/pull/4846): Composer proxy script is not ignored
## [8.5.21] - 2021-09-25
### Changed
* PHPUnit no longer converts PHP deprecations to exceptions by default (configure `convertDeprecationsToExceptions="true"` to enable this)
* The PHPUnit XML configuration file generator now configures `convertDeprecationsToExceptions="true"`
### Fixed
* [#4772](https://github.com/sebastianbergmann/phpunit/pull/4772): TestDox HTML report not displayed correctly when browser has custom colour settings
## [8.5.20] - 2021-08-31
### Fixed
* [#4751](https://github.com/sebastianbergmann/phpunit/issues/4751): Configuration validation fails when using brackets in glob pattern
## [8.5.19] - 2021-07-31
### Fixed
* [#4740](https://github.com/sebastianbergmann/phpunit/issues/4740): `phpunit.phar` does not work with PHP 8.1
## [8.5.18] - 2021-07-19
### Fixed
* [#4720](https://github.com/sebastianbergmann/phpunit/issues/4720): PHPUnit does not verify its own PHP extension requirements
## [8.5.17] - 2021-06-23
### Changed
* PHPUnit now errors out on startup when `PHP_VERSION` contains a value that is not compatible with `version_compare()`, for instance `X.Y.Z-(to be removed in future macOS)`
## [8.5.16] - 2021-06-05
### Changed
* The test result cache (the storage for which is implemented in `PHPUnit\Runner\DefaultTestResultCache`) no longer uses PHP's `serialize()` and `unserialize()` functions for persistence. It now uses a versioned JSON format instead that is independent of PHP implementation details (see [#3581](https://github.com/sebastianbergmann/phpunit/issues/3581) and [#4662](https://github.com/sebastianbergmann/phpunit/pull/4662) for examples why this is a problem). When PHPUnit tries to load the test result cache from a file that does not exist, or from a file that does not contain data in JSON format, or from a file that contains data in a JSON format version other than the one used by the currently running PHPUnit version, then this is considered to be a "cache miss". An empty `DefaultTestResultCache` object is created in this case. This should also prevent PHPUnit from crashing when trying to load a test result cache file created by a different version of PHPUnit (see [#4580](https://github.com/sebastianbergmann/phpunit/issues/4580) for example).
### Fixed
* [#4663](https://github.com/sebastianbergmann/phpunit/issues/4663): `TestCase::expectError()` works on PHP 7.3, but not on PHP >= 7.4
* [#4678](https://github.com/sebastianbergmann/phpunit/pull/4678): Stubbed methods with `iterable` return types should return empty array by default
* [#4692](https://github.com/sebastianbergmann/phpunit/issues/4692): Annotations in single-line doc-comments are not handled correctly
* [#4694](https://github.com/sebastianbergmann/phpunit/issues/4694): `TestCase::getMockFromWsdl()` does not work with PHP 8.1-dev
## [8.5.15] - 2021-03-17
### Fixed
* [#4591](https://github.com/sebastianbergmann/phpunit/issues/4591): TeamCity logger logs warnings as test failures
## [8.5.14] - 2021-01-17
### Fixed
* [#4535](https://github.com/sebastianbergmann/phpunit/issues/4535): `getMockFromWsdl()` does not handle methods that do not have parameters correctly
* [#4572](https://github.com/sebastianbergmann/phpunit/issues/4572): Schema validation does not work with `%xx` sequences in path to `phpunit.xsd`
* [#4575](https://github.com/sebastianbergmann/phpunit/issues/4575): PHPUnit 8.5 incompatibility with PHP 8.1
## [8.5.13] - 2020-12-01
### Fixed
* Running tests in isolated processes did not work with PHP 8 on Windows
## [8.5.12] - 2020-11-30
### Changed
* Changed PHP version constraint in `composer.json` from `^7.2` to `>=7.2` to allow the installation of PHPUnit 8.5 on PHP 8. Please note that the code coverage functionality is not available for PHPUnit 8.5 on PHP 8.
### Fixed
* [#4529](https://github.com/sebastianbergmann/phpunit/issues/4529): Debug mode of Xdebug 2 is not disabled for PHPT tests
## [8.5.11] - 2020-11-27
### Changed
* Bumped required version of `phpunit/php-code-coverage`
## [8.5.10] - 2020-11-27
### Added
* Support for Xdebug 3
### Fixed
* [#4516](https://github.com/sebastianbergmann/phpunit/issues/4516): `phpunit/phpunit-selenium` does not work with PHPUnit 8.5.9
## [8.5.9] - 2020-11-10
### Fixed
* [#3965](https://github.com/sebastianbergmann/phpunit/issues/3965): Process Isolation throws exceptions when PHPDBG is used
* [#4470](https://github.com/sebastianbergmann/phpunit/pull/4470): Infinite recursion when `--static-backup --strict-global-state` is used
## [8.5.8] - 2020-06-22
### Fixed
* [#4312](https://github.com/sebastianbergmann/phpunit/issues/4312): Fix for [#4299](https://github.com/sebastianbergmann/phpunit/issues/4299) breaks backward compatibility
## [8.5.7] - 2020-06-21
### Fixed
* [#4299](https://github.com/sebastianbergmann/phpunit/issues/4299): "No tests executed" does not always result in exit code `1`
* [#4306](https://github.com/sebastianbergmann/phpunit/issues/4306): Exceptions during code coverage driver initialization are not handled correctly
## [8.5.6] - 2020-06-15
### Fixed
* [#4211](https://github.com/sebastianbergmann/phpunit/issues/4211): `phpdbg_*()` functions are scoped to `PHPUnit\phpdbg_*()`
## [8.5.5] - 2020-05-22
### Fixed
* [#4033](https://github.com/sebastianbergmann/phpunit/issues/4033): Unexpected behaviour when `$GLOBALS` is deleted
## [8.5.4] - 2020-04-23
### Changed
* Changed how `PHPUnit\TextUI\Command` passes warnings to `PHPUnit\TextUI\TestRunner`
## [8.5.3] - 2020-03-31
### Fixed
* [#4017](https://github.com/sebastianbergmann/phpunit/issues/4017): Do not suggest refactoring to something that is also deprecated
* [#4133](https://github.com/sebastianbergmann/phpunit/issues/4133): `expectExceptionMessageRegExp()` has been removed in PHPUnit 9 without a deprecation warning being given in PHPUnit 8
* [#4139](https://github.com/sebastianbergmann/phpunit/issues/4139): Cannot double interfaces that declare a constructor with PHP 8
* [#4144](https://github.com/sebastianbergmann/phpunit/issues/4144): Empty objects are converted to empty arrays in JSON comparison failure diff
## [8.5.2] - 2020-01-08
### Removed
* `eval-stdin.php` has been removed, it was not used anymore since PHPUnit 7.2.7
## [8.5.1] - 2019-12-25
### Changed
* `eval-stdin.php` can now only be executed with `cli` and `phpdbg`
### Fixed
* [#3983](https://github.com/sebastianbergmann/phpunit/issues/3983): Deprecation warning given too eagerly
## [8.5.0] - 2019-12-06
### Added
* [#3911](https://github.com/sebastianbergmann/phpunit/issues/3911): Support combined use of `addMethods()` and `onlyMethods()`
* [#3949](https://github.com/sebastianbergmann/phpunit/issues/3949): Introduce specialized assertions `assertFileEqualsCanonicalizing()`, `assertFileEqualsIgnoringCase()`, `assertStringEqualsFileCanonicalizing()`, `assertStringEqualsFileIgnoringCase()`, `assertFileNotEqualsCanonicalizing()`, `assertFileNotEqualsIgnoringCase()`, `assertStringNotEqualsFileCanonicalizing()`, and `assertStringNotEqualsFileIgnoringCase()` as alternative to using `assertFileEquals()` etc. with optional parameters
### Changed
* [#3860](https://github.com/sebastianbergmann/phpunit/pull/3860): Deprecate invoking PHPUnit commandline test runner with just a class name
* [#3950](https://github.com/sebastianbergmann/phpunit/issues/3950): Deprecate optional parameters of `assertFileEquals()` etc.
* [#3955](https://github.com/sebastianbergmann/phpunit/issues/3955): Deprecate support for doubling multiple interfaces
### Fixed
* [#3953](https://github.com/sebastianbergmann/phpunit/issues/3953): Code Coverage for test executed in isolation does not work when the PHAR is used
* [#3967](https://github.com/sebastianbergmann/phpunit/issues/3967): Cannot double interface that extends interface that extends `\Throwable`
* [#3968](https://github.com/sebastianbergmann/phpunit/pull/3968): Test class run in a separate PHP process are passing when `exit` called inside
[8.5.33]: https://github.com/sebastianbergmann/phpunit/compare/8.5.32...8.5.33
[8.5.32]: https://github.com/sebastianbergmann/phpunit/compare/8.5.31...8.5.32
[8.5.31]: https://github.com/sebastianbergmann/phpunit/compare/8.5.30...8.5.31
[8.5.30]: https://github.com/sebastianbergmann/phpunit/compare/8.5.29...8.5.30
[8.5.29]: https://github.com/sebastianbergmann/phpunit/compare/8.5.28...8.5.29
[8.5.28]: https://github.com/sebastianbergmann/phpunit/compare/8.5.27...8.5.28
[8.5.27]: https://github.com/sebastianbergmann/phpunit/compare/8.5.26...8.5.27
[8.5.26]: https://github.com/sebastianbergmann/phpunit/compare/8.5.25...8.5.26
[8.5.25]: https://github.com/sebastianbergmann/phpunit/compare/8.5.24...8.5.25
[8.5.24]: https://github.com/sebastianbergmann/phpunit/compare/8.5.23...8.5.24
[8.5.23]: https://github.com/sebastianbergmann/phpunit/compare/8.5.22...8.5.23
[8.5.22]: https://github.com/sebastianbergmann/phpunit/compare/8.5.21...8.5.22
[8.5.21]: https://github.com/sebastianbergmann/phpunit/compare/8.5.20...8.5.21
[8.5.20]: https://github.com/sebastianbergmann/phpunit/compare/8.5.19...8.5.20
[8.5.19]: https://github.com/sebastianbergmann/phpunit/compare/8.5.18...8.5.19
[8.5.18]: https://github.com/sebastianbergmann/phpunit/compare/8.5.17...8.5.18
[8.5.17]: https://github.com/sebastianbergmann/phpunit/compare/8.5.16...8.5.17
[8.5.16]: https://github.com/sebastianbergmann/phpunit/compare/8.5.15...8.5.16
[8.5.15]: https://github.com/sebastianbergmann/phpunit/compare/8.5.14...8.5.15
[8.5.14]: https://github.com/sebastianbergmann/phpunit/compare/8.5.13...8.5.14
[8.5.13]: https://github.com/sebastianbergmann/phpunit/compare/8.5.12...8.5.13
[8.5.12]: https://github.com/sebastianbergmann/phpunit/compare/8.5.11...8.5.12
[8.5.11]: https://github.com/sebastianbergmann/phpunit/compare/8.5.10...8.5.11
[8.5.10]: https://github.com/sebastianbergmann/phpunit/compare/8.5.9...8.5.10
[8.5.9]: https://github.com/sebastianbergmann/phpunit/compare/8.5.8...8.5.9
[8.5.8]: https://github.com/sebastianbergmann/phpunit/compare/8.5.7...8.5.8
[8.5.7]: https://github.com/sebastianbergmann/phpunit/compare/8.5.6...8.5.7
[8.5.6]: https://github.com/sebastianbergmann/phpunit/compare/8.5.5...8.5.6
[8.5.5]: https://github.com/sebastianbergmann/phpunit/compare/8.5.4...8.5.5
[8.5.4]: https://github.com/sebastianbergmann/phpunit/compare/8.5.3...8.5.4
[8.5.3]: https://github.com/sebastianbergmann/phpunit/compare/8.5.2...8.5.3
[8.5.2]: https://github.com/sebastianbergmann/phpunit/compare/8.5.1...8.5.2
[8.5.1]: https://github.com/sebastianbergmann/phpunit/compare/8.5.0...8.5.1
[8.5.0]: https://github.com/sebastianbergmann/phpunit/compare/8.4.3...8.5.0
PK %Z,u~G) G) ! phpunit/src/Util/Log/TeamCity.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Log;
use function class_exists;
use function count;
use function explode;
use function get_class;
use function getmypid;
use function ini_get;
use function is_bool;
use function is_scalar;
use function method_exists;
use function print_r;
use function round;
use function str_replace;
use function stripos;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\ExceptionWrapper;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestFailure;
use PHPUnit\Framework\TestResult;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\TextUI\DefaultResultPrinter;
use PHPUnit\Util\Exception;
use PHPUnit\Util\Filter;
use ReflectionClass;
use ReflectionException;
use SebastianBergmann\Comparator\ComparisonFailure;
use Throwable;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class TeamCity extends DefaultResultPrinter
{
/**
* @var bool
*/
private $isSummaryTestCountPrinted = false;
/**
* @var string
*/
private $startedTestName;
/**
* @var false|int
*/
private $flowId;
public function printResult(TestResult $result): void
{
$this->printHeader($result);
$this->printFooter($result);
}
/**
* An error occurred.
*/
public function addError(Test $test, Throwable $t, float $time): void
{
$this->printEvent(
'testFailed',
[
'name' => $test->getName(),
'message' => self::getMessage($t),
'details' => self::getDetails($t),
'duration' => self::toMilliseconds($time),
]
);
}
/**
* A warning occurred.
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
$this->write(self::getMessage($e) . PHP_EOL);
}
/**
* A failure occurred.
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$parameters = [
'name' => $test->getName(),
'message' => self::getMessage($e),
'details' => self::getDetails($e),
'duration' => self::toMilliseconds($time),
];
if ($e instanceof ExpectationFailedException) {
$comparisonFailure = $e->getComparisonFailure();
if ($comparisonFailure instanceof ComparisonFailure) {
$expectedString = $comparisonFailure->getExpectedAsString();
if ($expectedString === null || empty($expectedString)) {
$expectedString = self::getPrimitiveValueAsString($comparisonFailure->getExpected());
}
$actualString = $comparisonFailure->getActualAsString();
if ($actualString === null || empty($actualString)) {
$actualString = self::getPrimitiveValueAsString($comparisonFailure->getActual());
}
if ($actualString !== null && $expectedString !== null) {
$parameters['type'] = 'comparisonFailure';
$parameters['actual'] = $actualString;
$parameters['expected'] = $expectedString;
}
}
}
$this->printEvent('testFailed', $parameters);
}
/**
* Incomplete test.
*/
public function addIncompleteTest(Test $test, Throwable $t, float $time): void
{
$this->printIgnoredTest($test->getName(), $t, $time);
}
/**
* Risky test.
*/
public function addRiskyTest(Test $test, Throwable $t, float $time): void
{
$this->addError($test, $t, $time);
}
/**
* Skipped test.
*/
public function addSkippedTest(Test $test, Throwable $t, float $time): void
{
$testName = $test->getName();
if ($this->startedTestName !== $testName) {
$this->startTest($test);
$this->printIgnoredTest($testName, $t, $time);
$this->endTest($test, $time);
} else {
$this->printIgnoredTest($testName, $t, $time);
}
}
public function printIgnoredTest(string $testName, Throwable $t, float $time): void
{
$this->printEvent(
'testIgnored',
[
'name' => $testName,
'message' => self::getMessage($t),
'details' => self::getDetails($t),
'duration' => self::toMilliseconds($time),
]
);
}
/**
* A testsuite started.
*/
public function startTestSuite(TestSuite $suite): void
{
if (stripos(ini_get('disable_functions'), 'getmypid') === false) {
$this->flowId = getmypid();
} else {
$this->flowId = false;
}
if (!$this->isSummaryTestCountPrinted) {
$this->isSummaryTestCountPrinted = true;
$this->printEvent(
'testCount',
['count' => count($suite)]
);
}
$suiteName = $suite->getName();
if (empty($suiteName)) {
return;
}
$parameters = ['name' => $suiteName];
if (class_exists($suiteName, false)) {
$fileName = self::getFileName($suiteName);
$parameters['locationHint'] = "php_qn://{$fileName}::\\{$suiteName}";
} else {
$split = explode('::', $suiteName);
if (count($split) === 2 && class_exists($split[0]) && method_exists($split[0], $split[1])) {
$fileName = self::getFileName($split[0]);
$parameters['locationHint'] = "php_qn://{$fileName}::\\{$suiteName}";
$parameters['name'] = $split[1];
}
}
$this->printEvent('testSuiteStarted', $parameters);
}
/**
* A testsuite ended.
*/
public function endTestSuite(TestSuite $suite): void
{
$suiteName = $suite->getName();
if (empty($suiteName)) {
return;
}
$parameters = ['name' => $suiteName];
if (!class_exists($suiteName, false)) {
$split = explode('::', $suiteName);
if (count($split) === 2 && class_exists($split[0]) && method_exists($split[0], $split[1])) {
$parameters['name'] = $split[1];
}
}
$this->printEvent('testSuiteFinished', $parameters);
}
/**
* A test started.
*/
public function startTest(Test $test): void
{
$testName = $test->getName();
$this->startedTestName = $testName;
$params = ['name' => $testName];
if ($test instanceof TestCase) {
$className = get_class($test);
$fileName = self::getFileName($className);
$params['locationHint'] = "php_qn://{$fileName}::\\{$className}::{$testName}";
}
$this->printEvent('testStarted', $params);
}
/**
* A test ended.
*/
public function endTest(Test $test, float $time): void
{
parent::endTest($test, $time);
$this->printEvent(
'testFinished',
[
'name' => $test->getName(),
'duration' => self::toMilliseconds($time),
]
);
}
protected function writeProgress(string $progress): void
{
}
private function printEvent(string $eventName, array $params = []): void
{
$this->write("\n##teamcity[{$eventName}");
if ($this->flowId) {
$params['flowId'] = $this->flowId;
}
foreach ($params as $key => $value) {
$escapedValue = self::escapeValue((string) $value);
$this->write(" {$key}='{$escapedValue}'");
}
$this->write("]\n");
}
private static function getMessage(Throwable $t): string
{
$message = '';
if ($t instanceof ExceptionWrapper) {
if ($t->getClassName() !== '') {
$message .= $t->getClassName();
}
if ($message !== '' && $t->getMessage() !== '') {
$message .= ' : ';
}
}
return $message . $t->getMessage();
}
private static function getDetails(Throwable $t): string
{
$stackTrace = Filter::getFilteredStacktrace($t);
$previous = $t instanceof ExceptionWrapper ? $t->getPreviousWrapped() : $t->getPrevious();
while ($previous) {
$stackTrace .= "\nCaused by\n" .
TestFailure::exceptionToString($previous) . "\n" .
Filter::getFilteredStacktrace($previous);
$previous = $previous instanceof ExceptionWrapper ?
$previous->getPreviousWrapped() : $previous->getPrevious();
}
return ' ' . str_replace("\n", "\n ", $stackTrace);
}
private static function getPrimitiveValueAsString($value): ?string
{
if ($value === null) {
return 'null';
}
if (is_bool($value)) {
return $value ? 'true' : 'false';
}
if (is_scalar($value)) {
return print_r($value, true);
}
return null;
}
private static function escapeValue(string $text): string
{
return str_replace(
['|', "'", "\n", "\r", ']', '['],
['||', "|'", '|n', '|r', '|]', '|['],
$text
);
}
/**
* @param string $className
*/
private static function getFileName($className): string
{
try {
return (new ReflectionClass($className))->getFileName();
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
}
/**
* @param float $time microseconds
*/
private static function toMilliseconds(float $time): int
{
return (int) round($time * 1000);
}
}
PK %ZFk- - phpunit/src/Util/Log/JUnit.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Log;
use function class_exists;
use function get_class;
use function method_exists;
use function sprintf;
use function str_replace;
use function trim;
use DOMDocument;
use DOMElement;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\ExceptionWrapper;
use PHPUnit\Framework\SelfDescribing;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestFailure;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\Util\Exception;
use PHPUnit\Util\Filter;
use PHPUnit\Util\Printer;
use PHPUnit\Util\Xml;
use ReflectionClass;
use ReflectionException;
use Throwable;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class JUnit extends Printer implements TestListener
{
/**
* @var DOMDocument
*/
private $document;
/**
* @var DOMElement
*/
private $root;
/**
* @var bool
*/
private $reportRiskyTests = false;
/**
* @var DOMElement[]
*/
private $testSuites = [];
/**
* @var int[]
*/
private $testSuiteTests = [0];
/**
* @var int[]
*/
private $testSuiteAssertions = [0];
/**
* @var int[]
*/
private $testSuiteErrors = [0];
/**
* @var int[]
*/
private $testSuiteWarnings = [0];
/**
* @var int[]
*/
private $testSuiteFailures = [0];
/**
* @var int[]
*/
private $testSuiteSkipped = [0];
/**
* @var int[]
*/
private $testSuiteTimes = [0];
/**
* @var int
*/
private $testSuiteLevel = 0;
/**
* @var DOMElement
*/
private $currentTestCase;
/**
* @param null|mixed $out
*/
public function __construct($out = null, bool $reportRiskyTests = false)
{
$this->document = new DOMDocument('1.0', 'UTF-8');
$this->document->formatOutput = true;
$this->root = $this->document->createElement('testsuites');
$this->document->appendChild($this->root);
parent::__construct($out);
$this->reportRiskyTests = $reportRiskyTests;
}
/**
* Flush buffer and close output.
*/
public function flush(): void
{
$this->write($this->getXML());
parent::flush();
}
/**
* An error occurred.
*/
public function addError(Test $test, Throwable $t, float $time): void
{
$this->doAddFault($test, $t, 'error');
$this->testSuiteErrors[$this->testSuiteLevel]++;
}
/**
* A warning occurred.
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
$this->doAddFault($test, $e, 'warning');
$this->testSuiteWarnings[$this->testSuiteLevel]++;
}
/**
* A failure occurred.
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$this->doAddFault($test, $e, 'failure');
$this->testSuiteFailures[$this->testSuiteLevel]++;
}
/**
* Incomplete test.
*/
public function addIncompleteTest(Test $test, Throwable $t, float $time): void
{
$this->doAddSkipped();
}
/**
* Risky test.
*/
public function addRiskyTest(Test $test, Throwable $t, float $time): void
{
if (!$this->reportRiskyTests) {
return;
}
$this->doAddFault($test, $t, 'error');
$this->testSuiteErrors[$this->testSuiteLevel]++;
}
/**
* Skipped test.
*/
public function addSkippedTest(Test $test, Throwable $t, float $time): void
{
$this->doAddSkipped();
}
/**
* A testsuite started.
*/
public function startTestSuite(TestSuite $suite): void
{
$testSuite = $this->document->createElement('testsuite');
$testSuite->setAttribute('name', $suite->getName());
if (class_exists($suite->getName(), false)) {
try {
$class = new ReflectionClass($suite->getName());
$testSuite->setAttribute('file', $class->getFileName());
} catch (ReflectionException $e) {
}
}
if ($this->testSuiteLevel > 0) {
$this->testSuites[$this->testSuiteLevel]->appendChild($testSuite);
} else {
$this->root->appendChild($testSuite);
}
$this->testSuiteLevel++;
$this->testSuites[$this->testSuiteLevel] = $testSuite;
$this->testSuiteTests[$this->testSuiteLevel] = 0;
$this->testSuiteAssertions[$this->testSuiteLevel] = 0;
$this->testSuiteErrors[$this->testSuiteLevel] = 0;
$this->testSuiteWarnings[$this->testSuiteLevel] = 0;
$this->testSuiteFailures[$this->testSuiteLevel] = 0;
$this->testSuiteSkipped[$this->testSuiteLevel] = 0;
$this->testSuiteTimes[$this->testSuiteLevel] = 0;
}
/**
* A testsuite ended.
*/
public function endTestSuite(TestSuite $suite): void
{
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'tests',
(string) $this->testSuiteTests[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'assertions',
(string) $this->testSuiteAssertions[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'errors',
(string) $this->testSuiteErrors[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'warnings',
(string) $this->testSuiteWarnings[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'failures',
(string) $this->testSuiteFailures[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'skipped',
(string) $this->testSuiteSkipped[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'time',
sprintf('%F', $this->testSuiteTimes[$this->testSuiteLevel])
);
if ($this->testSuiteLevel > 1) {
$this->testSuiteTests[$this->testSuiteLevel - 1] += $this->testSuiteTests[$this->testSuiteLevel];
$this->testSuiteAssertions[$this->testSuiteLevel - 1] += $this->testSuiteAssertions[$this->testSuiteLevel];
$this->testSuiteErrors[$this->testSuiteLevel - 1] += $this->testSuiteErrors[$this->testSuiteLevel];
$this->testSuiteWarnings[$this->testSuiteLevel - 1] += $this->testSuiteWarnings[$this->testSuiteLevel];
$this->testSuiteFailures[$this->testSuiteLevel - 1] += $this->testSuiteFailures[$this->testSuiteLevel];
$this->testSuiteSkipped[$this->testSuiteLevel - 1] += $this->testSuiteSkipped[$this->testSuiteLevel];
$this->testSuiteTimes[$this->testSuiteLevel - 1] += $this->testSuiteTimes[$this->testSuiteLevel];
}
$this->testSuiteLevel--;
}
/**
* A test started.
*/
public function startTest(Test $test): void
{
$usesDataprovider = false;
if (method_exists($test, 'usesDataProvider')) {
$usesDataprovider = $test->usesDataProvider();
}
$testCase = $this->document->createElement('testcase');
$testCase->setAttribute('name', $test->getName());
try {
$class = new ReflectionClass($test);
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
$methodName = $test->getName(!$usesDataprovider);
if ($class->hasMethod($methodName)) {
try {
$method = $class->getMethod($methodName);
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
$testCase->setAttribute('class', $class->getName());
$testCase->setAttribute('classname', str_replace('\\', '.', $class->getName()));
$testCase->setAttribute('file', $class->getFileName());
$testCase->setAttribute('line', (string) $method->getStartLine());
}
$this->currentTestCase = $testCase;
}
/**
* A test ended.
*/
public function endTest(Test $test, float $time): void
{
$numAssertions = 0;
if (method_exists($test, 'getNumAssertions')) {
$numAssertions = $test->getNumAssertions();
}
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
$this->currentTestCase->setAttribute(
'assertions',
(string) $numAssertions
);
$this->currentTestCase->setAttribute(
'time',
sprintf('%F', $time)
);
$this->testSuites[$this->testSuiteLevel]->appendChild(
$this->currentTestCase
);
$this->testSuiteTests[$this->testSuiteLevel]++;
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
$testOutput = '';
if (method_exists($test, 'hasOutput') && method_exists($test, 'getActualOutput')) {
$testOutput = $test->hasOutput() ? $test->getActualOutput() : '';
}
if (!empty($testOutput)) {
$systemOut = $this->document->createElement(
'system-out',
Xml::prepareString($testOutput)
);
$this->currentTestCase->appendChild($systemOut);
}
$this->currentTestCase = null;
}
/**
* Returns the XML as a string.
*/
public function getXML(): string
{
return $this->document->saveXML();
}
private function doAddFault(Test $test, Throwable $t, string $type): void
{
if ($this->currentTestCase === null) {
return;
}
if ($test instanceof SelfDescribing) {
$buffer = $test->toString() . "\n";
} else {
$buffer = '';
}
$buffer .= trim(
TestFailure::exceptionToString($t) . "\n" .
Filter::getFilteredStacktrace($t)
);
$fault = $this->document->createElement(
$type,
Xml::prepareString($buffer)
);
if ($t instanceof ExceptionWrapper) {
$fault->setAttribute('type', $t->getClassName());
} else {
$fault->setAttribute('type', get_class($t));
}
$this->currentTestCase->appendChild($fault);
}
private function doAddSkipped(): void
{
if ($this->currentTestCase === null) {
return;
}
$skipped = $this->document->createElement('skipped');
$this->currentTestCase->appendChild($skipped);
$this->testSuiteSkipped[$this->testSuiteLevel]++;
}
}
PK %Z)s phpunit/src/Util/FileLoader.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const DIRECTORY_SEPARATOR;
use function array_diff;
use function array_keys;
use function fopen;
use function get_defined_vars;
use function sprintf;
use function stream_resolve_include_path;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class FileLoader
{
/**
* Checks if a PHP sourcecode file is readable. The sourcecode file is loaded through the load() method.
*
* As a fallback, PHP looks in the directory of the file executing the stream_resolve_include_path function.
* We do not want to load the Test.php file here, so skip it if it found that.
* PHP prioritizes the include_path setting, so if the current directory is in there, it will first look in the
* current working directory.
*
* @throws Exception
*/
public static function checkAndLoad(string $filename): string
{
$includePathFilename = stream_resolve_include_path($filename);
$localFile = __DIR__ . DIRECTORY_SEPARATOR . $filename;
if (!$includePathFilename ||
$includePathFilename === $localFile ||
!self::isReadable($includePathFilename)) {
throw new Exception(
sprintf('Cannot open file "%s".' . "\n", $filename)
);
}
self::load($includePathFilename);
return $includePathFilename;
}
/**
* Loads a PHP sourcefile.
*/
public static function load(string $filename): void
{
$oldVariableNames = array_keys(get_defined_vars());
/**
* @noinspection PhpIncludeInspection
*
* @psalm-suppress UnresolvableInclude
*/
include_once $filename;
$newVariables = get_defined_vars();
foreach (array_diff(array_keys($newVariables), $oldVariableNames) as $variableName) {
if ($variableName !== 'oldVariableNames') {
$GLOBALS[$variableName] = $newVariables[$variableName];
}
}
}
/**
* @see https://github.com/sebastianbergmann/phpunit/pull/2751
*/
private static function isReadable(string $filename): bool
{
return @fopen($filename, 'r') !== false;
}
}
PK %Z/O * phpunit/src/Util/PHP/DefaultPhpProcess.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\PHP;
use function array_merge;
use function fclose;
use function file_put_contents;
use function fread;
use function fwrite;
use function is_array;
use function is_resource;
use function proc_close;
use function proc_open;
use function proc_terminate;
use function rewind;
use function sprintf;
use function stream_get_contents;
use function stream_select;
use function sys_get_temp_dir;
use function tempnam;
use function unlink;
use PHPUnit\Framework\Exception;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
class DefaultPhpProcess extends AbstractPhpProcess
{
/**
* @var string
*/
protected $tempFile;
/**
* Runs a single job (PHP code) using a separate PHP process.
*
* @throws Exception
*/
public function runJob(string $job, array $settings = []): array
{
if ($this->stdin || $this->useTemporaryFile()) {
if (!($this->tempFile = tempnam(sys_get_temp_dir(), 'PHPUnit')) ||
file_put_contents($this->tempFile, $job) === false) {
throw new Exception(
'Unable to write temporary file'
);
}
$job = $this->stdin;
}
return $this->runProcess($job, $settings);
}
/**
* Returns an array of file handles to be used in place of pipes.
*/
protected function getHandles(): array
{
return [];
}
/**
* Handles creating the child process and returning the STDOUT and STDERR.
*
* @throws Exception
*/
protected function runProcess(string $job, array $settings): array
{
$handles = $this->getHandles();
$env = null;
if ($this->env) {
$env = $_SERVER ?? [];
unset($env['argv'], $env['argc']);
$env = array_merge($env, $this->env);
foreach ($env as $envKey => $envVar) {
if (is_array($envVar)) {
unset($env[$envKey]);
}
}
}
$pipeSpec = [
0 => $handles[0] ?? ['pipe', 'r'],
1 => $handles[1] ?? ['pipe', 'w'],
2 => $handles[2] ?? ['pipe', 'w'],
];
$process = proc_open(
$this->getCommand($settings, $this->tempFile),
$pipeSpec,
$pipes,
null,
$env
);
if (!is_resource($process)) {
throw new Exception(
'Unable to spawn worker process'
);
}
if ($job) {
$this->process($pipes[0], $job);
}
fclose($pipes[0]);
$stderr = $stdout = '';
if ($this->timeout) {
unset($pipes[0]);
while (true) {
$r = $pipes;
$w = null;
$e = null;
$n = @stream_select($r, $w, $e, $this->timeout);
if ($n === false) {
break;
}
if ($n === 0) {
proc_terminate($process, 9);
throw new Exception(
sprintf(
'Job execution aborted after %d seconds',
$this->timeout
)
);
}
if ($n > 0) {
foreach ($r as $pipe) {
$pipeOffset = 0;
foreach ($pipes as $i => $origPipe) {
if ($pipe === $origPipe) {
$pipeOffset = $i;
break;
}
}
if (!$pipeOffset) {
break;
}
$line = fread($pipe, 8192);
if ($line === '' || $line === false) {
fclose($pipes[$pipeOffset]);
unset($pipes[$pipeOffset]);
} elseif ($pipeOffset === 1) {
$stdout .= $line;
} else {
$stderr .= $line;
}
}
if (empty($pipes)) {
break;
}
}
}
} else {
if (isset($pipes[1])) {
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
}
if (isset($pipes[2])) {
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
}
}
if (isset($handles[1])) {
rewind($handles[1]);
$stdout = stream_get_contents($handles[1]);
fclose($handles[1]);
}
if (isset($handles[2])) {
rewind($handles[2]);
$stderr = stream_get_contents($handles[2]);
fclose($handles[2]);
}
proc_close($process);
$this->cleanup();
return ['stdout' => $stdout, 'stderr' => $stderr];
}
/**
* @param resource $pipe
*/
protected function process($pipe, string $job): void
{
fwrite($pipe, $job);
}
protected function cleanup(): void
{
if ($this->tempFile) {
unlink($this->tempFile);
}
}
protected function useTemporaryFile(): bool
{
return false;
}
}
PK %Zcϑ * phpunit/src/Util/PHP/WindowsPhpProcess.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\PHP;
use const PHP_MAJOR_VERSION;
use function tmpfile;
use PHPUnit\Framework\Exception;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @see https://bugs.php.net/bug.php?id=51800
*/
final class WindowsPhpProcess extends DefaultPhpProcess
{
public function getCommand(array $settings, string $file = null): string
{
if (PHP_MAJOR_VERSION < 8) {
return '"' . parent::getCommand($settings, $file) . '"';
}
return parent::getCommand($settings, $file);
}
/**
* @throws Exception
*/
protected function getHandles(): array
{
if (false === $stdout_handle = tmpfile()) {
throw new Exception(
'A temporary file could not be created; verify that your TEMP environment variable is writable'
);
}
return [
1 => $stdout_handle,
];
}
protected function useTemporaryFile(): bool
{
return true;
}
}
PK %Zw+ + + phpunit/src/Util/PHP/AbstractPhpProcess.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\PHP;
use const DIRECTORY_SEPARATOR;
use const PHP_SAPI;
use function array_keys;
use function array_merge;
use function assert;
use function escapeshellarg;
use function ini_get_all;
use function restore_error_handler;
use function set_error_handler;
use function sprintf;
use function str_replace;
use function strpos;
use function strrpos;
use function substr;
use function trim;
use function unserialize;
use __PHP_Incomplete_Class;
use ErrorException;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\SyntheticError;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestFailure;
use PHPUnit\Framework\TestResult;
use SebastianBergmann\Environment\Runtime;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
abstract class AbstractPhpProcess
{
/**
* @var Runtime
*/
protected $runtime;
/**
* @var bool
*/
protected $stderrRedirection = false;
/**
* @var string
*/
protected $stdin = '';
/**
* @var string
*/
protected $args = '';
/**
* @var array
*/
protected $env = [];
/**
* @var int
*/
protected $timeout = 0;
public static function factory(): self
{
if (DIRECTORY_SEPARATOR === '\\') {
return new WindowsPhpProcess;
}
return new DefaultPhpProcess;
}
public function __construct()
{
$this->runtime = new Runtime;
}
/**
* Defines if should use STDERR redirection or not.
*
* Then $stderrRedirection is TRUE, STDERR is redirected to STDOUT.
*/
public function setUseStderrRedirection(bool $stderrRedirection): void
{
$this->stderrRedirection = $stderrRedirection;
}
/**
* Returns TRUE if uses STDERR redirection or FALSE if not.
*/
public function useStderrRedirection(): bool
{
return $this->stderrRedirection;
}
/**
* Sets the input string to be sent via STDIN.
*/
public function setStdin(string $stdin): void
{
$this->stdin = $stdin;
}
/**
* Returns the input string to be sent via STDIN.
*/
public function getStdin(): string
{
return $this->stdin;
}
/**
* Sets the string of arguments to pass to the php job.
*/
public function setArgs(string $args): void
{
$this->args = $args;
}
/**
* Returns the string of arguments to pass to the php job.
*/
public function getArgs(): string
{
return $this->args;
}
/**
* Sets the array of environment variables to start the child process with.
*
* @param array $env
*/
public function setEnv(array $env): void
{
$this->env = $env;
}
/**
* Returns the array of environment variables to start the child process with.
*/
public function getEnv(): array
{
return $this->env;
}
/**
* Sets the amount of seconds to wait before timing out.
*/
public function setTimeout(int $timeout): void
{
$this->timeout = $timeout;
}
/**
* Returns the amount of seconds to wait before timing out.
*/
public function getTimeout(): int
{
return $this->timeout;
}
/**
* Runs a single test in a separate PHP process.
*
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function runTestJob(string $job, Test $test, TestResult $result): void
{
$result->startTest($test);
$_result = $this->runJob($job);
$this->processChildResult(
$test,
$result,
$_result['stdout'],
$_result['stderr']
);
}
/**
* Returns the command based into the configurations.
*/
public function getCommand(array $settings, string $file = null): string
{
$command = $this->runtime->getBinary();
if ($this->runtime->hasPCOV()) {
$settings = array_merge(
$settings,
$this->runtime->getCurrentSettings(
array_keys(ini_get_all('pcov'))
)
);
} elseif ($this->runtime->hasXdebug()) {
$settings = array_merge(
$settings,
$this->runtime->getCurrentSettings(
array_keys(ini_get_all('xdebug'))
)
);
}
$command .= $this->settingsToParameters($settings);
if (PHP_SAPI === 'phpdbg') {
$command .= ' -qrr';
if (!$file) {
$command .= 's=';
}
}
if ($file) {
$command .= ' ' . escapeshellarg($file);
}
if ($this->args) {
if (!$file) {
$command .= ' --';
}
$command .= ' ' . $this->args;
}
if ($this->stderrRedirection) {
$command .= ' 2>&1';
}
return $command;
}
/**
* Runs a single job (PHP code) using a separate PHP process.
*/
abstract public function runJob(string $job, array $settings = []): array;
protected function settingsToParameters(array $settings): string
{
$buffer = '';
foreach ($settings as $setting) {
$buffer .= ' -d ' . escapeshellarg($setting);
}
return $buffer;
}
/**
* Processes the TestResult object from an isolated process.
*
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
private function processChildResult(Test $test, TestResult $result, string $stdout, string $stderr): void
{
$time = 0;
if (!empty($stderr)) {
$result->addError(
$test,
new Exception(trim($stderr)),
$time
);
} else {
set_error_handler(
/**
* @throws ErrorException
*/
static function ($errno, $errstr, $errfile, $errline): void
{
throw new ErrorException($errstr, $errno, $errno, $errfile, $errline);
}
);
try {
if (strpos($stdout, "#!/usr/bin/env php\n") === 0) {
$stdout = substr($stdout, 19);
}
$childResult = unserialize(str_replace("#!/usr/bin/env php\n", '', $stdout));
restore_error_handler();
if ($childResult === false) {
$result->addFailure(
$test,
new AssertionFailedError('Test was run in child process and ended unexpectedly'),
$time
);
}
} catch (ErrorException $e) {
restore_error_handler();
$childResult = false;
$result->addError(
$test,
new Exception(trim($stdout), 0, $e),
$time
);
}
if ($childResult !== false) {
if (!empty($childResult['output'])) {
$output = $childResult['output'];
}
/* @var TestCase $test */
$test->setResult($childResult['testResult']);
$test->addToAssertionCount($childResult['numAssertions']);
$childResult = $childResult['result'];
assert($childResult instanceof TestResult);
if ($result->getCollectCodeCoverageInformation()) {
$result->getCodeCoverage()->merge(
$childResult->getCodeCoverage()
);
}
$time = $childResult->time();
$notImplemented = $childResult->notImplemented();
$risky = $childResult->risky();
$skipped = $childResult->skipped();
$errors = $childResult->errors();
$warnings = $childResult->warnings();
$failures = $childResult->failures();
if (!empty($notImplemented)) {
$result->addError(
$test,
$this->getException($notImplemented[0]),
$time
);
} elseif (!empty($risky)) {
$result->addError(
$test,
$this->getException($risky[0]),
$time
);
} elseif (!empty($skipped)) {
$result->addError(
$test,
$this->getException($skipped[0]),
$time
);
} elseif (!empty($errors)) {
$result->addError(
$test,
$this->getException($errors[0]),
$time
);
} elseif (!empty($warnings)) {
$result->addWarning(
$test,
$this->getException($warnings[0]),
$time
);
} elseif (!empty($failures)) {
$result->addFailure(
$test,
$this->getException($failures[0]),
$time
);
}
}
}
$result->endTest($test, $time);
if (!empty($output)) {
print $output;
}
}
/**
* Gets the thrown exception from a PHPUnit\Framework\TestFailure.
*
* @see https://github.com/sebastianbergmann/phpunit/issues/74
*/
private function getException(TestFailure $error): Exception
{
$exception = $error->thrownException();
if ($exception instanceof __PHP_Incomplete_Class) {
$exceptionArray = [];
foreach ((array) $exception as $key => $value) {
$key = substr($key, strrpos($key, "\0") + 1);
$exceptionArray[$key] = $value;
}
$exception = new SyntheticError(
sprintf(
'%s: %s',
$exceptionArray['_PHP_Incomplete_Class_Name'],
$exceptionArray['message']
),
$exceptionArray['code'],
$exceptionArray['file'],
$exceptionArray['line'],
$exceptionArray['trace']
);
}
return $exception;
}
}
PK %Z+U `
`
/ phpunit/src/Util/PHP/Template/TestCaseClass.tplnu [ {driverMethod}($filter),
$filter
);
if ({cachesStaticAnalysis}) {
$codeCoverage->cacheStaticAnalysis(unserialize('{codeCoverageCacheDirectory}'));
}
$result->setCodeCoverage($codeCoverage);
}
$result->beStrictAboutTestsThatDoNotTestAnything({isStrictAboutTestsThatDoNotTestAnything});
$result->beStrictAboutOutputDuringTests({isStrictAboutOutputDuringTests});
$result->enforceTimeLimit({enforcesTimeLimit});
$result->beStrictAboutTodoAnnotatedTests({isStrictAboutTodoAnnotatedTests});
$result->beStrictAboutResourceUsageDuringSmallTests({isStrictAboutResourceUsageDuringSmallTests});
$test = new {className}('{name}', unserialize('{data}'), '{dataName}');
$test->setDependencyInput(unserialize('{dependencyInput}'));
$test->setInIsolation(TRUE);
ob_end_clean();
$test->run($result);
$output = '';
if (!$test->hasExpectationOnOutput()) {
$output = $test->getActualOutput();
}
ini_set('xdebug.scream', '0');
@rewind(STDOUT); /* @ as not every STDOUT target stream is rewindable */
if ($stdout = @stream_get_contents(STDOUT)) {
$output = $stdout . $output;
$streamMetaData = stream_get_meta_data(STDOUT);
if (!empty($streamMetaData['stream_type']) && 'STDIO' === $streamMetaData['stream_type']) {
@ftruncate(STDOUT, 0);
@rewind(STDOUT);
}
}
print serialize(
[
'testResult' => $test->getResult(),
'numAssertions' => $test->getNumAssertions(),
'result' => $result,
'output' => $output
]
);
}
$configurationFilePath = '{configurationFilePath}';
if ('' !== $configurationFilePath) {
$configuration = (new Loader)->load($configurationFilePath);
(new PhpHandler)->handle($configuration->php());
unset($configuration);
}
function __phpunit_error_handler($errno, $errstr, $errfile, $errline)
{
return true;
}
set_error_handler('__phpunit_error_handler');
{constants}
{included_files}
{globals}
restore_error_handler();
if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
require_once $GLOBALS['__PHPUNIT_BOOTSTRAP'];
unset($GLOBALS['__PHPUNIT_BOOTSTRAP']);
}
__phpunit_run_isolated_test();
PK %Zh" . phpunit/src/Util/PHP/Template/PhptTestCase.tplnu [ {driverMethod}($filter),
$filter
);
if ({codeCoverageCacheDirectory}) {
$coverage->cacheStaticAnalysis({codeCoverageCacheDirectory});
}
$coverage->start(__FILE__);
}
register_shutdown_function(
function() use ($coverage) {
$output = null;
if ($coverage) {
$output = $coverage->stop();
}
file_put_contents('{coverageFile}', serialize($output));
}
);
ob_end_clean();
require '{job}';
PK %Zw^ȯ
0 phpunit/src/Util/PHP/Template/TestCaseMethod.tplnu [ {driverMethod}($filter),
$filter
);
if ({cachesStaticAnalysis}) {
$codeCoverage->cacheStaticAnalysis(unserialize('{codeCoverageCacheDirectory}'));
}
$result->setCodeCoverage($codeCoverage);
}
$result->beStrictAboutTestsThatDoNotTestAnything({isStrictAboutTestsThatDoNotTestAnything});
$result->beStrictAboutOutputDuringTests({isStrictAboutOutputDuringTests});
$result->enforceTimeLimit({enforcesTimeLimit});
$result->beStrictAboutTodoAnnotatedTests({isStrictAboutTodoAnnotatedTests});
$result->beStrictAboutResourceUsageDuringSmallTests({isStrictAboutResourceUsageDuringSmallTests});
$test = new {className}('{methodName}', unserialize('{data}'), '{dataName}');
\assert($test instanceof TestCase);
$test->setDependencyInput(unserialize('{dependencyInput}'));
$test->setInIsolation(true);
ob_end_clean();
$test->run($result);
$output = '';
if (!$test->hasExpectationOnOutput()) {
$output = $test->getActualOutput();
}
ini_set('xdebug.scream', '0');
@rewind(STDOUT); /* @ as not every STDOUT target stream is rewindable */
if ($stdout = @stream_get_contents(STDOUT)) {
$output = $stdout . $output;
$streamMetaData = stream_get_meta_data(STDOUT);
if (!empty($streamMetaData['stream_type']) && 'STDIO' === $streamMetaData['stream_type']) {
@ftruncate(STDOUT, 0);
@rewind(STDOUT);
}
}
print serialize(
[
'testResult' => $test->getResult(),
'numAssertions' => $test->getNumAssertions(),
'result' => $result,
'output' => $output
]
);
}
$configurationFilePath = '{configurationFilePath}';
if ('' !== $configurationFilePath) {
$configuration = (new Loader)->load($configurationFilePath);
(new PhpHandler)->handle($configuration->php());
unset($configuration);
}
function __phpunit_error_handler($errno, $errstr, $errfile, $errline)
{
return true;
}
set_error_handler('__phpunit_error_handler');
{constants}
{included_files}
{globals}
restore_error_handler();
if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) {
require_once $GLOBALS['__PHPUNIT_BOOTSTRAP'];
unset($GLOBALS['__PHPUNIT_BOOTSTRAP']);
}
__phpunit_run_isolated_test();
PK %Z4/
( phpunit/src/Util/XmlTestListRenderer.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use function get_class;
use function implode;
use function str_replace;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Runner\PhptTestCase;
use RecursiveIteratorIterator;
use XMLWriter;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class XmlTestListRenderer
{
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function render(TestSuite $suite): string
{
$writer = new XMLWriter;
$writer->openMemory();
$writer->setIndent(true);
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement('tests');
$currentTestCase = null;
foreach (new RecursiveIteratorIterator($suite->getIterator()) as $test) {
if ($test instanceof TestCase) {
if (get_class($test) !== $currentTestCase) {
if ($currentTestCase !== null) {
$writer->endElement();
}
$writer->startElement('testCaseClass');
$writer->writeAttribute('name', get_class($test));
$currentTestCase = get_class($test);
}
$writer->startElement('testCaseMethod');
$writer->writeAttribute('name', $test->getName(false));
$writer->writeAttribute('groups', implode(',', $test->getGroups()));
if (!empty($test->getDataSetAsString(false))) {
$writer->writeAttribute(
'dataSet',
str_replace(
' with data set ',
'',
$test->getDataSetAsString(false)
)
);
}
$writer->endElement();
} elseif ($test instanceof PhptTestCase) {
if ($currentTestCase !== null) {
$writer->endElement();
$currentTestCase = null;
}
$writer->startElement('phptFile');
$writer->writeAttribute('path', $test->getName());
$writer->endElement();
}
}
if ($currentTestCase !== null) {
$writer->endElement();
}
$writer->endElement();
$writer->endDocument();
return $writer->outputMemory();
}
}
PK %ZCԓ phpunit/src/Util/Xml.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const ENT_QUOTES;
use function assert;
use function class_exists;
use function htmlspecialchars;
use function mb_convert_encoding;
use function ord;
use function preg_replace;
use function settype;
use function strlen;
use DOMCharacterData;
use DOMDocument;
use DOMElement;
use DOMNode;
use DOMText;
use ReflectionClass;
use ReflectionException;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Xml
{
/**
* @deprecated Only used by assertEqualXMLStructure()
*/
public static function import(DOMElement $element): DOMElement
{
return (new DOMDocument)->importNode($element, true);
}
/**
* @deprecated Only used by assertEqualXMLStructure()
*/
public static function removeCharacterDataNodes(DOMNode $node): void
{
if ($node->hasChildNodes()) {
for ($i = $node->childNodes->length - 1; $i >= 0; $i--) {
if (($child = $node->childNodes->item($i)) instanceof DOMCharacterData) {
$node->removeChild($child);
}
}
}
}
/**
* Escapes a string for the use in XML documents.
*
* Any Unicode character is allowed, excluding the surrogate blocks, FFFE,
* and FFFF (not even as character reference).
*
* @see https://www.w3.org/TR/xml/#charsets
*/
public static function prepareString(string $string): string
{
return preg_replace(
'/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/',
'',
htmlspecialchars(
self::convertToUtf8($string),
ENT_QUOTES
)
);
}
/**
* "Convert" a DOMElement object into a PHP variable.
*/
public static function xmlToVariable(DOMElement $element)
{
$variable = null;
switch ($element->tagName) {
case 'array':
$variable = [];
foreach ($element->childNodes as $entry) {
if (!$entry instanceof DOMElement || $entry->tagName !== 'element') {
continue;
}
$item = $entry->childNodes->item(0);
if ($item instanceof DOMText) {
$item = $entry->childNodes->item(1);
}
$value = self::xmlToVariable($item);
if ($entry->hasAttribute('key')) {
$variable[(string) $entry->getAttribute('key')] = $value;
} else {
$variable[] = $value;
}
}
break;
case 'object':
$className = $element->getAttribute('class');
if ($element->hasChildNodes()) {
$arguments = $element->childNodes->item(0)->childNodes;
$constructorArgs = [];
foreach ($arguments as $argument) {
if ($argument instanceof DOMElement) {
$constructorArgs[] = self::xmlToVariable($argument);
}
}
try {
assert(class_exists($className));
$variable = (new ReflectionClass($className))->newInstanceArgs($constructorArgs);
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
} else {
$variable = new $className;
}
break;
case 'boolean':
$variable = $element->textContent === 'true';
break;
case 'integer':
case 'double':
case 'string':
$variable = $element->textContent;
settype($variable, $element->tagName);
break;
}
return $variable;
}
private static function convertToUtf8(string $string): string
{
if (!self::isUtf8($string)) {
$string = mb_convert_encoding($string, 'UTF-8');
}
return $string;
}
private static function isUtf8(string $string): bool
{
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
if (ord($string[$i]) < 0x80) {
$n = 0;
} elseif ((ord($string[$i]) & 0xE0) === 0xC0) {
$n = 1;
} elseif ((ord($string[$i]) & 0xF0) === 0xE0) {
$n = 2;
} elseif ((ord($string[$i]) & 0xF0) === 0xF0) {
$n = 3;
} else {
return false;
}
for ($j = 0; $j < $n; $j++) {
if ((++$i === $length) || ((ord($string[$i]) & 0xC0) !== 0x80)) {
return false;
}
}
}
return true;
}
}
PK %Z/k- - phpunit/src/Util/Filesystem.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const DIRECTORY_SEPARATOR;
use function is_dir;
use function mkdir;
use function str_replace;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Filesystem
{
/**
* Maps class names to source file names.
*
* - PEAR CS: Foo_Bar_Baz -> Foo/Bar/Baz.php
* - Namespace: Foo\Bar\Baz -> Foo/Bar/Baz.php
*/
public static function classNameToFilename(string $className): string
{
return str_replace(
['_', '\\'],
DIRECTORY_SEPARATOR,
$className
) . '.php';
}
public static function createDirectory(string $directory): bool
{
return !(!is_dir($directory) && !@mkdir($directory, 0777, true) && !is_dir($directory));
}
}
PK %ZtqHH phpunit/src/Util/Color.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const DIRECTORY_SEPARATOR;
use function array_keys;
use function array_map;
use function array_values;
use function count;
use function explode;
use function implode;
use function min;
use function preg_replace;
use function preg_replace_callback;
use function sprintf;
use function strtr;
use function trim;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Color
{
/**
* @var array
*/
private const WHITESPACE_MAP = [
' ' => '·',
"\t" => '⇥',
];
/**
* @var array
*/
private const WHITESPACE_EOL_MAP = [
' ' => '·',
"\t" => '⇥',
"\n" => '↵',
"\r" => '⟵',
];
/**
* @var array
*/
private static $ansiCodes = [
'reset' => '0',
'bold' => '1',
'dim' => '2',
'dim-reset' => '22',
'underlined' => '4',
'fg-default' => '39',
'fg-black' => '30',
'fg-red' => '31',
'fg-green' => '32',
'fg-yellow' => '33',
'fg-blue' => '34',
'fg-magenta' => '35',
'fg-cyan' => '36',
'fg-white' => '37',
'bg-default' => '49',
'bg-black' => '40',
'bg-red' => '41',
'bg-green' => '42',
'bg-yellow' => '43',
'bg-blue' => '44',
'bg-magenta' => '45',
'bg-cyan' => '46',
'bg-white' => '47',
];
public static function colorize(string $color, string $buffer): string
{
if (trim($buffer) === '') {
return $buffer;
}
$codes = array_map('\trim', explode(',', $color));
$styles = [];
foreach ($codes as $code) {
if (isset(self::$ansiCodes[$code])) {
$styles[] = self::$ansiCodes[$code] ?? '';
}
}
if (empty($styles)) {
return $buffer;
}
return self::optimizeColor(sprintf("\x1b[%sm", implode(';', $styles)) . $buffer . "\x1b[0m");
}
public static function colorizePath(string $path, ?string $prevPath = null, bool $colorizeFilename = false): string
{
if ($prevPath === null) {
$prevPath = '';
}
$path = explode(DIRECTORY_SEPARATOR, $path);
$prevPath = explode(DIRECTORY_SEPARATOR, $prevPath);
for ($i = 0; $i < min(count($path), count($prevPath)); $i++) {
if ($path[$i] == $prevPath[$i]) {
$path[$i] = self::dim($path[$i]);
}
}
if ($colorizeFilename) {
$last = count($path) - 1;
$path[$last] = preg_replace_callback(
'/([\-_\.]+|phpt$)/',
static function ($matches)
{
return self::dim($matches[0]);
},
$path[$last]
);
}
return self::optimizeColor(implode(self::dim(DIRECTORY_SEPARATOR), $path));
}
public static function dim(string $buffer): string
{
if (trim($buffer) === '') {
return $buffer;
}
return "\e[2m{$buffer}\e[22m";
}
public static function visualizeWhitespace(string $buffer, bool $visualizeEOL = false): string
{
$replaceMap = $visualizeEOL ? self::WHITESPACE_EOL_MAP : self::WHITESPACE_MAP;
return preg_replace_callback('/\s+/', static function ($matches) use ($replaceMap)
{
return self::dim(strtr($matches[0], $replaceMap));
}, $buffer);
}
private static function optimizeColor(string $buffer): string
{
$patterns = [
"/\e\\[22m\e\\[2m/" => '',
"/\e\\[([^m]*)m\e\\[([1-9][0-9;]*)m/" => "\e[$1;$2m",
"/(\e\\[[^m]*m)+(\e\\[0m)/" => '$2',
];
return preg_replace(array_keys($patterns), array_values($patterns), $buffer);
}
}
PK %ZͼQ ' phpunit/src/Util/Xml/SchemaDetector.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class SchemaDetector
{
/**
* @throws Exception
*/
public function detect(string $filename): SchemaDetectionResult
{
$document = (new Loader)->loadFile(
$filename,
false,
true,
true
);
foreach (['9.2', '8.5'] as $candidate) {
$schema = (new SchemaFinder)->find($candidate);
if (!(new Validator)->validate($document, $schema)->hasValidationErrors()) {
return new SuccessfulSchemaDetectionResult($candidate);
}
}
return new FailedSchemaDetectionResult;
}
}
PK %Z 4 phpunit/src/Util/Xml/FailedSchemaDetectionResult.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @psalm-immutable
*/
final class FailedSchemaDetectionResult extends SchemaDetectionResult
{
}
PK %Z{G G ) phpunit/src/Util/Xml/SnapshotNodeList.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
use function count;
use ArrayIterator;
use Countable;
use DOMNode;
use DOMNodeList;
use IteratorAggregate;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @template-implements IteratorAggregate
*/
final class SnapshotNodeList implements Countable, IteratorAggregate
{
/**
* @var DOMNode[]
*/
private $nodes = [];
public static function fromNodeList(DOMNodeList $list): self
{
$snapshot = new self;
foreach ($list as $node) {
$snapshot->nodes[] = $node;
}
return $snapshot;
}
public function count(): int
{
return count($this->nodes);
}
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->nodes);
}
}
PK %Z2)cΟ . phpunit/src/Util/Xml/SchemaDetectionResult.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @psalm-immutable
*/
abstract class SchemaDetectionResult
{
public function detected(): bool
{
return false;
}
/**
* @throws Exception
*/
public function version(): string
{
throw new Exception('No supported schema was detected');
}
}
PK %ZWY " phpunit/src/Util/Xml/Validator.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
use function file_get_contents;
use function libxml_clear_errors;
use function libxml_get_errors;
use function libxml_use_internal_errors;
use DOMDocument;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Validator
{
public function validate(DOMDocument $document, string $xsdFilename): ValidationResult
{
$originalErrorHandling = libxml_use_internal_errors(true);
$document->schemaValidateSource(file_get_contents($xsdFilename));
$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors($originalErrorHandling);
return ValidationResult::fromArray($errors);
}
}
PK %ZG % phpunit/src/Util/Xml/SchemaFinder.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
use function defined;
use function is_file;
use function sprintf;
use PHPUnit\Runner\Version;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class SchemaFinder
{
/**
* @throws Exception
*/
public function find(string $version): string
{
if ($version === Version::series()) {
$filename = $this->path() . 'phpunit.xsd';
} else {
$filename = $this->path() . 'schema/' . $version . '.xsd';
}
if (!is_file($filename)) {
throw new Exception(
sprintf(
'Schema for PHPUnit %s is not available',
$version
)
);
}
return $filename;
}
private function path(): string
{
if (defined('__PHPUNIT_PHAR_ROOT__')) {
return __PHPUNIT_PHAR_ROOT__ . '/';
}
return __DIR__ . '/../../../';
}
}
PK %Zui 8 phpunit/src/Util/Xml/SuccessfulSchemaDetectionResult.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @psalm-immutable
*/
final class SuccessfulSchemaDetectionResult extends SchemaDetectionResult
{
/**
* @var string
*/
private $version;
public function __construct(string $version)
{
$this->version = $version;
}
public function detected(): bool
{
return true;
}
public function version(): string
{
return $this->version;
}
}
PK %Zϸ8 ) phpunit/src/Util/Xml/ValidationResult.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
use function sprintf;
use function trim;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @psalm-immutable
*/
final class ValidationResult
{
/**
* @psalm-var array>
*/
private $validationErrors = [];
/**
* @psalm-param array $errors
*/
public static function fromArray(array $errors): self
{
$validationErrors = [];
foreach ($errors as $error) {
if (!isset($validationErrors[$error->line])) {
$validationErrors[$error->line] = [];
}
$validationErrors[$error->line][] = trim($error->message);
}
return new self($validationErrors);
}
private function __construct(array $validationErrors)
{
$this->validationErrors = $validationErrors;
}
public function hasValidationErrors(): bool
{
return !empty($this->validationErrors);
}
public function asString(): string
{
$buffer = '';
foreach ($this->validationErrors as $line => $validationErrorsOnLine) {
$buffer .= sprintf(PHP_EOL . ' Line %d:' . PHP_EOL, $line);
foreach ($validationErrorsOnLine as $validationError) {
$buffer .= sprintf(' - %s' . PHP_EOL, $validationError);
}
}
return $buffer;
}
}
PK %Z. " phpunit/src/Util/Xml/Exception.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
use RuntimeException;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Exception extends RuntimeException implements \PHPUnit\Exception
{
}
PK %ZOb4 4 phpunit/src/Util/Xml/Loader.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Xml;
use function chdir;
use function dirname;
use function error_reporting;
use function file_get_contents;
use function getcwd;
use function libxml_get_errors;
use function libxml_use_internal_errors;
use function sprintf;
use DOMDocument;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Loader
{
/**
* @throws Exception
*/
public function loadFile(string $filename, bool $isHtml = false, bool $xinclude = false, bool $strict = false): DOMDocument
{
$reporting = error_reporting(0);
$contents = file_get_contents($filename);
error_reporting($reporting);
if ($contents === false) {
throw new Exception(
sprintf(
'Could not read "%s".',
$filename
)
);
}
return $this->load($contents, $isHtml, $filename, $xinclude, $strict);
}
/**
* @throws Exception
*/
public function load(string $actual, bool $isHtml = false, string $filename = '', bool $xinclude = false, bool $strict = false): DOMDocument
{
if ($actual === '') {
throw new Exception('Could not load XML from empty string');
}
// Required for XInclude on Windows.
if ($xinclude) {
$cwd = getcwd();
@chdir(dirname($filename));
}
$document = new DOMDocument;
$document->preserveWhiteSpace = false;
$internal = libxml_use_internal_errors(true);
$message = '';
$reporting = error_reporting(0);
if ($filename !== '') {
// Required for XInclude
$document->documentURI = $filename;
}
if ($isHtml) {
$loaded = $document->loadHTML($actual);
} else {
$loaded = $document->loadXML($actual);
}
if (!$isHtml && $xinclude) {
$document->xinclude();
}
foreach (libxml_get_errors() as $error) {
$message .= "\n" . $error->message;
}
libxml_use_internal_errors($internal);
error_reporting($reporting);
if (isset($cwd)) {
@chdir($cwd);
}
if ($loaded === false || ($strict && $message !== '')) {
if ($filename !== '') {
throw new Exception(
sprintf(
'Could not load "%s".%s',
$filename,
$message !== '' ? "\n" . $message : ''
)
);
}
if ($message === '') {
$message = 'Could not load XML for unknown reason';
}
throw new Exception($message);
}
return $document;
}
}
PK %ZX , phpunit/src/Util/InvalidDataSetException.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use RuntimeException;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class InvalidDataSetException extends RuntimeException implements \PHPUnit\Exception
{
}
PK %Zq phpunit/src/Util/Type.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Type
{
public static function isType(string $type): bool
{
switch ($type) {
case 'numeric':
case 'integer':
case 'int':
case 'iterable':
case 'float':
case 'string':
case 'boolean':
case 'bool':
case 'null':
case 'array':
case 'object':
case 'resource':
case 'scalar':
return true;
default:
return false;
}
}
}
PK %Z' phpunit/src/Util/ExcludeList.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const DIRECTORY_SEPARATOR;
use function class_exists;
use function defined;
use function dirname;
use function is_dir;
use function realpath;
use function sprintf;
use function strpos;
use function sys_get_temp_dir;
use Composer\Autoload\ClassLoader;
use DeepCopy\DeepCopy;
use Doctrine\Instantiator\Instantiator;
use PharIo\Manifest\Manifest;
use PharIo\Version\Version as PharIoVersion;
use PhpParser\Parser;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use SebastianBergmann\CliParser\Parser as CliParser;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeUnit\CodeUnit;
use SebastianBergmann\CodeUnitReverseLookup\Wizard;
use SebastianBergmann\Comparator\Comparator;
use SebastianBergmann\Complexity\Calculator;
use SebastianBergmann\Diff\Diff;
use SebastianBergmann\Environment\Runtime;
use SebastianBergmann\Exporter\Exporter;
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;
use SebastianBergmann\GlobalState\Snapshot;
use SebastianBergmann\Invoker\Invoker;
use SebastianBergmann\LinesOfCode\Counter;
use SebastianBergmann\ObjectEnumerator\Enumerator;
use SebastianBergmann\RecursionContext\Context;
use SebastianBergmann\ResourceOperations\ResourceOperations;
use SebastianBergmann\Template\Template;
use SebastianBergmann\Timer\Timer;
use SebastianBergmann\Type\TypeName;
use SebastianBergmann\Version;
use TheSeer\Tokenizer\Tokenizer;
/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
final class ExcludeList
{
/**
* @var array
*/
private const EXCLUDED_CLASS_NAMES = [
// composer
ClassLoader::class => 1,
// doctrine/instantiator
Instantiator::class => 1,
// myclabs/deepcopy
DeepCopy::class => 1,
// nikic/php-parser
Parser::class => 1,
// phar-io/manifest
Manifest::class => 1,
// phar-io/version
PharIoVersion::class => 1,
// phpdocumentor/type-resolver
Type::class => 1,
// phpunit/phpunit
TestCase::class => 2,
// phpunit/php-code-coverage
CodeCoverage::class => 1,
// phpunit/php-file-iterator
FileIteratorFacade::class => 1,
// phpunit/php-invoker
Invoker::class => 1,
// phpunit/php-text-template
Template::class => 1,
// phpunit/php-timer
Timer::class => 1,
// sebastian/cli-parser
CliParser::class => 1,
// sebastian/code-unit
CodeUnit::class => 1,
// sebastian/code-unit-reverse-lookup
Wizard::class => 1,
// sebastian/comparator
Comparator::class => 1,
// sebastian/complexity
Calculator::class => 1,
// sebastian/diff
Diff::class => 1,
// sebastian/environment
Runtime::class => 1,
// sebastian/exporter
Exporter::class => 1,
// sebastian/global-state
Snapshot::class => 1,
// sebastian/lines-of-code
Counter::class => 1,
// sebastian/object-enumerator
Enumerator::class => 1,
// sebastian/recursion-context
Context::class => 1,
// sebastian/resource-operations
ResourceOperations::class => 1,
// sebastian/type
TypeName::class => 1,
// sebastian/version
Version::class => 1,
// theseer/tokenizer
Tokenizer::class => 1,
];
/**
* @var string[]
*/
private static $directories = [];
/**
* @var bool
*/
private static $initialized = false;
public static function addDirectory(string $directory): void
{
if (!is_dir($directory)) {
throw new Exception(
sprintf(
'"%s" is not a directory',
$directory
)
);
}
self::$directories[] = realpath($directory);
}
/**
* @throws Exception
*
* @return string[]
*/
public function getExcludedDirectories(): array
{
$this->initialize();
return self::$directories;
}
/**
* @throws Exception
*/
public function isExcluded(string $file): bool
{
if (defined('PHPUNIT_TESTSUITE')) {
return false;
}
$this->initialize();
foreach (self::$directories as $directory) {
if (strpos($file, $directory) === 0) {
return true;
}
}
return false;
}
/**
* @throws Exception
*/
private function initialize(): void
{
if (self::$initialized) {
return;
}
foreach (self::EXCLUDED_CLASS_NAMES as $className => $parent) {
if (!class_exists($className)) {
continue;
}
$directory = (new ReflectionClass($className))->getFileName();
for ($i = 0; $i < $parent; $i++) {
$directory = dirname($directory);
}
self::$directories[] = $directory;
}
// Hide process isolation workaround on Windows.
if (DIRECTORY_SEPARATOR === '\\') {
// tempnam() prefix is limited to first 3 chars.
// @see https://php.net/manual/en/function.tempnam.php
self::$directories[] = sys_get_temp_dir() . '\\PHP';
}
self::$initialized = true;
}
}
PK %Z phpunit/src/Util/Blacklist.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
/**
* @deprecated Use ExcludeList instead
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
final class Blacklist
{
public static function addDirectory(string $directory): void
{
ExcludeList::addDirectory($directory);
}
/**
* @throws Exception
*
* @return string[]
*/
public function getBlacklistedDirectories(): array
{
return (new ExcludeList)->getExcludedDirectories();
}
/**
* @throws Exception
*/
public function isBlacklisted(string $file): bool
{
return (new ExcludeList)->isExcluded($file);
}
}
PK %Z3\!% % 0 phpunit/src/Util/XdebugFilterScriptGenerator.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const DIRECTORY_SEPARATOR;
use function addslashes;
use function array_map;
use function implode;
use function is_string;
use function realpath;
use function sprintf;
use PHPUnit\TextUI\XmlConfiguration\CodeCoverage\CodeCoverage as FilterConfiguration;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @deprecated
*/
final class XdebugFilterScriptGenerator
{
public function generate(FilterConfiguration $filter): string
{
$files = array_map(
static function ($item)
{
return sprintf(
" '%s'",
$item
);
},
$this->getItems($filter)
);
$files = implode(",\n", $files);
return <<directories() as $directory) {
$path = realpath($directory->path());
if (is_string($path)) {
$files[] = sprintf(
addslashes('%s' . DIRECTORY_SEPARATOR),
$path
);
}
}
foreach ($filter->files() as $file) {
$files[] = $file->path();
}
return $files;
}
}
PK %Z\Y phpunit/src/Util/Cloner.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use Throwable;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Cloner
{
/**
* @psalm-template OriginalType
*
* @psalm-param OriginalType $original
*
* @psalm-return OriginalType
*/
public static function clone(object $original): object
{
try {
return clone $original;
} catch (Throwable $t) {
return $original;
}
}
}
PK %Z ͳ ) phpunit/src/Util/TextTestListRenderer.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const PHP_EOL;
use function get_class;
use function sprintf;
use function str_replace;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Runner\PhptTestCase;
use RecursiveIteratorIterator;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class TextTestListRenderer
{
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function render(TestSuite $suite): string
{
$buffer = 'Available test(s):' . PHP_EOL;
foreach (new RecursiveIteratorIterator($suite->getIterator()) as $test) {
if ($test instanceof TestCase) {
$name = sprintf(
'%s::%s',
get_class($test),
str_replace(' with data set ', '', $test->getName())
);
} elseif ($test instanceof PhptTestCase) {
$name = $test->getName();
} else {
continue;
}
$buffer .= sprintf(
' - %s' . PHP_EOL,
$name
);
}
return $buffer;
}
}
PK %ZTsh
h
( phpunit/src/Util/Annotation/Registry.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Annotation;
use function array_key_exists;
use PHPUnit\Util\Exception;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
/**
* Reflection information, and therefore DocBlock information, is static within
* a single PHP process. It is therefore okay to use a Singleton registry here.
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Registry
{
/** @var null|self */
private static $instance;
/** @var array indexed by class name */
private $classDocBlocks = [];
/** @var array> indexed by class name and method name */
private $methodDocBlocks = [];
public static function getInstance(): self
{
return self::$instance ?? self::$instance = new self;
}
private function __construct()
{
}
/**
* @throws Exception
*
* @psalm-param class-string $class
*/
public function forClassName(string $class): DocBlock
{
if (array_key_exists($class, $this->classDocBlocks)) {
return $this->classDocBlocks[$class];
}
try {
$reflection = new ReflectionClass($class);
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
return $this->classDocBlocks[$class] = DocBlock::ofClass($reflection);
}
/**
* @throws Exception
*
* @psalm-param class-string $classInHierarchy
*/
public function forMethod(string $classInHierarchy, string $method): DocBlock
{
if (isset($this->methodDocBlocks[$classInHierarchy][$method])) {
return $this->methodDocBlocks[$classInHierarchy][$method];
}
try {
$reflection = new ReflectionMethod($classInHierarchy, $method);
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
return $this->methodDocBlocks[$classInHierarchy][$method] = DocBlock::ofMethod($reflection, $classInHierarchy);
}
}
PK %ZS
NF F ( phpunit/src/Util/Annotation/DocBlock.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\Annotation;
use const JSON_ERROR_NONE;
use const PREG_OFFSET_CAPTURE;
use function array_filter;
use function array_key_exists;
use function array_map;
use function array_merge;
use function array_pop;
use function array_slice;
use function array_values;
use function count;
use function explode;
use function file;
use function implode;
use function is_array;
use function is_int;
use function json_decode;
use function json_last_error;
use function json_last_error_msg;
use function preg_match;
use function preg_match_all;
use function preg_replace;
use function preg_split;
use function realpath;
use function rtrim;
use function sprintf;
use function str_replace;
use function strlen;
use function strpos;
use function strtolower;
use function substr;
use function trim;
use PharIo\Version\VersionConstraintParser;
use PHPUnit\Framework\InvalidDataProviderException;
use PHPUnit\Framework\SkippedTestError;
use PHPUnit\Framework\Warning;
use PHPUnit\Util\Exception;
use PHPUnit\Util\InvalidDataSetException;
use ReflectionClass;
use ReflectionException;
use ReflectionFunctionAbstract;
use ReflectionMethod;
use Reflector;
use Traversable;
/**
* This is an abstraction around a PHPUnit-specific docBlock,
* allowing us to ask meaningful questions about a specific
* reflection symbol.
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class DocBlock
{
/**
* @todo This constant should be private (it's public because of TestTest::testGetProvidedDataRegEx)
*/
public const REGEX_DATA_PROVIDER = '/@dataProvider\s+([a-zA-Z0-9._:-\\\\x7f-\xff]+)/';
private const REGEX_REQUIRES_VERSION = '/@requires\s+(?PPHP(?:Unit)?)\s+(?P[<>=!]{0,2})\s*(?P[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m';
private const REGEX_REQUIRES_VERSION_CONSTRAINT = '/@requires\s+(?PPHP(?:Unit)?)\s+(?P[\d\t \-.|~^]+)[ \t]*\r?$/m';
private const REGEX_REQUIRES_OS = '/@requires\s+(?POS(?:FAMILY)?)\s+(?P.+?)[ \t]*\r?$/m';
private const REGEX_REQUIRES_SETTING = '/@requires\s+(?Psetting)\s+(?P([^ ]+?))\s*(?P[\w\.-]+[\w\.]?)?[ \t]*\r?$/m';
private const REGEX_REQUIRES = '/@requires\s+(?Pfunction|extension)\s+(?P([^\s<>=!]+))\s*(?P[<>=!]{0,2})\s*(?P[\d\.-]+[\d\.]?)?[ \t]*\r?$/m';
private const REGEX_TEST_WITH = '/@testWith\s+/';
/** @var string */
private $docComment;
/** @var bool */
private $isMethod;
/** @var array> pre-parsed annotations indexed by name and occurrence index */
private $symbolAnnotations;
/**
* @var null|array
*
* @psalm-var null|(array{
* __OFFSET: array&array{__FILE: string},
* setting?: array,
* extension_versions?: array
* }&array<
* string,
* string|array{version: string, operator: string}|array{constraint: string}|array
* >)
*/
private $parsedRequirements;
/** @var int */
private $startLine;
/** @var int */
private $endLine;
/** @var string */
private $fileName;
/** @var string */
private $name;
/**
* @var string
*
* @psalm-var class-string
*/
private $className;
public static function ofClass(ReflectionClass $class): self
{
$className = $class->getName();
return new self(
(string) $class->getDocComment(),
false,
self::extractAnnotationsFromReflector($class),
$class->getStartLine(),
$class->getEndLine(),
$class->getFileName(),
$className,
$className
);
}
/**
* @psalm-param class-string $classNameInHierarchy
*/
public static function ofMethod(ReflectionMethod $method, string $classNameInHierarchy): self
{
return new self(
(string) $method->getDocComment(),
true,
self::extractAnnotationsFromReflector($method),
$method->getStartLine(),
$method->getEndLine(),
$method->getFileName(),
$method->getName(),
$classNameInHierarchy
);
}
/**
* Note: we do not preserve an instance of the reflection object, since it cannot be safely (de-)serialized.
*
* @param array> $symbolAnnotations
*
* @psalm-param class-string $className
*/
private function __construct(string $docComment, bool $isMethod, array $symbolAnnotations, int $startLine, int $endLine, string $fileName, string $name, string $className)
{
$this->docComment = $docComment;
$this->isMethod = $isMethod;
$this->symbolAnnotations = $symbolAnnotations;
$this->startLine = $startLine;
$this->endLine = $endLine;
$this->fileName = $fileName;
$this->name = $name;
$this->className = $className;
}
/**
* @psalm-return array{
* __OFFSET: array&array{__FILE: string},
* setting?: array,
* extension_versions?: array
* }&array<
* string,
* string|array{version: string, operator: string}|array{constraint: string}|array
* >
*
* @throws Warning if the requirements version constraint is not well-formed
*/
public function requirements(): array
{
if ($this->parsedRequirements !== null) {
return $this->parsedRequirements;
}
$offset = $this->startLine;
$requires = [];
$recordedSettings = [];
$extensionVersions = [];
$recordedOffsets = [
'__FILE' => realpath($this->fileName),
];
// Trim docblock markers, split it into lines and rewind offset to start of docblock
$lines = preg_replace(['#^/\*{2}#', '#\*/$#'], '', preg_split('/\r\n|\r|\n/', $this->docComment));
$offset -= count($lines);
foreach ($lines as $line) {
if (preg_match(self::REGEX_REQUIRES_OS, $line, $matches)) {
$requires[$matches['name']] = $matches['value'];
$recordedOffsets[$matches['name']] = $offset;
}
if (preg_match(self::REGEX_REQUIRES_VERSION, $line, $matches)) {
$requires[$matches['name']] = [
'version' => $matches['version'],
'operator' => $matches['operator'],
];
$recordedOffsets[$matches['name']] = $offset;
}
if (preg_match(self::REGEX_REQUIRES_VERSION_CONSTRAINT, $line, $matches)) {
if (!empty($requires[$matches['name']])) {
$offset++;
continue;
}
try {
$versionConstraintParser = new VersionConstraintParser;
$requires[$matches['name'] . '_constraint'] = [
'constraint' => $versionConstraintParser->parse(trim($matches['constraint'])),
];
$recordedOffsets[$matches['name'] . '_constraint'] = $offset;
} catch (\PharIo\Version\Exception $e) {
throw new Warning($e->getMessage(), $e->getCode(), $e);
}
}
if (preg_match(self::REGEX_REQUIRES_SETTING, $line, $matches)) {
$recordedSettings[$matches['setting']] = $matches['value'];
$recordedOffsets['__SETTING_' . $matches['setting']] = $offset;
}
if (preg_match(self::REGEX_REQUIRES, $line, $matches)) {
$name = $matches['name'] . 's';
if (!isset($requires[$name])) {
$requires[$name] = [];
}
$requires[$name][] = $matches['value'];
$recordedOffsets[$matches['name'] . '_' . $matches['value']] = $offset;
if ($name === 'extensions' && !empty($matches['version'])) {
$extensionVersions[$matches['value']] = [
'version' => $matches['version'],
'operator' => $matches['operator'],
];
}
}
$offset++;
}
return $this->parsedRequirements = array_merge(
$requires,
['__OFFSET' => $recordedOffsets],
array_filter([
'setting' => $recordedSettings,
'extension_versions' => $extensionVersions,
])
);
}
/**
* Returns the provided data for a method.
*
* @throws Exception
*/
public function getProvidedData(): ?array
{
/** @noinspection SuspiciousBinaryOperationInspection */
$data = $this->getDataFromDataProviderAnnotation($this->docComment) ?? $this->getDataFromTestWithAnnotation($this->docComment);
if ($data === null) {
return null;
}
if ($data === []) {
throw new SkippedTestError;
}
foreach ($data as $key => $value) {
if (!is_array($value)) {
throw new InvalidDataSetException(
sprintf(
'Data set %s is invalid.',
is_int($key) ? '#' . $key : '"' . $key . '"'
)
);
}
}
return $data;
}
/**
* @psalm-return array
*/
public function getInlineAnnotations(): array
{
$code = file($this->fileName);
$lineNumber = $this->startLine;
$startLine = $this->startLine - 1;
$endLine = $this->endLine - 1;
$codeLines = array_slice($code, $startLine, $endLine - $startLine + 1);
$annotations = [];
foreach ($codeLines as $line) {
if (preg_match('#/\*\*?\s*@(?P[A-Za-z_-]+)(?:[ \t]+(?P.*?))?[ \t]*\r?\*/$#m', $line, $matches)) {
$annotations[strtolower($matches['name'])] = [
'line' => $lineNumber,
'value' => $matches['value'],
];
}
$lineNumber++;
}
return $annotations;
}
public function symbolAnnotations(): array
{
return $this->symbolAnnotations;
}
public function isHookToBeExecutedBeforeClass(): bool
{
return $this->isMethod &&
false !== strpos($this->docComment, '@beforeClass');
}
public function isHookToBeExecutedAfterClass(): bool
{
return $this->isMethod &&
false !== strpos($this->docComment, '@afterClass');
}
public function isToBeExecutedBeforeTest(): bool
{
return 1 === preg_match('/@before\b/', $this->docComment);
}
public function isToBeExecutedAfterTest(): bool
{
return 1 === preg_match('/@after\b/', $this->docComment);
}
public function isToBeExecutedAsPreCondition(): bool
{
return 1 === preg_match('/@preCondition\b/', $this->docComment);
}
public function isToBeExecutedAsPostCondition(): bool
{
return 1 === preg_match('/@postCondition\b/', $this->docComment);
}
private function getDataFromDataProviderAnnotation(string $docComment): ?array
{
$methodName = null;
$className = $this->className;
if ($this->isMethod) {
$methodName = $this->name;
}
if (!preg_match_all(self::REGEX_DATA_PROVIDER, $docComment, $matches)) {
return null;
}
$result = [];
foreach ($matches[1] as $match) {
$dataProviderMethodNameNamespace = explode('\\', $match);
$leaf = explode('::', array_pop($dataProviderMethodNameNamespace));
$dataProviderMethodName = array_pop($leaf);
if (empty($dataProviderMethodNameNamespace)) {
$dataProviderMethodNameNamespace = '';
} else {
$dataProviderMethodNameNamespace = implode('\\', $dataProviderMethodNameNamespace) . '\\';
}
if (empty($leaf)) {
$dataProviderClassName = $className;
} else {
/** @psalm-var class-string $dataProviderClassName */
$dataProviderClassName = $dataProviderMethodNameNamespace . array_pop($leaf);
}
try {
$dataProviderClass = new ReflectionClass($dataProviderClassName);
$dataProviderMethod = $dataProviderClass->getMethod(
$dataProviderMethodName
);
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
$e->getCode(),
$e
);
// @codeCoverageIgnoreEnd
}
if ($dataProviderMethod->isStatic()) {
$object = null;
} else {
$object = $dataProviderClass->newInstance();
}
if ($dataProviderMethod->getNumberOfParameters() === 0) {
$data = $dataProviderMethod->invoke($object);
} else {
$data = $dataProviderMethod->invoke($object, $methodName);
}
if ($data instanceof Traversable) {
$origData = $data;
$data = [];
foreach ($origData as $key => $value) {
if (is_int($key)) {
$data[] = $value;
} elseif (array_key_exists($key, $data)) {
throw new InvalidDataProviderException(
sprintf(
'The key "%s" has already been defined in the data provider "%s".',
$key,
$match
)
);
} else {
$data[$key] = $value;
}
}
}
if (is_array($data)) {
$result = array_merge($result, $data);
}
}
return $result;
}
/**
* @throws Exception
*/
private function getDataFromTestWithAnnotation(string $docComment): ?array
{
$docComment = $this->cleanUpMultiLineAnnotation($docComment);
if (!preg_match(self::REGEX_TEST_WITH, $docComment, $matches, PREG_OFFSET_CAPTURE)) {
return null;
}
$offset = strlen($matches[0][0]) + $matches[0][1];
$annotationContent = substr($docComment, $offset);
$data = [];
foreach (explode("\n", $annotationContent) as $candidateRow) {
$candidateRow = trim($candidateRow);
if ($candidateRow[0] !== '[') {
break;
}
$dataSet = json_decode($candidateRow, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception(
'The data set for the @testWith annotation cannot be parsed: ' . json_last_error_msg()
);
}
$data[] = $dataSet;
}
if (!$data) {
throw new Exception('The data set for the @testWith annotation cannot be parsed.');
}
return $data;
}
private function cleanUpMultiLineAnnotation(string $docComment): string
{
//removing initial ' * ' for docComment
$docComment = str_replace("\r\n", "\n", $docComment);
$docComment = preg_replace('/' . '\n' . '\s*' . '\*' . '\s?' . '/', "\n", $docComment);
$docComment = (string) substr($docComment, 0, -1);
return rtrim($docComment, "\n");
}
/** @return array> */
private static function parseDocBlock(string $docBlock): array
{
// Strip away the docblock header and footer to ease parsing of one line annotations
$docBlock = (string) substr($docBlock, 3, -2);
$annotations = [];
if (preg_match_all('/@(?P[A-Za-z_-]+)(?:[ \t]+(?P.*?))?[ \t]*\r?$/m', $docBlock, $matches)) {
$numMatches = count($matches[0]);
for ($i = 0; $i < $numMatches; $i++) {
$annotations[$matches['name'][$i]][] = (string) $matches['value'][$i];
}
}
return $annotations;
}
/** @param ReflectionClass|ReflectionFunctionAbstract $reflector */
private static function extractAnnotationsFromReflector(Reflector $reflector): array
{
$annotations = [];
if ($reflector instanceof ReflectionClass) {
$annotations = array_merge(
$annotations,
...array_map(
static function (ReflectionClass $trait): array
{
return self::parseDocBlock((string) $trait->getDocComment());
},
array_values($reflector->getTraits())
)
);
}
return array_merge(
$annotations,
self::parseDocBlock((string) $reflector->getDocComment())
);
}
}
PK %Zo phpunit/src/Util/Reflection.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Reflection
{
/**
* @psalm-return list
*/
public function publicMethodsInTestClass(ReflectionClass $class): array
{
return $this->filterMethods($class, ReflectionMethod::IS_PUBLIC);
}
/**
* @psalm-return list
*/
public function methodsInTestClass(ReflectionClass $class): array
{
return $this->filterMethods($class, null);
}
/**
* @psalm-return list
*/
private function filterMethods(ReflectionClass $class, ?int $filter): array
{
$methods = [];
// PHP <7.3.5 throw error when null is passed
// to ReflectionClass::getMethods() when strict_types is enabled.
$classMethods = $filter === null ? $class->getMethods() : $class->getMethods($filter);
foreach ($classMethods as $method) {
if ($method->getDeclaringClass()->getName() === TestCase::class) {
continue;
}
if ($method->getDeclaringClass()->getName() === Assert::class) {
continue;
}
$methods[] = $method;
}
return $methods;
}
}
PK %Zi . phpunit/src/Util/VersionComparisonOperator.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use function in_array;
use function sprintf;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @psalm-immutable
*/
final class VersionComparisonOperator
{
/**
* @psalm-var '<'|'lt'|'<='|'le'|'>'|'gt'|'>='|'ge'|'=='|'='|'eq'|'!='|'<>'|'ne'
*/
private $operator;
public function __construct(string $operator)
{
$this->ensureOperatorIsValid($operator);
$this->operator = $operator;
}
/**
* @return '!='|'<'|'<='|'<>'|'='|'=='|'>'|'>='|'eq'|'ge'|'gt'|'le'|'lt'|'ne'
*/
public function asString(): string
{
return $this->operator;
}
/**
* @throws Exception
*
* @psalm-assert '<'|'lt'|'<='|'le'|'>'|'gt'|'>='|'ge'|'=='|'='|'eq'|'!='|'<>'|'ne' $operator
*/
private function ensureOperatorIsValid(string $operator): void
{
if (!in_array($operator, ['<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne'], true)) {
throw new Exception(
sprintf(
'"%s" is not a valid version_compare() operator',
$operator
)
);
}
}
}
PK %ZIf f phpunit/src/Util/Json.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const JSON_PRETTY_PRINT;
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;
use function count;
use function is_array;
use function is_object;
use function json_decode;
use function json_encode;
use function json_last_error;
use function ksort;
use PHPUnit\Framework\Exception;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Json
{
/**
* Prettify json string.
*
* @throws \PHPUnit\Framework\Exception
*/
public static function prettify(string $json): string
{
$decodedJson = json_decode($json, false);
if (json_last_error()) {
throw new Exception(
'Cannot prettify invalid json'
);
}
return json_encode($decodedJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
/**
* To allow comparison of JSON strings, first process them into a consistent
* format so that they can be compared as strings.
*
* @return array ($error, $canonicalized_json) The $error parameter is used
* to indicate an error decoding the json. This is used to avoid ambiguity
* with JSON strings consisting entirely of 'null' or 'false'.
*/
public static function canonicalize(string $json): array
{
$decodedJson = json_decode($json);
if (json_last_error()) {
return [true, null];
}
self::recursiveSort($decodedJson);
$reencodedJson = json_encode($decodedJson);
return [false, $reencodedJson];
}
/**
* JSON object keys are unordered while PHP array keys are ordered.
*
* Sort all array keys to ensure both the expected and actual values have
* their keys in the same order.
*/
private static function recursiveSort(&$json): void
{
if (!is_array($json)) {
// If the object is not empty, change it to an associative array
// so we can sort the keys (and we will still re-encode it
// correctly, since PHP encodes associative arrays as JSON objects.)
// But EMPTY objects MUST remain empty objects. (Otherwise we will
// re-encode it as a JSON array rather than a JSON object.)
// See #2919.
if (is_object($json) && count((array) $json) > 0) {
$json = (array) $json;
} else {
return;
}
}
ksort($json);
foreach ($json as $key => &$value) {
self::recursiveSort($value);
}
}
}
PK %Z]r8
phpunit/src/Util/Printer.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const ENT_COMPAT;
use const ENT_SUBSTITUTE;
use const PHP_SAPI;
use function assert;
use function count;
use function dirname;
use function explode;
use function fclose;
use function fopen;
use function fsockopen;
use function fwrite;
use function htmlspecialchars;
use function is_resource;
use function is_string;
use function sprintf;
use function str_replace;
use function strncmp;
use function strpos;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
class Printer
{
/**
* @psalm-var closed-resource|resource
*/
private $stream;
/**
* @var bool
*/
private $isPhpStream;
/**
* @param null|resource|string $out
*
* @throws Exception
*/
public function __construct($out = null)
{
if (is_resource($out)) {
$this->stream = $out;
return;
}
if (!is_string($out)) {
return;
}
if (strpos($out, 'socket://') === 0) {
$tmp = explode(':', str_replace('socket://', '', $out));
if (count($tmp) !== 2) {
throw new Exception(
sprintf(
'"%s" does not match "socket://hostname:port" format',
$out
)
);
}
$this->stream = fsockopen($tmp[0], (int) $tmp[1]);
return;
}
if (strpos($out, 'php://') === false && !Filesystem::createDirectory(dirname($out))) {
throw new Exception(
sprintf(
'Directory "%s" was not created',
dirname($out)
)
);
}
$this->stream = fopen($out, 'wb');
$this->isPhpStream = strncmp($out, 'php://', 6) !== 0;
}
public function write(string $buffer): void
{
if ($this->stream) {
assert(is_resource($this->stream));
fwrite($this->stream, $buffer);
} else {
if (PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg') {
$buffer = htmlspecialchars($buffer, ENT_COMPAT | ENT_SUBSTITUTE);
}
print $buffer;
}
}
public function flush(): void
{
if ($this->stream && $this->isPhpStream) {
assert(is_resource($this->stream));
fclose($this->stream);
}
}
}
PK %ZT ! phpunit/src/Util/ErrorHandler.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const E_DEPRECATED;
use const E_NOTICE;
use const E_STRICT;
use const E_USER_DEPRECATED;
use const E_USER_NOTICE;
use const E_USER_WARNING;
use const E_WARNING;
use function error_reporting;
use function restore_error_handler;
use function set_error_handler;
use PHPUnit\Framework\Error\Deprecated;
use PHPUnit\Framework\Error\Error;
use PHPUnit\Framework\Error\Notice;
use PHPUnit\Framework\Error\Warning;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class ErrorHandler
{
/**
* @var bool
*/
private $convertDeprecationsToExceptions;
/**
* @var bool
*/
private $convertErrorsToExceptions;
/**
* @var bool
*/
private $convertNoticesToExceptions;
/**
* @var bool
*/
private $convertWarningsToExceptions;
/**
* @var bool
*/
private $registered = false;
public static function invokeIgnoringWarnings(callable $callable)
{
set_error_handler(
static function ($errorNumber, $errorString)
{
if ($errorNumber === E_WARNING) {
return;
}
return false;
}
);
$result = $callable();
restore_error_handler();
return $result;
}
public function __construct(bool $convertDeprecationsToExceptions, bool $convertErrorsToExceptions, bool $convertNoticesToExceptions, bool $convertWarningsToExceptions)
{
$this->convertDeprecationsToExceptions = $convertDeprecationsToExceptions;
$this->convertErrorsToExceptions = $convertErrorsToExceptions;
$this->convertNoticesToExceptions = $convertNoticesToExceptions;
$this->convertWarningsToExceptions = $convertWarningsToExceptions;
}
public function __invoke(int $errorNumber, string $errorString, string $errorFile, int $errorLine): bool
{
/*
* Do not raise an exception when the error suppression operator (@) was used.
*
* @see https://github.com/sebastianbergmann/phpunit/issues/3739
*/
if (!($errorNumber & error_reporting())) {
return false;
}
switch ($errorNumber) {
case E_NOTICE:
case E_USER_NOTICE:
case E_STRICT:
if (!$this->convertNoticesToExceptions) {
return false;
}
throw new Notice($errorString, $errorNumber, $errorFile, $errorLine);
case E_WARNING:
case E_USER_WARNING:
if (!$this->convertWarningsToExceptions) {
return false;
}
throw new Warning($errorString, $errorNumber, $errorFile, $errorLine);
case E_DEPRECATED:
case E_USER_DEPRECATED:
if (!$this->convertDeprecationsToExceptions) {
return false;
}
throw new Deprecated($errorString, $errorNumber, $errorFile, $errorLine);
default:
if (!$this->convertErrorsToExceptions) {
return false;
}
throw new Error($errorString, $errorNumber, $errorFile, $errorLine);
}
}
public function register(): void
{
if ($this->registered) {
return;
}
$oldErrorHandler = set_error_handler($this);
if ($oldErrorHandler !== null) {
restore_error_handler();
return;
}
$this->registered = true;
}
public function unregister(): void
{
if (!$this->registered) {
return;
}
restore_error_handler();
}
}
PK %Z5bS S * phpunit/src/Util/TestDox/ResultPrinter.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\TestDox;
use function get_class;
use function in_array;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\ErrorTestCase;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\Framework\WarningTestCase;
use PHPUnit\Runner\BaseTestRunner;
use PHPUnit\TextUI\ResultPrinter as ResultPrinterInterface;
use PHPUnit\Util\Printer;
use Throwable;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
abstract class ResultPrinter extends Printer implements ResultPrinterInterface
{
/**
* @var NamePrettifier
*/
protected $prettifier;
/**
* @var string
*/
protected $testClass = '';
/**
* @var int
*/
protected $testStatus;
/**
* @var array
*/
protected $tests = [];
/**
* @var int
*/
protected $successful = 0;
/**
* @var int
*/
protected $warned = 0;
/**
* @var int
*/
protected $failed = 0;
/**
* @var int
*/
protected $risky = 0;
/**
* @var int
*/
protected $skipped = 0;
/**
* @var int
*/
protected $incomplete = 0;
/**
* @var null|string
*/
protected $currentTestClassPrettified;
/**
* @var null|string
*/
protected $currentTestMethodPrettified;
/**
* @var array
*/
private $groups;
/**
* @var array
*/
private $excludeGroups;
/**
* @param resource $out
*
* @throws \PHPUnit\Framework\Exception
*/
public function __construct($out = null, array $groups = [], array $excludeGroups = [])
{
parent::__construct($out);
$this->groups = $groups;
$this->excludeGroups = $excludeGroups;
$this->prettifier = new NamePrettifier;
$this->startRun();
}
/**
* Flush buffer and close output.
*/
public function flush(): void
{
$this->doEndClass();
$this->endRun();
parent::flush();
}
/**
* An error occurred.
*/
public function addError(Test $test, Throwable $t, float $time): void
{
if (!$this->isOfInterest($test)) {
return;
}
$this->testStatus = BaseTestRunner::STATUS_ERROR;
$this->failed++;
}
/**
* A warning occurred.
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
if (!$this->isOfInterest($test)) {
return;
}
$this->testStatus = BaseTestRunner::STATUS_WARNING;
$this->warned++;
}
/**
* A failure occurred.
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
if (!$this->isOfInterest($test)) {
return;
}
$this->testStatus = BaseTestRunner::STATUS_FAILURE;
$this->failed++;
}
/**
* Incomplete test.
*/
public function addIncompleteTest(Test $test, Throwable $t, float $time): void
{
if (!$this->isOfInterest($test)) {
return;
}
$this->testStatus = BaseTestRunner::STATUS_INCOMPLETE;
$this->incomplete++;
}
/**
* Risky test.
*/
public function addRiskyTest(Test $test, Throwable $t, float $time): void
{
if (!$this->isOfInterest($test)) {
return;
}
$this->testStatus = BaseTestRunner::STATUS_RISKY;
$this->risky++;
}
/**
* Skipped test.
*/
public function addSkippedTest(Test $test, Throwable $t, float $time): void
{
if (!$this->isOfInterest($test)) {
return;
}
$this->testStatus = BaseTestRunner::STATUS_SKIPPED;
$this->skipped++;
}
/**
* A testsuite started.
*/
public function startTestSuite(TestSuite $suite): void
{
}
/**
* A testsuite ended.
*/
public function endTestSuite(TestSuite $suite): void
{
}
/**
* A test started.
*
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function startTest(Test $test): void
{
if (!$this->isOfInterest($test)) {
return;
}
$class = get_class($test);
if ($this->testClass !== $class) {
if ($this->testClass !== '') {
$this->doEndClass();
}
$this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
$this->testClass = $class;
$this->tests = [];
$this->startClass($class);
}
if ($test instanceof TestCase) {
$this->currentTestMethodPrettified = $this->prettifier->prettifyTestCase($test);
}
$this->testStatus = BaseTestRunner::STATUS_PASSED;
}
/**
* A test ended.
*/
public function endTest(Test $test, float $time): void
{
if (!$this->isOfInterest($test)) {
return;
}
$this->tests[] = [$this->currentTestMethodPrettified, $this->testStatus];
$this->currentTestClassPrettified = null;
$this->currentTestMethodPrettified = null;
}
protected function doEndClass(): void
{
foreach ($this->tests as $test) {
$this->onTest($test[0], $test[1] === BaseTestRunner::STATUS_PASSED);
}
$this->endClass($this->testClass);
}
/**
* Handler for 'start run' event.
*/
protected function startRun(): void
{
}
/**
* Handler for 'start class' event.
*/
protected function startClass(string $name): void
{
}
/**
* Handler for 'on test' event.
*/
protected function onTest(string $name, bool $success = true): void
{
}
/**
* Handler for 'end class' event.
*/
protected function endClass(string $name): void
{
}
/**
* Handler for 'end run' event.
*/
protected function endRun(): void
{
}
private function isOfInterest(Test $test): bool
{
if (!$test instanceof TestCase) {
return false;
}
if ($test instanceof ErrorTestCase || $test instanceof WarningTestCase) {
return false;
}
if (!empty($this->groups)) {
foreach ($test->getGroups() as $group) {
if (in_array($group, $this->groups, true)) {
return true;
}
}
return false;
}
if (!empty($this->excludeGroups)) {
foreach ($test->getGroups() as $group) {
if (in_array($group, $this->excludeGroups, true)) {
return false;
}
}
return true;
}
return true;
}
}
PK %Z(/ - phpunit/src/Util/TestDox/XmlResultPrinter.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\TestDox;
use function array_filter;
use function get_class;
use function implode;
use function strpos;
use DOMDocument;
use DOMElement;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\Framework\WarningTestCase;
use PHPUnit\Util\Printer;
use PHPUnit\Util\Test as TestUtil;
use ReflectionClass;
use ReflectionException;
use Throwable;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class XmlResultPrinter extends Printer implements TestListener
{
/**
* @var DOMDocument
*/
private $document;
/**
* @var DOMElement
*/
private $root;
/**
* @var NamePrettifier
*/
private $prettifier;
/**
* @var null|Throwable
*/
private $exception;
/**
* @param resource|string $out
*
* @throws Exception
*/
public function __construct($out = null)
{
$this->document = new DOMDocument('1.0', 'UTF-8');
$this->document->formatOutput = true;
$this->root = $this->document->createElement('tests');
$this->document->appendChild($this->root);
$this->prettifier = new NamePrettifier;
parent::__construct($out);
}
/**
* Flush buffer and close output.
*/
public function flush(): void
{
$this->write($this->document->saveXML());
parent::flush();
}
/**
* An error occurred.
*/
public function addError(Test $test, Throwable $t, float $time): void
{
$this->exception = $t;
}
/**
* A warning occurred.
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
}
/**
* A failure occurred.
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$this->exception = $e;
}
/**
* Incomplete test.
*/
public function addIncompleteTest(Test $test, Throwable $t, float $time): void
{
}
/**
* Risky test.
*/
public function addRiskyTest(Test $test, Throwable $t, float $time): void
{
}
/**
* Skipped test.
*/
public function addSkippedTest(Test $test, Throwable $t, float $time): void
{
}
/**
* A test suite started.
*/
public function startTestSuite(TestSuite $suite): void
{
}
/**
* A test suite ended.
*/
public function endTestSuite(TestSuite $suite): void
{
}
/**
* A test started.
*/
public function startTest(Test $test): void
{
$this->exception = null;
}
/**
* A test ended.
*
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function endTest(Test $test, float $time): void
{
if (!$test instanceof TestCase || $test instanceof WarningTestCase) {
return;
}
$groups = array_filter(
$test->getGroups(),
static function ($group)
{
return !($group === 'small' || $group === 'medium' || $group === 'large' || strpos($group, '__phpunit_') === 0);
}
);
$testNode = $this->document->createElement('test');
$testNode->setAttribute('className', get_class($test));
$testNode->setAttribute('methodName', $test->getName());
$testNode->setAttribute('prettifiedClassName', $this->prettifier->prettifyTestClass(get_class($test)));
$testNode->setAttribute('prettifiedMethodName', $this->prettifier->prettifyTestCase($test));
$testNode->setAttribute('status', (string) $test->getStatus());
$testNode->setAttribute('time', (string) $time);
$testNode->setAttribute('size', (string) $test->getSize());
$testNode->setAttribute('groups', implode(',', $groups));
foreach ($groups as $group) {
$groupNode = $this->document->createElement('group');
$groupNode->setAttribute('name', $group);
$testNode->appendChild($groupNode);
}
$annotations = TestUtil::parseTestMethodAnnotations(
get_class($test),
$test->getName(false)
);
foreach (['class', 'method'] as $type) {
foreach ($annotations[$type] as $annotation => $values) {
if ($annotation !== 'covers' && $annotation !== 'uses') {
continue;
}
foreach ($values as $value) {
$coversNode = $this->document->createElement($annotation);
$coversNode->setAttribute('target', $value);
$testNode->appendChild($coversNode);
}
}
}
foreach ($test->doubledTypes() as $doubledType) {
$testDoubleNode = $this->document->createElement('testDouble');
$testDoubleNode->setAttribute('type', $doubledType);
$testNode->appendChild($testDoubleNode);
}
$inlineAnnotations = \PHPUnit\Util\Test::getInlineAnnotations(get_class($test), $test->getName(false));
if (isset($inlineAnnotations['given'], $inlineAnnotations['when'], $inlineAnnotations['then'])) {
$testNode->setAttribute('given', $inlineAnnotations['given']['value']);
$testNode->setAttribute('givenStartLine', (string) $inlineAnnotations['given']['line']);
$testNode->setAttribute('when', $inlineAnnotations['when']['value']);
$testNode->setAttribute('whenStartLine', (string) $inlineAnnotations['when']['line']);
$testNode->setAttribute('then', $inlineAnnotations['then']['value']);
$testNode->setAttribute('thenStartLine', (string) $inlineAnnotations['then']['line']);
}
if ($this->exception !== null) {
if ($this->exception instanceof Exception) {
$steps = $this->exception->getSerializableTrace();
} else {
$steps = $this->exception->getTrace();
}
try {
$file = (new ReflectionClass($test))->getFileName();
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
foreach ($steps as $step) {
if (isset($step['file']) && $step['file'] === $file) {
$testNode->setAttribute('exceptionLine', (string) $step['line']);
break;
}
}
$testNode->setAttribute('exceptionMessage', $this->exception->getMessage());
}
$this->root->appendChild($testNode);
}
}
PK %Z_D># ># + phpunit/src/Util/TestDox/NamePrettifier.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\TestDox;
use function array_key_exists;
use function array_keys;
use function array_map;
use function array_pop;
use function array_values;
use function explode;
use function get_class;
use function gettype;
use function implode;
use function in_array;
use function is_bool;
use function is_float;
use function is_int;
use function is_numeric;
use function is_object;
use function is_scalar;
use function is_string;
use function ord;
use function preg_quote;
use function preg_replace;
use function range;
use function sprintf;
use function str_replace;
use function strlen;
use function strpos;
use function strtolower;
use function strtoupper;
use function substr;
use function trim;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Color;
use PHPUnit\Util\Exception as UtilException;
use PHPUnit\Util\Test;
use ReflectionException;
use ReflectionMethod;
use ReflectionObject;
use SebastianBergmann\Exporter\Exporter;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class NamePrettifier
{
/**
* @var string[]
*/
private $strings = [];
/**
* @var bool
*/
private $useColor;
public function __construct(bool $useColor = false)
{
$this->useColor = $useColor;
}
/**
* Prettifies the name of a test class.
*
* @psalm-param class-string $className
*/
public function prettifyTestClass(string $className): string
{
try {
$annotations = Test::parseTestMethodAnnotations($className);
if (isset($annotations['class']['testdox'][0])) {
return $annotations['class']['testdox'][0];
}
} catch (UtilException $e) {
// ignore, determine className by parsing the provided name
}
$parts = explode('\\', $className);
$className = array_pop($parts);
if (substr($className, -1 * strlen('Test')) === 'Test') {
$className = substr($className, 0, strlen($className) - strlen('Test'));
}
if (strpos($className, 'Tests') === 0) {
$className = substr($className, strlen('Tests'));
} elseif (strpos($className, 'Test') === 0) {
$className = substr($className, strlen('Test'));
}
if (empty($className)) {
$className = 'UnnamedTests';
}
if (!empty($parts)) {
$parts[] = $className;
$fullyQualifiedName = implode('\\', $parts);
} else {
$fullyQualifiedName = $className;
}
$result = preg_replace('/(?<=[[:lower:]])(?=[[:upper:]])/u', ' ', $className);
if ($fullyQualifiedName !== $className) {
return $result . ' (' . $fullyQualifiedName . ')';
}
return $result;
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function prettifyTestCase(TestCase $test): string
{
$annotations = Test::parseTestMethodAnnotations(
get_class($test),
$test->getName(false)
);
$annotationWithPlaceholders = false;
$callback = static function (string $variable): string
{
return sprintf('/%s(?=\b)/', preg_quote($variable, '/'));
};
if (isset($annotations['method']['testdox'][0])) {
$result = $annotations['method']['testdox'][0];
if (strpos($result, '$') !== false) {
$annotation = $annotations['method']['testdox'][0];
$providedData = $this->mapTestMethodParameterNamesToProvidedDataValues($test);
$variables = array_map($callback, array_keys($providedData));
$result = trim(preg_replace($variables, $providedData, $annotation));
$annotationWithPlaceholders = true;
}
} else {
$result = $this->prettifyTestMethod($test->getName(false));
}
if (!$annotationWithPlaceholders && $test->usesDataProvider()) {
$result .= $this->prettifyDataSet($test);
}
return $result;
}
public function prettifyDataSet(TestCase $test): string
{
if (!$this->useColor) {
return $test->getDataSetAsString(false);
}
if (is_int($test->dataName())) {
$data = Color::dim(' with data set ') . Color::colorize('fg-cyan', (string) $test->dataName());
} else {
$data = Color::dim(' with ') . Color::colorize('fg-cyan', Color::visualizeWhitespace((string) $test->dataName()));
}
return $data;
}
/**
* Prettifies the name of a test method.
*/
public function prettifyTestMethod(string $name): string
{
$buffer = '';
if ($name === '') {
return $buffer;
}
$string = (string) preg_replace('#\d+$#', '', $name, -1, $count);
if (in_array($string, $this->strings, true)) {
$name = $string;
} elseif ($count === 0) {
$this->strings[] = $string;
}
if (strpos($name, 'test_') === 0) {
$name = substr($name, 5);
} elseif (strpos($name, 'test') === 0) {
$name = substr($name, 4);
}
if ($name === '') {
return $buffer;
}
$name[0] = strtoupper($name[0]);
if (strpos($name, '_') !== false) {
return trim(str_replace('_', ' ', $name));
}
$wasNumeric = false;
foreach (range(0, strlen($name) - 1) as $i) {
if ($i > 0 && ord($name[$i]) >= 65 && ord($name[$i]) <= 90) {
$buffer .= ' ' . strtolower($name[$i]);
} else {
$isNumeric = is_numeric($name[$i]);
if (!$wasNumeric && $isNumeric) {
$buffer .= ' ';
$wasNumeric = true;
}
if ($wasNumeric && !$isNumeric) {
$wasNumeric = false;
}
$buffer .= $name[$i];
}
}
return $buffer;
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
private function mapTestMethodParameterNamesToProvidedDataValues(TestCase $test): array
{
try {
$reflector = new ReflectionMethod(get_class($test), $test->getName(false));
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new UtilException(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
$providedData = [];
$providedDataValues = array_values($test->getProvidedData());
$i = 0;
$providedData['$_dataName'] = $test->dataName();
foreach ($reflector->getParameters() as $parameter) {
if (!array_key_exists($i, $providedDataValues) && $parameter->isDefaultValueAvailable()) {
try {
$providedDataValues[$i] = $parameter->getDefaultValue();
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new UtilException(
$e->getMessage(),
$e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd
}
$value = $providedDataValues[$i++] ?? null;
if (is_object($value)) {
$reflector = new ReflectionObject($value);
if ($reflector->hasMethod('__toString')) {
$value = (string) $value;
} else {
$value = get_class($value);
}
}
if (!is_scalar($value)) {
$value = gettype($value);
}
if (is_bool($value) || is_int($value) || is_float($value)) {
$value = (new Exporter)->export($value);
}
if (is_string($value) && $value === '') {
if ($this->useColor) {
$value = Color::colorize('dim,underlined', 'empty');
} else {
$value = "''";
}
}
$providedData['$' . $parameter->getName()] = $value;
}
if ($this->useColor) {
$providedData = array_map(static function ($value)
{
return Color::colorize('fg-cyan', Color::visualizeWhitespace((string) $value, true));
}, $providedData);
}
return $providedData;
}
}
PK %Z/+ /+ + phpunit/src/Util/TestDox/TestDoxPrinter.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\TestDox;
use const PHP_EOL;
use function array_map;
use function get_class;
use function implode;
use function method_exists;
use function preg_split;
use function trim;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Reorderable;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestResult;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\Runner\BaseTestRunner;
use PHPUnit\Runner\PhptTestCase;
use PHPUnit\TextUI\DefaultResultPrinter;
use Throwable;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
class TestDoxPrinter extends DefaultResultPrinter
{
/**
* @var NamePrettifier
*/
protected $prettifier;
/**
* @var int The number of test results received from the TestRunner
*/
protected $testIndex = 0;
/**
* @var int The number of test results already sent to the output
*/
protected $testFlushIndex = 0;
/**
* @var array Buffer for test results
*/
protected $testResults = [];
/**
* @var array Lookup table for testname to testResults[index]
*/
protected $testNameResultIndex = [];
/**
* @var bool
*/
protected $enableOutputBuffer = false;
/**
* @var array array
*/
protected $originalExecutionOrder = [];
/**
* @var int
*/
protected $spinState = 0;
/**
* @var bool
*/
protected $showProgress = true;
/**
* @param null|resource|string $out
* @param int|string $numberOfColumns
*
* @throws \PHPUnit\Framework\Exception
*/
public function __construct($out = null, bool $verbose = false, string $colors = self::COLOR_DEFAULT, bool $debug = false, $numberOfColumns = 80, bool $reverse = false)
{
parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
$this->prettifier = new NamePrettifier($this->colors);
}
public function setOriginalExecutionOrder(array $order): void
{
$this->originalExecutionOrder = $order;
$this->enableOutputBuffer = !empty($order);
}
public function setShowProgressAnimation(bool $showProgress): void
{
$this->showProgress = $showProgress;
}
public function printResult(TestResult $result): void
{
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function endTest(Test $test, float $time): void
{
if (!$test instanceof TestCase && !$test instanceof PhptTestCase && !$test instanceof TestSuite) {
return;
}
if ($this->testHasPassed()) {
$this->registerTestResult($test, null, BaseTestRunner::STATUS_PASSED, $time, false);
}
if ($test instanceof TestCase || $test instanceof PhptTestCase) {
$this->testIndex++;
}
parent::endTest($test, $time);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function addError(Test $test, Throwable $t, float $time): void
{
$this->registerTestResult($test, $t, BaseTestRunner::STATUS_ERROR, $time, true);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
$this->registerTestResult($test, $e, BaseTestRunner::STATUS_WARNING, $time, true);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$this->registerTestResult($test, $e, BaseTestRunner::STATUS_FAILURE, $time, true);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function addIncompleteTest(Test $test, Throwable $t, float $time): void
{
$this->registerTestResult($test, $t, BaseTestRunner::STATUS_INCOMPLETE, $time, false);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function addRiskyTest(Test $test, Throwable $t, float $time): void
{
$this->registerTestResult($test, $t, BaseTestRunner::STATUS_RISKY, $time, false);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function addSkippedTest(Test $test, Throwable $t, float $time): void
{
$this->registerTestResult($test, $t, BaseTestRunner::STATUS_SKIPPED, $time, false);
}
public function writeProgress(string $progress): void
{
$this->flushOutputBuffer();
}
public function flush(): void
{
$this->flushOutputBuffer(true);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
protected function registerTestResult(Test $test, ?Throwable $t, int $status, float $time, bool $verbose): void
{
$testName = $test instanceof Reorderable ? $test->sortId() : $test->getName();
$result = [
'className' => $this->formatClassName($test),
'testName' => $testName,
'testMethod' => $this->formatTestName($test),
'message' => '',
'status' => $status,
'time' => $time,
'verbose' => $verbose,
];
if ($t !== null) {
$result['message'] = $this->formatTestResultMessage($t, $result);
}
$this->testResults[$this->testIndex] = $result;
$this->testNameResultIndex[$testName] = $this->testIndex;
}
protected function formatTestName(Test $test): string
{
return method_exists($test, 'getName') ? $test->getName() : '';
}
protected function formatClassName(Test $test): string
{
return get_class($test);
}
protected function testHasPassed(): bool
{
if (!isset($this->testResults[$this->testIndex]['status'])) {
return true;
}
if ($this->testResults[$this->testIndex]['status'] === BaseTestRunner::STATUS_PASSED) {
return true;
}
return false;
}
protected function flushOutputBuffer(bool $forceFlush = false): void
{
if ($this->testFlushIndex === $this->testIndex) {
return;
}
if ($this->testFlushIndex > 0) {
if ($this->enableOutputBuffer &&
isset($this->originalExecutionOrder[$this->testFlushIndex - 1])) {
$prevResult = $this->getTestResultByName($this->originalExecutionOrder[$this->testFlushIndex - 1]);
} else {
$prevResult = $this->testResults[$this->testFlushIndex - 1];
}
} else {
$prevResult = $this->getEmptyTestResult();
}
if (!$this->enableOutputBuffer) {
$this->writeTestResult($prevResult, $this->testResults[$this->testFlushIndex++]);
} else {
do {
$flushed = false;
if (!$forceFlush && isset($this->originalExecutionOrder[$this->testFlushIndex])) {
$result = $this->getTestResultByName($this->originalExecutionOrder[$this->testFlushIndex]);
} else {
// This test(name) cannot found in original execution order,
// flush result to output stream right away
$result = $this->testResults[$this->testFlushIndex];
}
if (!empty($result)) {
$this->hideSpinner();
$this->writeTestResult($prevResult, $result);
$this->testFlushIndex++;
$prevResult = $result;
$flushed = true;
} else {
$this->showSpinner();
}
} while ($flushed && $this->testFlushIndex < $this->testIndex);
}
}
protected function showSpinner(): void
{
if (!$this->showProgress) {
return;
}
if ($this->spinState) {
$this->undrawSpinner();
}
$this->spinState++;
$this->drawSpinner();
}
protected function hideSpinner(): void
{
if (!$this->showProgress) {
return;
}
if ($this->spinState) {
$this->undrawSpinner();
}
$this->spinState = 0;
}
protected function drawSpinner(): void
{
// optional for CLI printers: show the user a 'buffering output' spinner
}
protected function undrawSpinner(): void
{
// remove the spinner from the current line
}
protected function writeTestResult(array $prevResult, array $result): void
{
}
protected function getEmptyTestResult(): array
{
return [
'className' => '',
'testName' => '',
'message' => '',
'failed' => '',
'verbose' => '',
];
}
protected function getTestResultByName(?string $testName): array
{
if (isset($this->testNameResultIndex[$testName])) {
return $this->testResults[$this->testNameResultIndex[$testName]];
}
return [];
}
protected function formatThrowable(Throwable $t, ?int $status = null): string
{
$message = trim(\PHPUnit\Framework\TestFailure::exceptionToString($t));
if ($message) {
$message .= PHP_EOL . PHP_EOL . $this->formatStacktrace($t);
} else {
$message = $this->formatStacktrace($t);
}
return $message;
}
protected function formatStacktrace(Throwable $t): string
{
return \PHPUnit\Util\Filter::getFilteredStacktrace($t);
}
protected function formatTestResultMessage(Throwable $t, array $result, string $prefix = '│'): string
{
$message = $this->formatThrowable($t, $result['status']);
if ($message === '') {
return '';
}
if (!($this->verbose || $result['verbose'])) {
return '';
}
return $this->prefixLines($prefix, $message);
}
protected function prefixLines(string $prefix, string $message): string
{
$message = trim($message);
return implode(
PHP_EOL,
array_map(
static function (string $text) use ($prefix)
{
return ' ' . $prefix . ($text ? ' ' . $text : '');
},
preg_split('/\r\n|\r|\n/', $message)
)
);
}
}
PK %Zw . phpunit/src/Util/TestDox/TextResultPrinter.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\TestDox;
use PHPUnit\Framework\TestResult;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class TextResultPrinter extends ResultPrinter
{
public function printResult(TestResult $result): void
{
}
/**
* Handler for 'start class' event.
*/
protected function startClass(string $name): void
{
$this->write($this->currentTestClassPrettified . "\n");
}
/**
* Handler for 'on test' event.
*/
protected function onTest(string $name, bool $success = true): void
{
if ($success) {
$this->write(' [x] ');
} else {
$this->write(' [ ] ');
}
$this->write($name . "\n");
}
/**
* Handler for 'end class' event.
*/
protected function endClass(string $name): void
{
$this->write("\n");
}
}
PK %Z?a/- /- . phpunit/src/Util/TestDox/CliTestDoxPrinter.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\TestDox;
use const PHP_EOL;
use function array_map;
use function ceil;
use function count;
use function explode;
use function get_class;
use function implode;
use function preg_match;
use function sprintf;
use function strlen;
use function strpos;
use function trim;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestResult;
use PHPUnit\Runner\BaseTestRunner;
use PHPUnit\Runner\PhptTestCase;
use PHPUnit\Util\Color;
use SebastianBergmann\Timer\ResourceUsageFormatter;
use SebastianBergmann\Timer\Timer;
use Throwable;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
class CliTestDoxPrinter extends TestDoxPrinter
{
/**
* The default Testdox left margin for messages is a vertical line.
*/
private const PREFIX_SIMPLE = [
'default' => '│',
'start' => '│',
'message' => '│',
'diff' => '│',
'trace' => '│',
'last' => '│',
];
/**
* Colored Testdox use box-drawing for a more textured map of the message.
*/
private const PREFIX_DECORATED = [
'default' => '│',
'start' => '┐',
'message' => '├',
'diff' => '┊',
'trace' => '╵',
'last' => '┴',
];
private const SPINNER_ICONS = [
" \e[36m◐\e[0m running tests",
" \e[36m◓\e[0m running tests",
" \e[36m◑\e[0m running tests",
" \e[36m◒\e[0m running tests",
];
private const STATUS_STYLES = [
BaseTestRunner::STATUS_PASSED => [
'symbol' => '✔',
'color' => 'fg-green',
],
BaseTestRunner::STATUS_ERROR => [
'symbol' => '✘',
'color' => 'fg-yellow',
'message' => 'bg-yellow,fg-black',
],
BaseTestRunner::STATUS_FAILURE => [
'symbol' => '✘',
'color' => 'fg-red',
'message' => 'bg-red,fg-white',
],
BaseTestRunner::STATUS_SKIPPED => [
'symbol' => '↩',
'color' => 'fg-cyan',
'message' => 'fg-cyan',
],
BaseTestRunner::STATUS_RISKY => [
'symbol' => '☢',
'color' => 'fg-yellow',
'message' => 'fg-yellow',
],
BaseTestRunner::STATUS_INCOMPLETE => [
'symbol' => '∅',
'color' => 'fg-yellow',
'message' => 'fg-yellow',
],
BaseTestRunner::STATUS_WARNING => [
'symbol' => '⚠',
'color' => 'fg-yellow',
'message' => 'fg-yellow',
],
BaseTestRunner::STATUS_UNKNOWN => [
'symbol' => '?',
'color' => 'fg-blue',
'message' => 'fg-white,bg-blue',
],
];
/**
* @var int[]
*/
private $nonSuccessfulTestResults = [];
/**
* @var Timer
*/
private $timer;
/**
* @param null|resource|string $out
* @param int|string $numberOfColumns
*
* @throws \PHPUnit\Framework\Exception
*/
public function __construct($out = null, bool $verbose = false, string $colors = self::COLOR_DEFAULT, bool $debug = false, $numberOfColumns = 80, bool $reverse = false)
{
parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
$this->timer = new Timer;
$this->timer->start();
}
public function printResult(TestResult $result): void
{
$this->printHeader($result);
$this->printNonSuccessfulTestsSummary($result->count());
$this->printFooter($result);
}
protected function printHeader(TestResult $result): void
{
$this->write("\n" . (new ResourceUsageFormatter)->resourceUsage($this->timer->stop()) . "\n\n");
}
protected function formatClassName(Test $test): string
{
if ($test instanceof TestCase) {
return $this->prettifier->prettifyTestClass(get_class($test));
}
return get_class($test);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
protected function registerTestResult(Test $test, ?Throwable $t, int $status, float $time, bool $verbose): void
{
if ($status !== BaseTestRunner::STATUS_PASSED) {
$this->nonSuccessfulTestResults[] = $this->testIndex;
}
parent::registerTestResult($test, $t, $status, $time, $verbose);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
protected function formatTestName(Test $test): string
{
if ($test instanceof TestCase) {
return $this->prettifier->prettifyTestCase($test);
}
return parent::formatTestName($test);
}
protected function writeTestResult(array $prevResult, array $result): void
{
// spacer line for new suite headers and after verbose messages
if ($prevResult['testName'] !== '' &&
(!empty($prevResult['message']) || $prevResult['className'] !== $result['className'])) {
$this->write(PHP_EOL);
}
// suite header
if ($prevResult['className'] !== $result['className']) {
$this->write($this->colorizeTextBox('underlined', $result['className']) . PHP_EOL);
}
// test result line
if ($this->colors && $result['className'] === PhptTestCase::class) {
$testName = Color::colorizePath($result['testName'], $prevResult['testName'], true);
} else {
$testName = $result['testMethod'];
}
$style = self::STATUS_STYLES[$result['status']];
$line = sprintf(
' %s %s%s' . PHP_EOL,
$this->colorizeTextBox($style['color'], $style['symbol']),
$testName,
$this->verbose ? ' ' . $this->formatRuntime($result['time'], $style['color']) : ''
);
$this->write($line);
// additional information when verbose
$this->write($result['message']);
}
protected function formatThrowable(Throwable $t, ?int $status = null): string
{
return trim(\PHPUnit\Framework\TestFailure::exceptionToString($t));
}
protected function colorizeMessageAndDiff(string $style, string $buffer): array
{
$lines = $buffer ? array_map('\rtrim', explode(PHP_EOL, $buffer)) : [];
$message = [];
$diff = [];
$insideDiff = false;
foreach ($lines as $line) {
if ($line === '--- Expected') {
$insideDiff = true;
}
if (!$insideDiff) {
$message[] = $line;
} else {
if (strpos($line, '-') === 0) {
$line = Color::colorize('fg-red', Color::visualizeWhitespace($line, true));
} elseif (strpos($line, '+') === 0) {
$line = Color::colorize('fg-green', Color::visualizeWhitespace($line, true));
} elseif ($line === '@@ @@') {
$line = Color::colorize('fg-cyan', $line);
}
$diff[] = $line;
}
}
$diff = implode(PHP_EOL, $diff);
if (!empty($message)) {
$message = $this->colorizeTextBox($style, implode(PHP_EOL, $message));
}
return [$message, $diff];
}
protected function formatStacktrace(Throwable $t): string
{
$trace = \PHPUnit\Util\Filter::getFilteredStacktrace($t);
if (!$this->colors) {
return $trace;
}
$lines = [];
$prevPath = '';
foreach (explode(PHP_EOL, $trace) as $line) {
if (preg_match('/^(.*):(\d+)$/', $line, $matches)) {
$lines[] = Color::colorizePath($matches[1], $prevPath) .
Color::dim(':') .
Color::colorize('fg-blue', $matches[2]) .
"\n";
$prevPath = $matches[1];
} else {
$lines[] = $line;
$prevPath = '';
}
}
return implode('', $lines);
}
protected function formatTestResultMessage(Throwable $t, array $result, ?string $prefix = null): string
{
$message = $this->formatThrowable($t, $result['status']);
$diff = '';
if (!($this->verbose || $result['verbose'])) {
return '';
}
if ($message && $this->colors) {
$style = self::STATUS_STYLES[$result['status']]['message'] ?? '';
[$message, $diff] = $this->colorizeMessageAndDiff($style, $message);
}
if ($prefix === null || !$this->colors) {
$prefix = self::PREFIX_SIMPLE;
}
if ($this->colors) {
$color = self::STATUS_STYLES[$result['status']]['color'] ?? '';
$prefix = array_map(static function ($p) use ($color)
{
return Color::colorize($color, $p);
}, self::PREFIX_DECORATED);
}
$trace = $this->formatStacktrace($t);
$out = $this->prefixLines($prefix['start'], PHP_EOL) . PHP_EOL;
if ($message) {
$out .= $this->prefixLines($prefix['message'], $message . PHP_EOL) . PHP_EOL;
}
if ($diff) {
$out .= $this->prefixLines($prefix['diff'], $diff . PHP_EOL) . PHP_EOL;
}
if ($trace) {
if ($message || $diff) {
$out .= $this->prefixLines($prefix['default'], PHP_EOL) . PHP_EOL;
}
$out .= $this->prefixLines($prefix['trace'], $trace . PHP_EOL) . PHP_EOL;
}
$out .= $this->prefixLines($prefix['last'], PHP_EOL) . PHP_EOL;
return $out;
}
protected function drawSpinner(): void
{
if ($this->colors) {
$id = $this->spinState % count(self::SPINNER_ICONS);
$this->write(self::SPINNER_ICONS[$id]);
}
}
protected function undrawSpinner(): void
{
if ($this->colors) {
$id = $this->spinState % count(self::SPINNER_ICONS);
$this->write("\e[1K\e[" . strlen(self::SPINNER_ICONS[$id]) . 'D');
}
}
private function formatRuntime(float $time, string $color = ''): string
{
if (!$this->colors) {
return sprintf('[%.2f ms]', $time * 1000);
}
if ($time > 1) {
$color = 'fg-magenta';
}
return Color::colorize($color, ' ' . (int) ceil($time * 1000) . ' ' . Color::dim('ms'));
}
private function printNonSuccessfulTestsSummary(int $numberOfExecutedTests): void
{
if (empty($this->nonSuccessfulTestResults)) {
return;
}
if ((count($this->nonSuccessfulTestResults) / $numberOfExecutedTests) >= 0.7) {
return;
}
$this->write("Summary of non-successful tests:\n\n");
$prevResult = $this->getEmptyTestResult();
foreach ($this->nonSuccessfulTestResults as $testIndex) {
$result = $this->testResults[$testIndex];
$this->writeTestResult($prevResult, $result);
$prevResult = $result;
}
}
}
PK %Zs,I
I
. phpunit/src/Util/TestDox/HtmlResultPrinter.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\TestDox;
use function sprintf;
use PHPUnit\Framework\TestResult;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class HtmlResultPrinter extends ResultPrinter
{
/**
* @var string
*/
private const PAGE_HEADER = <<<'EOT'
Test Documentation
EOT;
/**
* @var string
*/
private const CLASS_HEADER = <<<'EOT'
%s
EOT;
/**
* @var string
*/
private const CLASS_FOOTER = <<<'EOT'
EOT;
/**
* @var string
*/
private const PAGE_FOOTER = <<<'EOT'
EOT;
public function printResult(TestResult $result): void
{
}
/**
* Handler for 'start run' event.
*/
protected function startRun(): void
{
$this->write(self::PAGE_HEADER);
}
/**
* Handler for 'start class' event.
*/
protected function startClass(string $name): void
{
$this->write(
sprintf(
self::CLASS_HEADER,
$this->currentTestClassPrettified
)
);
}
/**
* Handler for 'on test' event.
*/
protected function onTest(string $name, bool $success = true): void
{
$this->write(
sprintf(
" %s\n",
$success ? 'success' : 'defect',
$name
)
);
}
/**
* Handler for 'end class' event.
*/
protected function endClass(string $name): void
{
$this->write(self::CLASS_FOOTER);
}
/**
* Handler for 'end run' event.
*/
protected function endRun(): void
{
$this->write(self::PAGE_FOOTER);
}
}
PK %Z3 phpunit/src/Util/GlobalState.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use function array_keys;
use function array_reverse;
use function array_shift;
use function defined;
use function get_defined_constants;
use function get_included_files;
use function in_array;
use function ini_get_all;
use function is_array;
use function is_file;
use function is_scalar;
use function preg_match;
use function serialize;
use function sprintf;
use function strpos;
use function strtr;
use function substr;
use function var_export;
use Closure;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class GlobalState
{
/**
* @var string[]
*/
private const SUPER_GLOBAL_ARRAYS = [
'_ENV',
'_POST',
'_GET',
'_COOKIE',
'_SERVER',
'_FILES',
'_REQUEST',
];
/**
* @throws Exception
*/
public static function getIncludedFilesAsString(): string
{
return self::processIncludedFilesAsString(get_included_files());
}
/**
* @param string[] $files
*
* @throws Exception
*/
public static function processIncludedFilesAsString(array $files): string
{
$excludeList = new ExcludeList;
$prefix = false;
$result = '';
if (defined('__PHPUNIT_PHAR__')) {
$prefix = 'phar://' . __PHPUNIT_PHAR__ . '/';
}
// Do not process bootstrap script
array_shift($files);
// If bootstrap script was a Composer bin proxy, skip the second entry as well
if (substr(strtr($files[0], '\\', '/'), -24) === '/phpunit/phpunit/phpunit') {
array_shift($files);
}
foreach (array_reverse($files) as $file) {
if (!empty($GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST']) &&
in_array($file, $GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST'], true)) {
continue;
}
if ($prefix !== false && strpos($file, $prefix) === 0) {
continue;
}
// Skip virtual file system protocols
if (preg_match('/^(vfs|phpvfs[a-z0-9]+):/', $file)) {
continue;
}
if (!$excludeList->isExcluded($file) && is_file($file)) {
$result = 'require_once \'' . $file . "';\n" . $result;
}
}
return $result;
}
public static function getIniSettingsAsString(): string
{
$result = '';
foreach (ini_get_all(null, false) as $key => $value) {
$result .= sprintf(
'@ini_set(%s, %s);' . "\n",
self::exportVariable($key),
self::exportVariable((string) $value)
);
}
return $result;
}
public static function getConstantsAsString(): string
{
$constants = get_defined_constants(true);
$result = '';
if (isset($constants['user'])) {
foreach ($constants['user'] as $name => $value) {
$result .= sprintf(
'if (!defined(\'%s\')) define(\'%s\', %s);' . "\n",
$name,
$name,
self::exportVariable($value)
);
}
}
return $result;
}
public static function getGlobalsAsString(): string
{
$result = '';
foreach (self::SUPER_GLOBAL_ARRAYS as $superGlobalArray) {
if (isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray])) {
foreach (array_keys($GLOBALS[$superGlobalArray]) as $key) {
if ($GLOBALS[$superGlobalArray][$key] instanceof Closure) {
continue;
}
$result .= sprintf(
'$GLOBALS[\'%s\'][\'%s\'] = %s;' . "\n",
$superGlobalArray,
$key,
self::exportVariable($GLOBALS[$superGlobalArray][$key])
);
}
}
}
$excludeList = self::SUPER_GLOBAL_ARRAYS;
$excludeList[] = 'GLOBALS';
foreach (array_keys($GLOBALS) as $key) {
if (!$GLOBALS[$key] instanceof Closure && !in_array($key, $excludeList, true)) {
$result .= sprintf(
'$GLOBALS[\'%s\'] = %s;' . "\n",
$key,
self::exportVariable($GLOBALS[$key])
);
}
}
return $result;
}
private static function exportVariable($variable): string
{
if (is_scalar($variable) || $variable === null ||
(is_array($variable) && self::arrayOnlyContainsScalars($variable))) {
return var_export($variable, true);
}
return 'unserialize(' . var_export(serialize($variable), true) . ')';
}
private static function arrayOnlyContainsScalars(array $array): bool
{
$result = true;
foreach ($array as $element) {
if (is_array($element)) {
$result = self::arrayOnlyContainsScalars($element);
} elseif (!is_scalar($element) && $element !== null) {
$result = false;
}
if (!$result) {
break;
}
}
return $result;
}
}
PK %ZǵNd Nd phpunit/src/Util/Test.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use const PHP_OS;
use const PHP_VERSION;
use function addcslashes;
use function array_flip;
use function array_key_exists;
use function array_merge;
use function array_unique;
use function array_unshift;
use function class_exists;
use function count;
use function explode;
use function extension_loaded;
use function function_exists;
use function get_class;
use function ini_get;
use function interface_exists;
use function is_array;
use function is_int;
use function method_exists;
use function phpversion;
use function preg_match;
use function preg_replace;
use function sprintf;
use function strncmp;
use function strpos;
use function strtolower;
use function trim;
use function version_compare;
use PHPUnit\Framework\CodeCoverageException;
use PHPUnit\Framework\ExecutionOrderDependency;
use PHPUnit\Framework\InvalidCoversTargetException;
use PHPUnit\Framework\SelfDescribing;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Warning;
use PHPUnit\Runner\Version;
use PHPUnit\Util\Annotation\Registry;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
use SebastianBergmann\CodeUnit\CodeUnitCollection;
use SebastianBergmann\CodeUnit\InvalidCodeUnitException;
use SebastianBergmann\CodeUnit\Mapper;
use SebastianBergmann\Environment\OperatingSystem;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Test
{
/**
* @var int
*/
public const UNKNOWN = -1;
/**
* @var int
*/
public const SMALL = 0;
/**
* @var int
*/
public const MEDIUM = 1;
/**
* @var int
*/
public const LARGE = 2;
/**
* @var array
*/
private static $hookMethods = [];
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function describe(\PHPUnit\Framework\Test $test): array
{
if ($test instanceof TestCase) {
return [get_class($test), $test->getName()];
}
if ($test instanceof SelfDescribing) {
return ['', $test->toString()];
}
return ['', get_class($test)];
}
public static function describeAsString(\PHPUnit\Framework\Test $test): string
{
if ($test instanceof SelfDescribing) {
return $test->toString();
}
return get_class($test);
}
/**
* @throws CodeCoverageException
*
* @return array|bool
*
* @psalm-param class-string $className
*/
public static function getLinesToBeCovered(string $className, string $methodName)
{
$annotations = self::parseTestMethodAnnotations(
$className,
$methodName
);
if (!self::shouldCoversAnnotationBeUsed($annotations)) {
return false;
}
return self::getLinesToBeCoveredOrUsed($className, $methodName, 'covers');
}
/**
* Returns lines of code specified with the @uses annotation.
*
* @throws CodeCoverageException
*
* @psalm-param class-string $className
*/
public static function getLinesToBeUsed(string $className, string $methodName): array
{
return self::getLinesToBeCoveredOrUsed($className, $methodName, 'uses');
}
public static function requiresCodeCoverageDataCollection(TestCase $test): bool
{
$annotations = self::parseTestMethodAnnotations(
get_class($test),
$test->getName(false)
);
// If there is no @covers annotation but a @coversNothing annotation on
// the test method then code coverage data does not need to be collected
if (isset($annotations['method']['coversNothing'])) {
// @see https://github.com/sebastianbergmann/phpunit/issues/4947#issuecomment-1084480950
// return false;
}
// If there is at least one @covers annotation then
// code coverage data needs to be collected
if (isset($annotations['method']['covers'])) {
return true;
}
// If there is no @covers annotation but a @coversNothing annotation
// then code coverage data does not need to be collected
if (isset($annotations['class']['coversNothing'])) {
// @see https://github.com/sebastianbergmann/phpunit/issues/4947#issuecomment-1084480950
// return false;
}
// If there is no @coversNothing annotation then
// code coverage data may be collected
return true;
}
/**
* @throws Exception
*
* @psalm-param class-string $className
*/
public static function getRequirements(string $className, string $methodName): array
{
return self::mergeArraysRecursively(
Registry::getInstance()->forClassName($className)->requirements(),
Registry::getInstance()->forMethod($className, $methodName)->requirements()
);
}
/**
* Returns the missing requirements for a test.
*
* @throws Exception
* @throws Warning
*
* @psalm-param class-string $className
*/
public static function getMissingRequirements(string $className, string $methodName): array
{
$required = self::getRequirements($className, $methodName);
$missing = [];
$hint = null;
if (!empty($required['PHP'])) {
$operator = new VersionComparisonOperator(empty($required['PHP']['operator']) ? '>=' : $required['PHP']['operator']);
if (!version_compare(PHP_VERSION, $required['PHP']['version'], $operator->asString())) {
$missing[] = sprintf('PHP %s %s is required.', $operator->asString(), $required['PHP']['version']);
$hint = 'PHP';
}
} elseif (!empty($required['PHP_constraint'])) {
$version = new \PharIo\Version\Version(self::sanitizeVersionNumber(PHP_VERSION));
if (!$required['PHP_constraint']['constraint']->complies($version)) {
$missing[] = sprintf(
'PHP version does not match the required constraint %s.',
$required['PHP_constraint']['constraint']->asString()
);
$hint = 'PHP_constraint';
}
}
if (!empty($required['PHPUnit'])) {
$phpunitVersion = Version::id();
$operator = new VersionComparisonOperator(empty($required['PHPUnit']['operator']) ? '>=' : $required['PHPUnit']['operator']);
if (!version_compare($phpunitVersion, $required['PHPUnit']['version'], $operator->asString())) {
$missing[] = sprintf('PHPUnit %s %s is required.', $operator->asString(), $required['PHPUnit']['version']);
$hint = $hint ?? 'PHPUnit';
}
} elseif (!empty($required['PHPUnit_constraint'])) {
$phpunitVersion = new \PharIo\Version\Version(self::sanitizeVersionNumber(Version::id()));
if (!$required['PHPUnit_constraint']['constraint']->complies($phpunitVersion)) {
$missing[] = sprintf(
'PHPUnit version does not match the required constraint %s.',
$required['PHPUnit_constraint']['constraint']->asString()
);
$hint = $hint ?? 'PHPUnit_constraint';
}
}
if (!empty($required['OSFAMILY']) && $required['OSFAMILY'] !== (new OperatingSystem)->getFamily()) {
$missing[] = sprintf('Operating system %s is required.', $required['OSFAMILY']);
$hint = $hint ?? 'OSFAMILY';
}
if (!empty($required['OS'])) {
$requiredOsPattern = sprintf('/%s/i', addcslashes($required['OS'], '/'));
if (!preg_match($requiredOsPattern, PHP_OS)) {
$missing[] = sprintf('Operating system matching %s is required.', $requiredOsPattern);
$hint = $hint ?? 'OS';
}
}
if (!empty($required['functions'])) {
foreach ($required['functions'] as $function) {
$pieces = explode('::', $function);
if (count($pieces) === 2 && class_exists($pieces[0]) && method_exists($pieces[0], $pieces[1])) {
continue;
}
if (function_exists($function)) {
continue;
}
$missing[] = sprintf('Function %s is required.', $function);
$hint = $hint ?? 'function_' . $function;
}
}
if (!empty($required['setting'])) {
foreach ($required['setting'] as $setting => $value) {
if (ini_get($setting) !== $value) {
$missing[] = sprintf('Setting "%s" must be "%s".', $setting, $value);
$hint = $hint ?? '__SETTING_' . $setting;
}
}
}
if (!empty($required['extensions'])) {
foreach ($required['extensions'] as $extension) {
if (isset($required['extension_versions'][$extension])) {
continue;
}
if (!extension_loaded($extension)) {
$missing[] = sprintf('Extension %s is required.', $extension);
$hint = $hint ?? 'extension_' . $extension;
}
}
}
if (!empty($required['extension_versions'])) {
foreach ($required['extension_versions'] as $extension => $req) {
$actualVersion = phpversion($extension);
$operator = new VersionComparisonOperator(empty($req['operator']) ? '>=' : $req['operator']);
if ($actualVersion === false || !version_compare($actualVersion, $req['version'], $operator->asString())) {
$missing[] = sprintf('Extension %s %s %s is required.', $extension, $operator->asString(), $req['version']);
$hint = $hint ?? 'extension_' . $extension;
}
}
}
if ($hint && isset($required['__OFFSET'])) {
array_unshift($missing, '__OFFSET_FILE=' . $required['__OFFSET']['__FILE']);
array_unshift($missing, '__OFFSET_LINE=' . ($required['__OFFSET'][$hint] ?? 1));
}
return $missing;
}
/**
* Returns the provided data for a method.
*
* @throws Exception
*
* @psalm-param class-string $className
*/
public static function getProvidedData(string $className, string $methodName): ?array
{
return Registry::getInstance()->forMethod($className, $methodName)->getProvidedData();
}
/**
* @psalm-param class-string $className
*/
public static function parseTestMethodAnnotations(string $className, ?string $methodName = null): array
{
$registry = Registry::getInstance();
if ($methodName !== null) {
try {
return [
'method' => $registry->forMethod($className, $methodName)->symbolAnnotations(),
'class' => $registry->forClassName($className)->symbolAnnotations(),
];
} catch (Exception $methodNotFound) {
// ignored
}
}
return [
'method' => null,
'class' => $registry->forClassName($className)->symbolAnnotations(),
];
}
/**
* @psalm-param class-string $className
*/
public static function getInlineAnnotations(string $className, string $methodName): array
{
return Registry::getInstance()->forMethod($className, $methodName)->getInlineAnnotations();
}
/** @psalm-param class-string $className */
public static function getBackupSettings(string $className, string $methodName): array
{
return [
'backupGlobals' => self::getBooleanAnnotationSetting(
$className,
$methodName,
'backupGlobals'
),
'backupStaticAttributes' => self::getBooleanAnnotationSetting(
$className,
$methodName,
'backupStaticAttributes'
),
];
}
/**
* @psalm-param class-string $className
*
* @return ExecutionOrderDependency[]
*/
public static function getDependencies(string $className, string $methodName): array
{
$annotations = self::parseTestMethodAnnotations(
$className,
$methodName
);
$dependsAnnotations = $annotations['class']['depends'] ?? [];
if (isset($annotations['method']['depends'])) {
$dependsAnnotations = array_merge(
$dependsAnnotations,
$annotations['method']['depends']
);
}
// Normalize dependency name to className::methodName
$dependencies = [];
foreach ($dependsAnnotations as $value) {
$dependencies[] = ExecutionOrderDependency::createFromDependsAnnotation($className, $value);
}
return array_unique($dependencies);
}
/** @psalm-param class-string $className */
public static function getGroups(string $className, ?string $methodName = ''): array
{
$annotations = self::parseTestMethodAnnotations(
$className,
$methodName
);
$groups = [];
if (isset($annotations['method']['author'])) {
$groups[] = $annotations['method']['author'];
} elseif (isset($annotations['class']['author'])) {
$groups[] = $annotations['class']['author'];
}
if (isset($annotations['class']['group'])) {
$groups[] = $annotations['class']['group'];
}
if (isset($annotations['method']['group'])) {
$groups[] = $annotations['method']['group'];
}
if (isset($annotations['class']['ticket'])) {
$groups[] = $annotations['class']['ticket'];
}
if (isset($annotations['method']['ticket'])) {
$groups[] = $annotations['method']['ticket'];
}
foreach (['method', 'class'] as $element) {
foreach (['small', 'medium', 'large'] as $size) {
if (isset($annotations[$element][$size])) {
$groups[] = [$size];
break 2;
}
}
}
foreach (['method', 'class'] as $element) {
if (isset($annotations[$element]['covers'])) {
foreach ($annotations[$element]['covers'] as $coversTarget) {
$groups[] = ['__phpunit_covers_' . self::canonicalizeName($coversTarget)];
}
}
if (isset($annotations[$element]['uses'])) {
foreach ($annotations[$element]['uses'] as $usesTarget) {
$groups[] = ['__phpunit_uses_' . self::canonicalizeName($usesTarget)];
}
}
}
return array_unique(array_merge([], ...$groups));
}
/** @psalm-param class-string $className */
public static function getSize(string $className, ?string $methodName): int
{
$groups = array_flip(self::getGroups($className, $methodName));
if (isset($groups['large'])) {
return self::LARGE;
}
if (isset($groups['medium'])) {
return self::MEDIUM;
}
if (isset($groups['small'])) {
return self::SMALL;
}
return self::UNKNOWN;
}
/** @psalm-param class-string $className */
public static function getProcessIsolationSettings(string $className, string $methodName): bool
{
$annotations = self::parseTestMethodAnnotations(
$className,
$methodName
);
return isset($annotations['class']['runTestsInSeparateProcesses']) || isset($annotations['method']['runInSeparateProcess']);
}
/** @psalm-param class-string $className */
public static function getClassProcessIsolationSettings(string $className, string $methodName): bool
{
$annotations = self::parseTestMethodAnnotations(
$className,
$methodName
);
return isset($annotations['class']['runClassInSeparateProcess']);
}
/** @psalm-param class-string $className */
public static function getPreserveGlobalStateSettings(string $className, string $methodName): ?bool
{
return self::getBooleanAnnotationSetting(
$className,
$methodName,
'preserveGlobalState'
);
}
/** @psalm-param class-string $className */
public static function getHookMethods(string $className): array
{
if (!class_exists($className, false)) {
return self::emptyHookMethodsArray();
}
if (!isset(self::$hookMethods[$className])) {
self::$hookMethods[$className] = self::emptyHookMethodsArray();
try {
foreach ((new Reflection)->methodsInTestClass(new ReflectionClass($className)) as $method) {
$docBlock = Registry::getInstance()->forMethod($className, $method->getName());
if ($method->isStatic()) {
if ($docBlock->isHookToBeExecutedBeforeClass()) {
array_unshift(
self::$hookMethods[$className]['beforeClass'],
$method->getName()
);
}
if ($docBlock->isHookToBeExecutedAfterClass()) {
self::$hookMethods[$className]['afterClass'][] = $method->getName();
}
}
if ($docBlock->isToBeExecutedBeforeTest()) {
array_unshift(
self::$hookMethods[$className]['before'],
$method->getName()
);
}
if ($docBlock->isToBeExecutedAsPreCondition()) {
array_unshift(
self::$hookMethods[$className]['preCondition'],
$method->getName()
);
}
if ($docBlock->isToBeExecutedAsPostCondition()) {
self::$hookMethods[$className]['postCondition'][] = $method->getName();
}
if ($docBlock->isToBeExecutedAfterTest()) {
self::$hookMethods[$className]['after'][] = $method->getName();
}
}
} catch (ReflectionException $e) {
}
}
return self::$hookMethods[$className];
}
public static function isTestMethod(ReflectionMethod $method): bool
{
if (!$method->isPublic()) {
return false;
}
if (strpos($method->getName(), 'test') === 0) {
return true;
}
return array_key_exists(
'test',
Registry::getInstance()->forMethod(
$method->getDeclaringClass()->getName(),
$method->getName()
)
->symbolAnnotations()
);
}
/**
* @throws CodeCoverageException
*
* @psalm-param class-string $className
*/
private static function getLinesToBeCoveredOrUsed(string $className, string $methodName, string $mode): array
{
$annotations = self::parseTestMethodAnnotations(
$className,
$methodName
);
$classShortcut = null;
if (!empty($annotations['class'][$mode . 'DefaultClass'])) {
if (count($annotations['class'][$mode . 'DefaultClass']) > 1) {
throw new CodeCoverageException(
sprintf(
'More than one @%sClass annotation in class or interface "%s".',
$mode,
$className
)
);
}
$classShortcut = $annotations['class'][$mode . 'DefaultClass'][0];
}
$list = $annotations['class'][$mode] ?? [];
if (isset($annotations['method'][$mode])) {
$list = array_merge($list, $annotations['method'][$mode]);
}
$codeUnits = CodeUnitCollection::fromArray([]);
$mapper = new Mapper;
foreach (array_unique($list) as $element) {
if ($classShortcut && strncmp($element, '::', 2) === 0) {
$element = $classShortcut . $element;
}
$element = preg_replace('/[\s()]+$/', '', $element);
$element = explode(' ', $element);
$element = $element[0];
if ($mode === 'covers' && interface_exists($element)) {
throw new InvalidCoversTargetException(
sprintf(
'Trying to @cover interface "%s".',
$element
)
);
}
try {
$codeUnits = $codeUnits->mergeWith($mapper->stringToCodeUnits($element));
} catch (InvalidCodeUnitException $e) {
throw new InvalidCoversTargetException(
sprintf(
'"@%s %s" is invalid',
$mode,
$element
),
$e->getCode(),
$e
);
}
}
return $mapper->codeUnitsToSourceLines($codeUnits);
}
private static function emptyHookMethodsArray(): array
{
return [
'beforeClass' => ['setUpBeforeClass'],
'before' => ['setUp'],
'preCondition' => ['assertPreConditions'],
'postCondition' => ['assertPostConditions'],
'after' => ['tearDown'],
'afterClass' => ['tearDownAfterClass'],
];
}
/** @psalm-param class-string $className */
private static function getBooleanAnnotationSetting(string $className, ?string $methodName, string $settingName): ?bool
{
$annotations = self::parseTestMethodAnnotations(
$className,
$methodName
);
if (isset($annotations['method'][$settingName])) {
if ($annotations['method'][$settingName][0] === 'enabled') {
return true;
}
if ($annotations['method'][$settingName][0] === 'disabled') {
return false;
}
}
if (isset($annotations['class'][$settingName])) {
if ($annotations['class'][$settingName][0] === 'enabled') {
return true;
}
if ($annotations['class'][$settingName][0] === 'disabled') {
return false;
}
}
return null;
}
/**
* Trims any extensions from version string that follows after
* the .[.] format.
*/
private static function sanitizeVersionNumber(string $version)
{
return preg_replace(
'/^(\d+\.\d+(?:.\d+)?).*$/',
'$1',
$version
);
}
private static function shouldCoversAnnotationBeUsed(array $annotations): bool
{
if (isset($annotations['method']['coversNothing'])) {
return false;
}
if (isset($annotations['method']['covers'])) {
return true;
}
if (isset($annotations['class']['coversNothing'])) {
return false;
}
return true;
}
/**
* Merge two arrays together.
*
* If an integer key exists in both arrays and preserveNumericKeys is false, the value
* from the second array will be appended to the first array. If both values are arrays, they
* are merged together, else the value of the second array overwrites the one of the first array.
*
* This implementation is copied from https://github.com/zendframework/zend-stdlib/blob/76b653c5e99b40eccf5966e3122c90615134ae46/src/ArrayUtils.php
*
* Zend Framework (http://framework.zend.com/)
*
* @see http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
private static function mergeArraysRecursively(array $a, array $b): array
{
foreach ($b as $key => $value) {
if (array_key_exists($key, $a)) {
if (is_int($key)) {
$a[] = $value;
} elseif (is_array($value) && is_array($a[$key])) {
$a[$key] = self::mergeArraysRecursively($a[$key], $value);
} else {
$a[$key] = $value;
}
} else {
$a[$key] = $value;
}
}
return $a;
}
private static function canonicalizeName(string $name): string
{
return strtolower(trim($name, '\\'));
}
}
PK %Z.2 phpunit/src/Util/Exception.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use RuntimeException;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Exception extends RuntimeException implements \PHPUnit\Exception
{
}
PK %Z̹}-_
_
phpunit/src/Util/Filter.phpnu [
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util;
use function array_unshift;
use function defined;
use function in_array;
use function is_file;
use function realpath;
use function sprintf;
use function strpos;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\SyntheticError;
use Throwable;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Filter
{
/**
* @throws Exception
*/
public static function getFilteredStacktrace(Throwable $t): string
{
$filteredStacktrace = '';
if ($t instanceof SyntheticError) {
$eTrace = $t->getSyntheticTrace();
$eFile = $t->getSyntheticFile();
$eLine = $t->getSyntheticLine();
} elseif ($t instanceof Exception) {
$eTrace = $t->getSerializableTrace();
$eFile = $t->getFile();
$eLine = $t->getLine();
} else {
if ($t->getPrevious()) {
$t = $t->getPrevious();
}
$eTrace = $t->getTrace();
$eFile = $t->getFile();
$eLine = $t->getLine();
}
if (!self::frameExists($eTrace, $eFile, $eLine)) {
array_unshift(
$eTrace,
['file' => $eFile, 'line' => $eLine]
);
}
$prefix = defined('__PHPUNIT_PHAR_ROOT__') ? __PHPUNIT_PHAR_ROOT__ : false;
$excludeList = new ExcludeList;
foreach ($eTrace as $frame) {
if (self::shouldPrintFrame($frame, $prefix, $excludeList)) {
$filteredStacktrace .= sprintf(
"%s:%s\n",
$frame['file'],
$frame['line'] ?? '?'
);
}
}
return $filteredStacktrace;
}
private static function shouldPrintFrame(array $frame, $prefix, ExcludeList $excludeList): bool
{
if (!isset($frame['file'])) {
return false;
}
$file = $frame['file'];
$fileIsNotPrefixed = $prefix === false || strpos($file, $prefix) !== 0;
// @see https://github.com/sebastianbergmann/phpunit/issues/4033
if (isset($GLOBALS['_SERVER']['SCRIPT_NAME'])) {
$script = realpath($GLOBALS['_SERVER']['SCRIPT_NAME']);
} else {
$script = '';
}
return is_file($file) &&
self::fileIsExcluded($file, $excludeList) &&
$fileIsNotPrefixed &&
$file !== $script;
}
private static function fileIsExcluded(string $file, ExcludeList $excludeList): bool
{
return (empty($GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST']) ||
!in_array($file, $GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST'], true)) &&
!$excludeList->isExcluded($file);
}
private static function frameExists(array $trace, string $file, int $line): bool
{
foreach ($trace as $frame) {
if (isset($frame['file'], $frame['line']) && $frame['file'] === $file && $frame['line'] === $line) {
return true;
}
}
return false;
}
}
PK %Z#4 &