Skip to content

Commit

Permalink
Merge branch '10.0' into separate_local_from_global_state
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann authored Mar 18, 2023
2 parents ad1eb97 + 176f4ae commit 7bb52b7
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 54 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
extensions: none, iconv, json, phar, tokenizer
coverage: none
tools: none
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
extensions: none, ctype, curl, date, dom, json, libxml, mbstring, phar, simplexml, soap, tokenizer, xml, xmlwriter, zlib
coverage: none
tools: none
Expand Down Expand Up @@ -190,7 +190,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: pcov
extensions: none, curl, dom, json, libxml, mbstring, phar, soap, tokenizer, xml, xmlwriter
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
Expand Down Expand Up @@ -226,7 +226,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: none
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_VALUES }}
Expand Down
2 changes: 1 addition & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpab" version="^1.25" installed="1.27.2" location="./tools/phpab" copy="true"/>
<phar name="php-cs-fixer" version="^3.0" installed="3.14.4" location="./tools/php-cs-fixer" copy="true"/>
<phar name="php-cs-fixer" version="^3.0" installed="3.15.1" location="./tools/php-cs-fixer" copy="true"/>
<phar name="psalm" version="^5.0" installed="5.8.0" location="./tools/psalm" copy="true"/>
<phar name="humbug/php-scoper" version="^0.18.1" installed="0.18.2" location="./tools/php-scoper" copy="true"/>
<phar name="composer" version="^2.0.3" installed="2.5.4" location="./tools/composer" copy="true"/>
Expand Down
5 changes: 3 additions & 2 deletions ChangeLog-10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes of the PHPUnit 10.0 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.

## [10.0.16] - 2023-MM-DD
## [10.0.16] - 2023-03-13

### Added

Expand All @@ -15,6 +15,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
### Fixed

* [#5278](https://github.com/sebastianbergmann/phpunit/issues/5278): Test Runner swallows output made during test
* [#5279](https://github.com/sebastianbergmann/phpunit/pull/5279): `StringContains` constraint does not correctly handle option for ignoring line endings

## [10.0.15] - 2023-03-09

Expand Down Expand Up @@ -260,7 +261,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
* PHP 7.3, PHP 7.4, and PHP 8.0 are no longer supported
* `phpunit/php-code-coverage` [no longer supports PHPDBG and Xdebug 2](https://github.com/sebastianbergmann/php-code-coverage/blob/10.0.0/ChangeLog.md#1000---2023-02-03)

[10.0.16]: https://github.com/sebastianbergmann/phpunit/compare/10.0.15...10.0
[10.0.16]: https://github.com/sebastianbergmann/phpunit/compare/10.0.15...10.0.16
[10.0.15]: https://github.com/sebastianbergmann/phpunit/compare/10.0.14...10.0.15
[10.0.14]: https://github.com/sebastianbergmann/phpunit/compare/10.0.13...10.0.14
[10.0.13]: https://github.com/sebastianbergmann/phpunit/compare/10.0.12...10.0.13
Expand Down
19 changes: 14 additions & 5 deletions build/templates/binary-phar-autoload.php.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,31 @@ if (version_compare('8.1.0', PHP_VERSION, '>')) {
die(1);
}

foreach (['dom', 'json', 'libxml', 'mbstring', 'tokenizer', 'xml', 'xmlwriter'] as $extension) {
if (extension_loaded($extension)) {
continue;
$requiredExtensions = ['dom', 'json', 'libxml', 'mbstring', 'tokenizer', 'xml', 'xmlwriter'];

$unavailableExtensions = array_filter(
$requiredExtensions,
static function ($extension) {
return !extension_loaded($extension);
}
);

if ([] !== $unavailableExtensions) {
fwrite(
STDERR,
sprintf(
'PHPUnit requires the "%s" extension.' . PHP_EOL,
$extension
'PHPUnit requires the "%s" extensions, but the "%s" %s not available.' . PHP_EOL,
count($unavailableExtensions) === 1 ? 'extension is' : 'extensions are',
implode('", "', $requiredExtensions),
implode('", "', $unavailableExtensions)
)
);

die(1);
}

unset($requiredExtensions, $unavailableExtensions);

if (__FILE__ === realpath($_SERVER['SCRIPT_NAME'])) {
$execute = true;
} else {
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
}
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues"
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy"
},
"prefer-stable": true,
"require": {
Expand Down
19 changes: 14 additions & 5 deletions phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,31 @@ if (version_compare('8.1.0', PHP_VERSION, '>')) {
die(1);
}

foreach (['dom', 'json', 'libxml', 'mbstring', 'tokenizer', 'xml', 'xmlwriter'] as $extension) {
if (extension_loaded($extension)) {
continue;
$requiredExtensions = ['dom', 'json', 'libxml', 'mbstring', 'tokenizer', 'xml', 'xmlwriter'];

$unavailableExtensions = array_filter(
$requiredExtensions,
static function ($extension) {
return !extension_loaded($extension);
}
);

if ([] !== $unavailableExtensions) {
fwrite(
STDERR,
sprintf(
'PHPUnit requires the "%s" extension.' . PHP_EOL,
$extension
'PHPUnit requires the "%s" extensions, but the "%s" %s not available.' . PHP_EOL,
count($unavailableExtensions) === 1 ? 'extension is' : 'extensions are',
implode('", "', $requiredExtensions),
implode('", "', $unavailableExtensions)
)
);

die(1);
}

unset($requiredExtensions, $unavailableExtensions);

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Value/Test/TestMethodBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function fromTestCase(TestCase $testCase): TestMethod
$location['file'],
$location['line'],
TestDoxBuilder::fromTestCase($testCase),
MetadataRegistry::parser()->for($testCase::class, $methodName),
MetadataRegistry::parser()->forClassAndMethod($testCase::class, $methodName),
self::dataFor($testCase),
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Framework/Constraint/String/StringContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ final class StringContains extends Constraint

public function __construct(string $string, bool $ignoreCase = false, bool $ignoreLineEndings = false)
{
if ($ignoreLineEndings) {
$string = $this->normalizeLineEndings($string);
}

$this->string = $string;
$this->ignoreCase = $ignoreCase;
$this->ignoreLineEndings = $ignoreLineEndings;
Expand All @@ -43,10 +47,6 @@ public function toString(): string
$string = mb_strtolower($this->string, 'UTF-8');
}

if ($this->ignoreLineEndings) {
$string = $this->normalizeLineEndings($string);
}

return sprintf(
'contains "%s"',
$string
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function fromClassReflector(ReflectionClass $class): static
return $testSuite;
}

foreach ((new Reflection)->publicMethodsInTestClass($class) as $method) {
foreach (Reflection::publicMethodsInTestClass($class) as $method) {
if ($method->getDeclaringClass()->getName() === Assert::class) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Api/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private function valueObjectForTestMethodWithoutTestData(string $className, stri
$className,
$methodName
),
MetadataRegistry::parser()->for(
MetadataRegistry::parser()->forClassAndMethod(
$className,
$methodName
),
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Api/HookMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function hookMethods(string $className): array

self::$hookMethods[$className] = self::emptyHookMethodsArray();

foreach ((new Reflection)->methodsInTestClass(new ReflectionClass($className)) as $method) {
foreach (Reflection::methodsInTestClass(new ReflectionClass($className)) as $method) {
$methodName = $method->getName();

assert(!empty($methodName));
Expand Down
19 changes: 0 additions & 19 deletions src/Metadata/Parser/CachingParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/
namespace PHPUnit\Metadata\Parser;

use function class_exists;
use function method_exists;
use PHPUnit\Metadata\MetadataCollection;

/**
Expand Down Expand Up @@ -77,21 +75,4 @@ public function forClassAndMethod(string $className, string $methodName): Metada

return $this->classAndMethodCache[$key];
}

/**
* @psalm-param class-string $className
* @psalm-param non-empty-string $methodName
*/
public function for(string $className, string $methodName): MetadataCollection
{
if (!class_exists($className)) {
return MetadataCollection::fromArray([]);
}

if (method_exists($className, $methodName)) {
return $this->forClassAndMethod($className, $methodName);
}

return $this->forClass($className);
}
}
6 changes: 3 additions & 3 deletions src/Metadata/Parser/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
final class Registry
{
private static ?CachingParser $instance = null;
private static ?Parser $instance = null;

public static function parser(): CachingParser
public static function parser(): Parser
{
return self::$instance ?? self::$instance = self::build();
}
Expand All @@ -28,7 +28,7 @@ private function __construct()
{
}

private static function build(): CachingParser
private static function build(): Parser
{
return new CachingParser(
new ParserChain(
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function id(): string
}

if (self::$version === '') {
self::$version = (new VersionId('10.0.15', dirname(__DIR__, 2)))->asString();
self::$version = (new VersionId('10.0.16', dirname(__DIR__, 2)))->asString();
}

return self::$version;
Expand Down
10 changes: 5 additions & 5 deletions src/Util/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ public static function sourceLocationFor(string $className, string $methodName):
/**
* @psalm-return list<ReflectionMethod>
*/
public function publicMethodsInTestClass(ReflectionClass $class): array
public static function publicMethodsInTestClass(ReflectionClass $class): array
{
return $this->filterMethods($class, ReflectionMethod::IS_PUBLIC);
return self::filterMethods($class, ReflectionMethod::IS_PUBLIC);
}

/**
* @psalm-return list<ReflectionMethod>
*/
public function methodsInTestClass(ReflectionClass $class): array
public static function methodsInTestClass(ReflectionClass $class): array
{
return $this->filterMethods($class, null);
return self::filterMethods($class, null);
}

/**
* @psalm-return list<ReflectionMethod>
*/
private function filterMethods(ReflectionClass $class, ?int $filter): array
private static function filterMethods(ReflectionClass $class, ?int $filter): array
{
$methods = [];

Expand Down
27 changes: 27 additions & 0 deletions tests/unit/Framework/Constraint/String/StringContainsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public static function provider(): array
'prefix SUBSTRING suffix',
],

[
true,
'',
true,
false,
'SUBSTRING',
'prefix substring suffix',
],

[
true,
'',
Expand All @@ -68,6 +77,24 @@ public static function provider(): array
"prefix substring\r\n suffix",
],

[
true,
'',
false,
true,
"substring\r suffix",
"prefix substring\n suffix",
],

[
true,
'',
false,
true,
"substring\r\n suffix",
"prefix substring\r suffix",
],

[
true,
'',
Expand Down
Loading

0 comments on commit 7bb52b7

Please sign in to comment.