structure tests: allow PHP 8.1 syntax and autoload enums
Change-Id: I0069df20fbc7ee46c7dc177e5bf352434b8abf32 (cherry picked from commit 12c9e516a2a42d399f5d51f6ba1b162ba68f4894)
This commit is contained in:
parent
82d3f6ac64
commit
ed94cc0b64
5 changed files with 12 additions and 5 deletions
|
|
@ -20,7 +20,8 @@
|
|||
|
||||
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
|
||||
|
||||
// This value should match the PHP version specified in composer.json and PHPVersionCheck.php.
|
||||
// This value should match the PHP version specified in composer.json,
|
||||
// PHPVersionCheck.php, and ScopeStructureTest.php
|
||||
$cfg['minimum_target_php_version'] = '8.1.0';
|
||||
|
||||
$cfg['file_list'] = array_merge(
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ class PHPVersionCheck {
|
|||
* Displays an error, if the installed PHP version does not meet the minimum requirement.
|
||||
*/
|
||||
function checkRequiredPHPVersion() {
|
||||
// This value should match the PHP version specified in composer.json,
|
||||
// .phan/config.php, and ScopeStructureTest.php
|
||||
$minimumVersion = '8.1.0';
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class ClassCollector {
|
|||
$matches = null;
|
||||
preg_match_all(
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
'#^\t*(?:namespace |(final )?(abstract )?(class|interface|trait) |class_alias\()[^;{]+[;{]\s*\}?#m',
|
||||
'#^\t*(?:namespace |(final )?(abstract )?(class|interface|trait|enum) |class_alias\()[^;{]+[;{]\s*\}?#m',
|
||||
$code,
|
||||
$matches
|
||||
);
|
||||
|
|
@ -109,6 +109,7 @@ class ClassCollector {
|
|||
switch ( $token[0] ) {
|
||||
case T_NAMESPACE:
|
||||
case T_CLASS:
|
||||
case T_ENUM:
|
||||
case T_INTERFACE:
|
||||
case T_TRAIT:
|
||||
case T_DOUBLE_COLON:
|
||||
|
|
@ -204,6 +205,7 @@ class ClassCollector {
|
|||
break;
|
||||
|
||||
case T_CLASS:
|
||||
case T_ENUM:
|
||||
case T_INTERFACE:
|
||||
case T_TRAIT:
|
||||
$this->tokens[] = $token;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class AutoLoaderStructureTest extends MediaWikiIntegrationTestCase {
|
|||
$matches = [];
|
||||
preg_match_all( '/
|
||||
^ [\t ]* (?:
|
||||
(?:final\s+)? (?:abstract\s+)? (?:class|interface|trait) \s+
|
||||
(?:final\s+)? (?:abstract\s+)? (?:class|interface|trait|enum) \s+
|
||||
(?P<class> \w+)
|
||||
|
|
||||
class_alias \s* \( \s*
|
||||
|
|
|
|||
|
|
@ -30,8 +30,10 @@ class ScopeStructureTest extends MediaWikiIntegrationTestCase {
|
|||
* @dataProvider provideAutoloadNoFileScope
|
||||
*/
|
||||
public function testAutoloadNoFileScope( $file ) {
|
||||
$parser = ( new ParserFactory )
|
||||
->createForVersion( PhpVersion::fromComponents( 7, 0 ) );
|
||||
// This value should match the PHP version specified in composer.json,
|
||||
// PHPVersionCheck.php, and .phan/config.php
|
||||
$version = PhpVersion::fromComponents( 8, 1 );
|
||||
$parser = ( new ParserFactory )->createForVersion( $version );
|
||||
$ast = $parser->parse( file_get_contents( $file ) );
|
||||
foreach ( $ast as $node ) {
|
||||
if ( $node instanceof Stmt\ClassLike
|
||||
|
|
|
|||
Loading…
Reference in a new issue