Skip to content

Commit 049675e

Browse files
committed
Working version on PHPUnit 9
1 parent 8ee6f49 commit 049675e

File tree

4 files changed

+33
-70
lines changed

4 files changed

+33
-70
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
}
1414
],
1515
"require": {
16-
"php": "^7.2||^8.0",
17-
"phpunit/phpunit": "^6.4||^7.0||^8.0||^9.0",
16+
"php": "^7.4||^8.0",
17+
"phpunit/phpunit": "^9.0",
1818
"symfony/console": "^3.4||^4.4"
1919
},
2020
"require-dev": {

phpunit.xml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
43
<!-- PHPUnit expects functional tests to be run with either a privileged user
54
or your current system user. See core/tests/README.md and
65
https://www.drupal.org/node/2116263 for details.
76
-->
8-
<phpunit bootstrap="tests/bootstrap.php" colors="true"
9-
beStrictAboutTestsThatDoNotTestAnything="true"
10-
beStrictAboutOutputDuringTests="true"
11-
beStrictAboutChangesToGlobalState="true">
7+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutChangesToGlobalState="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
8+
<coverage>
9+
<include>
10+
<directory>./src</directory>
11+
</include>
12+
<exclude>
13+
<directory suffix="Test.php">./</directory>
14+
<directory suffix="TestBase.php">./</directory>
15+
</exclude>
16+
</coverage>
1217
<php>
1318
<!-- Set error reporting to E_ALL. -->
1419
<ini name="error_reporting" value="32767"/>
@@ -20,19 +25,6 @@
2025
<testsuite name="unit">
2126
<directory>./tests/Unit</directory>
2227
</testsuite>
23-
<testsuite name="functional">
24-
<directory>./tests/Functional</directory>
25-
</testsuite>
2628
</testsuites>
2729
<!-- Filter for coverage reports. -->
28-
<filter>
29-
<whitelist>
30-
<directory>./src</directory>
31-
<!-- By definition test classes have no tests. -->
32-
<exclude>
33-
<directory suffix="Test.php">./</directory>
34-
<directory suffix="TestBase.php">./</directory>
35-
</exclude>
36-
</whitelist>
37-
</filter>
3830
</phpunit>

src/FinderCommand.php

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPUnit\TextUI\TestDirectoryNotFoundException;
88
use PHPUnit\TextUI\TestSuiteMapper;
99
use PHPUnit\TextUI\XmlConfiguration\Configuration;
10+
use PHPUnit\TextUI\XmlConfiguration\Loader;
1011
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\Input\InputArgument;
1213
use Symfony\Component\Console\Input\InputInterface;
@@ -36,45 +37,20 @@ protected function execute(InputInterface $input, OutputInterface $output) {
3637
include_once $bootstrap;
3738
$testSuites = $input->getArgument('test-suite');
3839

39-
$phpunit_9 = FALSE;
40-
if (!class_exists('\PHPUnit\Util\Configuration')) {
41-
$config = (new \PHPUnit\TextUI\XmlConfiguration\Loader())->load($configFile);
42-
$phpunit_9 = TRUE;
43-
}
44-
else {
45-
$config = \PHPUnit\Util\Configuration::getInstance($configFile);
46-
}
47-
if (empty($testSuites)) {
48-
$testSuites = $phpunit_9 ? $config->testSuite() : $config->getTestSuiteNames();
49-
}
50-
$testFilenames = [];
51-
if ($phpunit_9) {
52-
foreach (array_map(function (\PHPUnit\TextUI\XmlConfiguration\TestSuite $suite) {
53-
return $suite->name();
54-
}, iterator_to_array($testSuites)) as $name) {
55-
try {
56-
foreach ((new TestSuiteMapper())->map($testSuites, $name) as $test) {
57-
if ($test instanceof TestCase) {
58-
$testFilenames[] = ((new \ReflectionClass($test))->getFileName());
59-
}
60-
}
61-
}
62-
catch (TestDirectoryNotFoundException $e) {
63-
continue;
64-
}
40+
$config = (new Loader())->load($configFile);
41+
42+
foreach ($config->testSuite() as $suite) {
43+
if ($testSuites && !in_array($suite->name(), $testSuites, TRUE)) {
44+
continue;
6545
}
66-
}
67-
else {
68-
foreach ($testSuites as $suite) {
69-
$suite = $config->getTestSuiteConfiguration($suite);
70-
foreach (new \RecursiveIteratorIterator($suite->getIterator()) as $test) {
71-
if ($test instanceof TestCase) {
72-
$testFilenames[] = ((new \ReflectionClass($test))->getFileName());
73-
}
46+
$testSuite = (new TestSuiteMapper)->map($config->testSuite(), $suite->name());
47+
foreach (new \RecursiveIteratorIterator($testSuite) as $test) {
48+
if ($test instanceof TestCase) {
49+
$testFilenames[] = ((new \ReflectionClass($test))->getFileName());
7450
}
7551
}
76-
7752
}
53+
7854
$testFilenames = array_unique($testFilenames);
7955
foreach ($testFilenames as $testFilename) {
8056
$output->writeln($testFilename);

tests/fixtures/phpunit.xml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
32
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
43
<!-- PHPUnit expects functional tests to be run with either a privileged user
54
or your current system user. See core/tests/README.md and
65
https://www.drupal.org/node/2116263 for details.
76
-->
8-
<phpunit bootstrap="tests/bootstrap.php" colors="true"
9-
beStrictAboutTestsThatDoNotTestAnything="true"
10-
beStrictAboutOutputDuringTests="true"
11-
beStrictAboutChangesToGlobalState="true">
7+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutChangesToGlobalState="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
8+
<coverage>
9+
<include>
10+
<directory>./src</directory>
11+
</include>
12+
<exclude>
13+
<directory suffix="Test.php">./</directory>
14+
<directory suffix="TestBase.php">./</directory>
15+
</exclude>
16+
</coverage>
1217
<php>
1318
<!-- Set error reporting to E_ALL. -->
1419
<ini name="error_reporting" value="32767"/>
@@ -25,14 +30,4 @@
2530
</testsuite>
2631
</testsuites>
2732
<!-- Filter for coverage reports. -->
28-
<filter>
29-
<whitelist>
30-
<directory>./src</directory>
31-
<!-- By definition test classes have no tests. -->
32-
<exclude>
33-
<directory suffix="Test.php">./</directory>
34-
<directory suffix="TestBase.php">./</directory>
35-
</exclude>
36-
</whitelist>
37-
</filter>
3833
</phpunit>

0 commit comments

Comments
 (0)