Adjust tests to be compatible with PHPUnit 10 (#998)

This avoids warnings on PHPUnit 10, without actually
switching to PHPUnit 10.
This commit is contained in:
Jorg Adam Sowa 2024-06-03 08:24:19 +02:00 committed by GitHub
parent 7b0384cdbe
commit daaadc3bae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 59 additions and 59 deletions

View File

@ -165,7 +165,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
$this->assertEquals($expectedValueNode, $node->consts[0]->value);
}
public function provideTestDefaultValues() {
public static function provideTestDefaultValues() {
return [
[
null,

View File

@ -68,7 +68,7 @@ class EnumCaseTest extends \PHPUnit\Framework\TestCase {
$this->assertEquals($expectedValueNode, $node->expr);
}
public function provideTestDefaultValues() {
public static function provideTestDefaultValues() {
return [
[
31415,

View File

@ -30,7 +30,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
$this->assertEquals($expectedValueNode, $node->default);
}
public function provideTestDefaultValues() {
public static function provideTestDefaultValues() {
return [
[
null,
@ -107,7 +107,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
$this->assertEquals($expectedType, $type);
}
public function provideTestTypes() {
public static function provideTestTypes() {
return [
['array', new Node\Identifier('array')],
['callable', new Node\Identifier('callable')],
@ -127,7 +127,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
];
}
public function provideTestNullableTypes() {
public static function provideTestNullableTypes() {
return [
['?array', new Node\NullableType(new Node\Identifier('array'))],
['?Some\Class', new Node\NullableType(new Node\Name('Some\Class'))],
@ -142,7 +142,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
];
}
public function provideTestUnionTypes() {
public static function provideTestUnionTypes() {
return [
[
new Node\UnionType([

View File

@ -136,7 +136,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
);
}
public function provideTestDefaultValues() {
public static function provideTestDefaultValues() {
return [
[
null,

View File

@ -20,7 +20,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
$this->assertInstanceOf($className, $factory->$methodName('test'));
}
public function provideTestFactory() {
public static function provideTestFactory() {
return [
['namespace', Builder\Namespace_::class],
['class', Builder\Class_::class],

View File

@ -50,8 +50,8 @@ class CodeParsingTest extends CodeTestAbstract {
return [$stmts, canonicalize($output)];
}
public function provideTestParse() {
return $this->getTests(__DIR__ . '/../code/parser', 'test');
public static function provideTestParse() {
return self::getTests(__DIR__ . '/../code/parser', 'test');
}
private function formatErrorMessage(Error $e, $code) {

View File

@ -3,7 +3,7 @@
namespace PhpParser;
abstract class CodeTestAbstract extends \PHPUnit\Framework\TestCase {
protected function getTests($directory, $fileExtension, $chunksPerTest = 2) {
protected static function getTests($directory, $fileExtension, $chunksPerTest = 2) {
$parser = new CodeTestParser();
$allTests = [];
foreach (filesInDir($directory, $fileExtension) as $fileName => $fileContents) {

View File

@ -25,7 +25,7 @@ class CommentTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($reformattedText, $comment->getReformattedText());
}
public function provideTestReformatting() {
public static function provideTestReformatting() {
return [
['// Some text', '// Some text'],
['/* Some text */', '/* Some text */'],

View File

@ -14,7 +14,7 @@ class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($expected, $evaluator->evaluateDirectly($expr));
}
public function provideTestEvaluate() {
public static function provideTestEvaluate() {
return [
['1', 1],
['1.0', 1.0],
@ -115,7 +115,7 @@ class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase {
}
}
public function provideTestEvaluateSilently() {
public static function provideTestEvaluateSilently() {
return [
[
new Expr\BinaryOp\Mod(new Scalar\Int_(42), new Scalar\Int_(0)),

View File

@ -51,7 +51,7 @@ class ErrorTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($endColumn, $error->getEndColumn($code));
}
public function provideTestColumnInfo() {
public static function provideTestColumnInfo() {
return [
// Error at "bar"
["<?php foo bar baz", 10, 12, 11, 13],

View File

@ -36,7 +36,7 @@ class DifferTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($expectedDiffStr, $this->formatDiffString($diff));
}
public function provideTestDiff() {
public static function provideTestDiff() {
return [
['abc', 'abc', 'abc'],
['abc', 'abcdef', 'abc+d+e+f'],
@ -57,7 +57,7 @@ class DifferTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($expectedDiffStr, $this->formatDiffString($diff));
}
public function provideTestDiffWithReplacements() {
public static function provideTestDiffWithReplacements() {
return [
['abcde', 'axyze', 'a/bx/cy/dze'],
['abcde', 'xbcdy', '/axbcd/ey'],

View File

@ -30,7 +30,7 @@ PHP;
$jsonDecoder->decode($json);
}
public function provideTestDecodingError() {
public static function provideTestDecodingError() {
return [
['???', 'JSON decoding error: Syntax error'],
['{"nodeType":123}', 'Node type must be a string'],

View File

@ -89,7 +89,7 @@ class EmulativeTest extends LexerTest {
], $lexer->tokenize($code));
}
public function provideTestReplaceKeywords() {
public static function provideTestReplaceKeywords() {
return [
// PHP 8.0
['match', \T_MATCH],
@ -173,7 +173,7 @@ class EmulativeTest extends LexerTest {
$this->assertSame($expLine, $attrs['endLine']);
}
public function provideTestLexNewFeatures() {
public static function provideTestLexNewFeatures() {
return [
['yield from', [
[\T_YIELD_FROM, 'yield from'],
@ -401,7 +401,7 @@ class EmulativeTest extends LexerTest {
$this->assertSameTokens($expectedTokens, $lexer->tokenize('<?php ' . $code));
}
public function provideTestTargetVersion() {
public static function provideTestTargetVersion() {
return [
['8.0', 'match', [[\T_MATCH, 'match']]],
['7.4', 'match', [[\T_STRING, 'match']]],

View File

@ -29,7 +29,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
}
}
public function provideTestError() {
public static function provideTestError() {
return [
["<?php /*", ["Unterminated comment from 1:7 to 1:9"]],
["<?php /*\n", ["Unterminated comment from 1:7 to 2:1"]],
@ -70,7 +70,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
}
}
public function provideTestLex() {
public static function provideTestLex() {
return [
// tests PHP 8 T_NAME_* emulation
[

View File

@ -32,7 +32,7 @@ class NameContextTest extends \PHPUnit\Framework\TestCase {
);
}
public function provideTestGetPossibleNames() {
public static function provideTestGetPossibleNames() {
return [
[Use_::TYPE_NORMAL, 'Test', ['\Test']],
[Use_::TYPE_NORMAL, 'Test\Namespaced', ['\Test\Namespaced']],

View File

@ -18,7 +18,7 @@ class CallableLikeTest extends \PHPUnit\Framework\TestCase {
}
}
public function provideTestIsFirstClassCallable() {
public static function provideTestIsFirstClassCallable() {
$normalArgs = [new Arg(new Int_(1))];
$callableArgs = [new VariadicPlaceholder()];
return [

View File

@ -22,7 +22,7 @@ class IdentifierTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($expected, $identifier->isSpecialClassName());
}
public function provideTestIsSpecialClassName() {
public static function provideTestIsSpecialClassName() {
return [
['self', true],
['PARENT', true],

View File

@ -152,7 +152,7 @@ class NameTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($expected, $name->isSpecialClassName());
}
public function provideTestIsSpecialClassName() {
public static function provideTestIsSpecialClassName() {
return [
['self', true],
['PARENT', true],

View File

@ -26,7 +26,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
$this->assertTrue($node->{'is' . $modifier}());
}
public function provideModifiers() {
public static function provideModifiers() {
return [
['public'],
['protected'],

View File

@ -10,7 +10,7 @@ class MagicConstTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($name, $magicConst->getName());
}
public function provideTestGetName() {
public static function provideTestGetName() {
return [
[new MagicConst\Class_(), '__CLASS__'],
[new MagicConst\Dir(), '__DIR__'],

View File

@ -42,7 +42,7 @@ class StringTest extends \PHPUnit\Framework\TestCase {
);
}
public function provideTestParseEscapeSequences() {
public static function provideTestParseEscapeSequences() {
return [
['"', '\\"', '"'],
['\\"', '\\"', '`'],
@ -57,7 +57,7 @@ class StringTest extends \PHPUnit\Framework\TestCase {
];
}
public function provideTestParse() {
public static function provideTestParse() {
$tests = [
['A', '\'A\''],
['A', 'b\'A\''],
@ -67,7 +67,7 @@ class StringTest extends \PHPUnit\Framework\TestCase {
['\'', '\'\\\'\''],
];
foreach ($this->provideTestParseEscapeSequences() as $i => $test) {
foreach (self::provideTestParseEscapeSequences() as $i => $test) {
// skip second and third tests, they aren't for double quotes
if ($i !== 1 && $i !== 2) {
$tests[] = [$test[0], '"' . $test[1] . '"'];

View File

@ -26,7 +26,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($node->isFinal());
}
public function provideModifiers() {
public static function provideModifiers() {
return [
['public'],
['protected'],

View File

@ -31,7 +31,7 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($node->isMagic());
}
public function provideModifiers() {
public static function provideModifiers() {
return [
['public'],
['protected'],
@ -57,7 +57,7 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
$this->assertTrue($node->isPublic(), 'Node should be implicitly public');
}
public function implicitPublicModifiers() {
public static function implicitPublicModifiers() {
return [
['abstract'],
['final'],
@ -75,7 +75,7 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
$this->assertTrue($node->isMagic(), 'Method should be magic');
}
public function provideMagics() {
public static function provideMagics() {
return [
['__construct'],
['__DESTRUCT'],

View File

@ -36,7 +36,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($node->isReadonly());
}
public function provideModifiers() {
public static function provideModifiers() {
return [
['public'],
['protected'],

View File

@ -25,7 +25,7 @@ class DummyNode extends NodeAbstract {
}
class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
public function provideNodes() {
public static function provideNodes() {
$attributes = [
'startLine' => 10,
'endLine' => 11,

View File

@ -16,7 +16,7 @@ class NodeDumperTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($this->canonicalize($dump), $this->canonicalize($dumper->dump($node)));
}
public function provideTestDump() {
public static function provideTestDump() {
return [
[
[],

View File

@ -424,7 +424,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
$traverser->traverse($stmts);
}
public function provideTestInvalidReturn() {
public static function provideTestInvalidReturn() {
$num = new Node\Scalar\Int_(42);
$expr = new Node\Stmt\Expression($num);
$stmts = [$expr];

View File

@ -407,7 +407,7 @@ EOC;
$traverser->traverse([$stmt]);
}
public function provideTestError() {
public static function provideTestError() {
return [
[
new Stmt\Use_([

View File

@ -3,9 +3,9 @@
namespace PhpParser\Parser;
use PhpParser\Lexer;
use PhpParser\ParserTest;
use PhpParser\ParserTestAbstract;
class Php7Test extends ParserTest
class Php7Test extends ParserTestAbstract
{
protected function getParser(Lexer $lexer) {
return new Php7($lexer);

View File

@ -3,9 +3,9 @@
namespace PhpParser\Parser;
use PhpParser\Lexer;
use PhpParser\ParserTest;
use PhpParser\ParserTestAbstract;
class Php8Test extends ParserTest
class Php8Test extends ParserTestAbstract
{
protected function getParser(Lexer $lexer) {
return new Php8($lexer);

View File

@ -7,7 +7,7 @@ use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
abstract class ParserTest extends \PHPUnit\Framework\TestCase {
abstract class ParserTestAbstract extends \PHPUnit\Framework\TestCase {
/** @returns Parser */
abstract protected function getParser(Lexer $lexer);
@ -128,7 +128,7 @@ EOC;
}
}
public function provideTestExtraAttributes() {
public static function provideTestExtraAttributes() {
return [
['0', ['kind' => Scalar\Int_::KIND_DEC]],
['9', ['kind' => Scalar\Int_::KIND_DEC]],

View File

@ -40,12 +40,12 @@ class PrettyPrinterTest extends CodeTestAbstract {
$this->doTestPrettyPrintMethod('prettyPrintFile', $name, $code, $expected, $mode);
}
public function provideTestPrettyPrint() {
return $this->getTests(__DIR__ . '/../code/prettyPrinter', 'test');
public static function provideTestPrettyPrint() {
return self::getTests(__DIR__ . '/../code/prettyPrinter', 'test');
}
public function provideTestPrettyPrintFile() {
return $this->getTests(__DIR__ . '/../code/prettyPrinter', 'file-test');
public static function provideTestPrettyPrintFile() {
return self::getTests(__DIR__ . '/../code/prettyPrinter', 'file-test');
}
public function testPrettyPrintExpr(): void {
@ -88,7 +88,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
$this->assertSame($expected, $result);
}
public function provideTestKindAttributes() {
public static function provideTestKindAttributes() {
$nowdoc = ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR'];
$heredoc = ['kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR'];
return [
@ -144,7 +144,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
$this->assertSame($expected, $result);
}
public function provideTestUnnaturalLiterals() {
public static function provideTestUnnaturalLiterals() {
return [
[new Int_(-1), '-1'],
[new Int_(-PHP_INT_MAX - 1), '(-' . PHP_INT_MAX . '-1)'],
@ -209,8 +209,8 @@ CODE
$this->assertSame(canonicalize($expected), canonicalize($newCode), $name);
}
public function provideTestFormatPreservingPrint() {
return $this->getTests(__DIR__ . '/../code/formatPreservation', 'test', 3);
public static function provideTestFormatPreservingPrint() {
return self::getTests(__DIR__ . '/../code/formatPreservation', 'test', 3);
}
/**
@ -245,10 +245,10 @@ CODE
$this->assertSame(canonicalize($code), canonicalize($newCode), $name);
}
public function provideTestRoundTripPrint() {
public static function provideTestRoundTripPrint() {
return array_merge(
$this->getTests(__DIR__ . '/../code/prettyPrinter', 'test'),
$this->getTests(__DIR__ . '/../code/parser', 'test')
self::getTests(__DIR__ . '/../code/prettyPrinter', 'test'),
self::getTests(__DIR__ . '/../code/parser', 'test')
);
}

View File

@ -28,7 +28,7 @@ class TokenTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($isIgnorable, $token->isIgnorable());
}
public function provideTestIsIgnorable() {
public static function provideTestIsIgnorable() {
return [
[\T_STRING, 'foo', false],
[\T_WHITESPACE, ' ', true],