Skip to content

Commit 25f0f7b

Browse files
committed
Support for PHPUnit 10
1 parent cfebd69 commit 25f0f7b

File tree

7 files changed

+17
-30
lines changed

7 files changed

+17
-30
lines changed

composer.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
"php": ">=8.0 <8.3",
1616
"nikic/php-parser": "^4.13"
1717
},
18-
"config": {
19-
"platform": {
20-
"php": "8.0"
21-
}
22-
},
2318
"autoload": {
2419
"psr-4": {"PHPFUI\\PHPUnitSyntaxCoverage\\": "src/PHPFUI/PHPUnitSyntaxCoverage/"}
2520
},
21+
"autoload-dev": {
22+
"psr-4": {"badPHP\\": "tests/"}
23+
},
2624
"require-dev": {
27-
"phpunit/phpunit": ">=8.0",
25+
"phpunit/phpunit": "<11.0",
2826
"roave/security-advisories": "dev-latest",
2927
"friendsofphp/php-cs-fixer": "^3.0",
3028
"symfony/translation-contracts": ">=2.3",

src/PHPFUI/PHPUnitSyntaxCoverage/Extensions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace PHPFUI\PHPUnitSyntaxCoverage;
1414

15-
class Extensions extends \PHPUnit\Framework\TestCase implements \PHPUnit\Runner\Hook
15+
class Extensions extends \PHPUnit\Framework\TestCase
1616
{
1717
private static \PhpParser\Parser $parser;
1818

@@ -82,7 +82,7 @@ public function assertValidPHP(string $code, string $message = '') : void
8282
}
8383
catch (\Throwable $e)
8484
{
85-
throw new \PHPFUI\PHPUnitSyntaxCoverage\Exception($message . "\n" . $e->getMessage());
85+
throw new \PHPFUI\PHPUnitSyntaxCoverage\Exception($message . "\n" . $e->getMessage() . ": ReflectionClass({$class}) failed to load");
8686
}
8787
}
8888
}
@@ -182,11 +182,11 @@ public function assertValidPHPDirectory(string $directory, string $message = '',
182182
*/
183183
public function assertValidPHPFile(string $fileName, string $message = '') : void
184184
{
185-
$this->assertFileExists($fileName, $message);
185+
$this->assertFileExists($fileName, $message . ': File does not exist');
186186

187187
$code = \file_get_contents($fileName);
188188

189-
$this->assertValidPHP($code, $message);
189+
$this->assertValidPHP($code, $message . ': Not valid PHP code');
190190

191191
if (! $this->skipNamespaceTest)
192192
{

tests/UnitTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public function testDirectory() : void
1717
$this->assertValidPHPDirectory(__DIR__ . '/../src', 'src directory is not valid');
1818

1919
$this->expectException(\PHPFUI\PHPUnitSyntaxCoverage\Exception::class);
20-
$this->assertValidPHPDirectory(__DIR__ . '/badPHP', 'badPHP directory is valid (should not be)');
20+
$this->assertValidPHPDirectory(__DIR__ . '/fixtures/badPHP', 'badPHP directory is valid (should not be)');
2121
}
2222

2323
public function testInvalidExtendedClassFile() : void
2424
{
25-
$file = __DIR__ . '/badPHP/BaseClass.php';
25+
$file = __DIR__ . '/fixtures/badPHP/BaseClass.php';
2626
$this->assertValidPHPFile($file, $file . ' is invalid');
2727

28-
$file = __DIR__ . '/badPHP/BadClass.php';
28+
$file = __DIR__ . '/fixtures/badPHP/BadClass.php';
2929
$this->expectException(\PHPFUI\PHPUnitSyntaxCoverage\Exception::class);
3030
$this->assertValidPHPFile($file, $file . ' is valid (should not be)');
3131
}
@@ -47,10 +47,7 @@ public function testVendorDirectory() : void
4747
{
4848
$this->skipNamespaceTesting();
4949
// Sloppy coding from various packages causes us to have to skip directories. If only they used PHPUnitSyntaxCoverage they would have detected these issues!
50-
$this->addSkipDirectory('package-versions-deprecated'); // phpunit
51-
$this->addSkipDirectory('php-cs-fixer');
5250
$this->addSkipDirectory('DependencyInjection'); // Symfony\Component\DependencyInjection
53-
$this->addSkipDirectory('path-util'); // Webmozart\PathUtil
5451
$this->assertValidPHPDirectory(__DIR__ . '/../vendor', 'Vendor directory is not valid');
5552
}
5653
}

tests/bootstrap.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,16 @@
44

55
\ini_set('memory_limit', '-1');
66

7-
function classNameExists(string $className) : string
8-
{
9-
$path = __DIR__ . "/{$className}.php";
10-
$path = \str_replace('\\', '/', $path);
11-
12-
return \file_exists($path) ? $path : '';
13-
}
7+
\error_reporting(E_ALL);
148

15-
function autoload($className) : void
9+
// allow the autoloader to be included from any script that needs it.
10+
function autoload(string $className) : void
1611
{
17-
$path = \classNameExists($className);
12+
$path = \str_replace('\\', DIRECTORY_SEPARATOR, __DIR__ . "/fixtures/{$className}.php");
1813

19-
if ($path)
20-
{
21-
/** @noinspection PhpIncludeInspection */
22-
include $path;
23-
}
14+
@include_once $path;
2415
}
16+
2517
\spl_autoload_register('autoload');
2618

2719
require_once 'vendor/autoload.php';
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)