Compare commits

..

17 Commits

Author SHA1 Message Date
683130c2ff Release PHP-Parser 5.1.0 2024-07-01 22:03:41 +02:00
a894652a3d Fix ternary precedence printing
The precedence table set the LHS and RHS precedence for the
ternary to -1, which is the dummy value used for unary operators.
Instead, it should be the same as the operator precedence, as
the ternary is non-associative since PHP 8.

Fixes #1009.
2024-07-01 21:51:42 +02:00
3ef0811e45 Fix a typo: Dereferencable to Dereferenceable 2024-06-12 20:31:58 +02:00
db1963f9ea Fix a typo: Dereferenceing to Dereferencing 2024-06-12 20:29:11 +02:00
daaadc3bae Adjust tests to be compatible with PHPUnit 10 (#998)
This avoids warnings on PHPUnit 10, without actually
switching to PHPUnit 10.
2024-06-03 08:24:19 +02:00
7b0384cdbe [8.4] Add support for new deref without parens
RFC: https://wiki.php.net/rfc/new_without_parentheses
2024-05-31 23:07:44 +02:00
d57da64d7c Add missing void return types (#997) 2024-05-31 09:32:45 +02:00
d327cf2acf Updated actions/checkout to v4 2024-05-21 18:12:19 +02:00
c5ee33df86 Declare more precise phpdoc types (#993) 2024-04-19 21:04:10 +09:00
46be4560c4 Use PHP 8.3 for more CI jobs 2024-03-17 11:24:36 +01:00
f2e037f8ea Make phpunit fail on deprecation warnings (#989)
(cherry picked from commit 4d36e9c16f)
2024-03-17 10:06:45 +01:00
b43758e9e9 Remove PHPUnit 7 and 8
PHPUnit 9 supports all the PHP versions that we need. Also update
the PHPUnit config schema.
2024-03-17 09:31:05 +01:00
09691fc86e Prevent off-by-one errors in line-number related methods 2024-03-13 20:24:50 +01:00
139676794d Release PHP-Parser 5.0.2 2024-03-05 21:51:40 +01:00
70c96493b4 Fix indentation detection after opening tag
Fixes #982.
2024-03-02 18:59:44 +01:00
ec02613432 Update PhpVersion::getNewestSupported() to PHP 8.3 2024-03-02 08:27:21 +01:00
af14fdb282 Avoid cyclic reference in parser
Pass $this as an explicit $self argument to the reduce callbacks,
so we can make them static. This avoids a circular reference in
the parser, so that it can be immediately destroyed when it goes
out of scope.

Fixes #980.
2024-02-21 21:13:45 +01:00
81 changed files with 3800 additions and 3321 deletions

View File

@ -10,7 +10,7 @@ jobs:
name: "PHP 7.4 Unit Tests (with coverage)"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
@ -20,7 +20,7 @@ jobs:
- name: "Install dependencies"
run: |
composer require php-coveralls/php-coveralls:^2.2 --dev --no-update
composer update --no-progress --prefer-dist
COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist
- name: "Tests"
run: "php vendor/bin/phpunit --coverage-clover build/logs/clover.xml"
- name: Coveralls
@ -40,31 +40,33 @@ jobs:
- "8.3"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-file: "development"
tools: composer:v2
- name: "Install dependencies"
run: "composer update --no-progress --prefer-dist ${{ matrix.flags }}"
run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist ${{ matrix.flags }}"
- name: "PHPUnit"
run: "php vendor/bin/phpunit"
test_old_73_80:
runs-on: "ubuntu-latest"
name: "PHP 7.4 Code on PHP 8.2 Integration Tests"
name: "PHP 7.4 Code on PHP 8.3 Integration Tests"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.2"
php-version: "8.3"
ini-file: "development"
tools: composer:v2
- name: "Install PHP 8 dependencies"
run: "composer update --no-progress --prefer-dist"
run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist"
- name: "Tests"
run: "test_old/run-php-src.sh 7.4.33"
test_old_80_70:
@ -72,15 +74,16 @@ jobs:
name: "PHP 8.3 Code on PHP 7.4 Integration Tests"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "7.4"
ini-file: "development"
tools: composer:v2
- name: "Install PHP 8 dependencies"
run: "composer update --no-progress --prefer-dist"
run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist"
- name: "Tests"
run: "test_old/run-php-src.sh 8.3.0RC2"
phpstan:
@ -88,12 +91,12 @@ jobs:
name: "PHPStan"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.2"
php-version: "8.3"
tools: composer:v2
- name: "Install dependencies"
run: |
@ -105,12 +108,12 @@ jobs:
name: "PHP-CS-Fixer"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
uses: "actions/checkout@v4"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.2"
php-version: "8.3"
tools: composer:v2
- name: "Install dependencies"
run: |

View File

@ -1,3 +1,32 @@
Version 5.1.0 (2024-07-01)
--------------------------
### Added
* [8.4] Added support for dereferencing `new` expressions without parentheses.
### Fixed
* Fixed redundant parentheses being added when pretty printing ternary expressions.
### Changed
* Made some phpdoc types more precise.
Version 5.0.2 (2024-03-05)
--------------------------
### Fixed
* Fix handling of indentation on next line after opening PHP tag in formatting-preserving pretty
printer.
### Changed
* Avoid cyclic references in `Parser` objects. This means that no longer used parser objects are
immediately destroyed now, instead of requiring cycle GC.
* Update `PhpVersion::getNewestSupported()` to report PHP 8.3 instead of PHP 8.2.
Version 5.0.1 (2024-02-21)
--------------------------

View File

@ -19,7 +19,7 @@
"ext-ctype": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^9.0",
"ircmaxell/php-yacc": "^0.0.7"
},
"extra": {

View File

@ -1,7 +1,7 @@
<?php declare(strict_types=1);
$meta #
#semval($) $this->semValue
#semval($,%t) $this->semValue
#semval($) $self->semValue
#semval($,%t) $self->semValue
#semval(%n) $stackPos-(%l-%n)
#semval(%n,%t) $stackPos-(%l-%n)
@ -97,7 +97,7 @@ class #(-p) extends \PhpParser\ParserAbstract
protected function initReduceCallbacks(): void {
$this->reduceCallbacks = [
#reduce
%n => function ($stackPos) {
%n => static function ($self, $stackPos) {
%b
},
#noact

View File

@ -1069,12 +1069,21 @@ anonymous_class:
$this->checkClass($$[0], -1); }
;
new_expr:
T_NEW class_name_reference ctor_arguments { $$ = Expr\New_[$2, $3]; }
new_dereferenceable:
T_NEW class_name_reference argument_list { $$ = Expr\New_[$2, $3]; }
| T_NEW anonymous_class
{ list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; }
;
new_non_dereferenceable:
T_NEW class_name_reference { $$ = Expr\New_[$2, []]; }
;
new_expr:
new_dereferenceable
| new_non_dereferenceable
;
lexical_vars:
/* empty */ { $$ = array(); }
| T_USE '(' lexical_var_list ')' { $$ = $3; }
@ -1126,7 +1135,7 @@ class_name_reference:
class_name_or_var:
class_name
| fully_dereferencable
| fully_dereferenceable
;
exit_expr:
@ -1175,7 +1184,7 @@ array_short_syntax:
$$ = new Expr\Array_($2, $attrs); }
;
dereferencable_scalar:
dereferenceable_scalar:
T_ARRAY '(' array_pair_list ')'
{ $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG;
$$ = new Expr\Array_($3, $attrs);
@ -1192,7 +1201,7 @@ scalar:
T_LNUMBER
{ $$ = $this->parseLNumber($1, attributes(), $this->phpVersion->allowsInvalidOctals()); }
| T_DNUMBER { $$ = Scalar\Float_::fromString($1, attributes()); }
| dereferencable_scalar
| dereferenceable_scalar
| constant
| class_constant
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
@ -1208,32 +1217,34 @@ optional_expr:
| expr
;
fully_dereferencable:
fully_dereferenceable:
variable
| '(' expr ')' { $$ = $2; }
| dereferencable_scalar
| dereferenceable_scalar
| class_constant
| new_dereferenceable
;
array_object_dereferencable:
fully_dereferencable
array_object_dereferenceable:
fully_dereferenceable
| constant
;
callable_expr:
callable_variable
| '(' expr ')' { $$ = $2; }
| dereferencable_scalar
| dereferenceable_scalar
| new_dereferenceable
;
callable_variable:
simple_variable
| array_object_dereferencable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| array_object_dereferencable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| array_object_dereferenceable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| array_object_dereferenceable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| function_call
| array_object_dereferencable T_OBJECT_OPERATOR property_name argument_list
| array_object_dereferenceable T_OBJECT_OPERATOR property_name argument_list
{ $$ = Expr\MethodCall[$1, $3, $4]; }
| array_object_dereferencable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list
| array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list
{ $$ = Expr\NullsafeMethodCall[$1, $3, $4]; }
;
@ -1245,9 +1256,9 @@ optional_plain_variable:
variable:
callable_variable
| static_member
| array_object_dereferencable T_OBJECT_OPERATOR property_name
| array_object_dereferenceable T_OBJECT_OPERATOR property_name
{ $$ = Expr\PropertyFetch[$1, $3]; }
| array_object_dereferencable T_NULLSAFE_OBJECT_OPERATOR property_name
| array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name
{ $$ = Expr\NullsafePropertyFetch[$1, $3]; }
;

View File

@ -23,6 +23,7 @@ function preprocessGrammar($code) {
$code = resolveNodes($code);
$code = resolveMacros($code);
$code = resolveStackAccess($code);
$code = str_replace('$this', '$self', $code);
return $code;
}

View File

@ -46,6 +46,7 @@ class Comment implements \JsonSerializable {
* Gets the line number the comment started on.
*
* @return int Line number (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getStartLine(): int {
return $this->startLine;
@ -73,6 +74,7 @@ class Comment implements \JsonSerializable {
* Gets the line number the comment ends on.
*
* @return int Line number (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getEndLine(): int {
return $this->endLine;

View File

@ -32,6 +32,7 @@ class Error extends \RuntimeException {
* Gets the line the error starts in.
*
* @return int Error start line
* @phpstan-return -1|positive-int
*/
public function getStartLine(): int {
return $this->attributes['startLine'] ?? -1;
@ -41,6 +42,7 @@ class Error extends \RuntimeException {
* Gets the line the error ends in.
*
* @return int Error end line
* @phpstan-return -1|positive-int
*/
public function getEndLine(): int {
return $this->attributes['endLine'] ?? -1;

View File

@ -251,7 +251,7 @@ class TokenStream {
private function calcIndentMap(): array {
$indentMap = [];
$indent = 0;
foreach ($this->tokens as $token) {
foreach ($this->tokens as $i => $token) {
$indentMap[] = $indent;
if ($token->id === \T_WHITESPACE) {
@ -259,6 +259,10 @@ class TokenStream {
$newlinePos = \strrpos($content, "\n");
if (false !== $newlinePos) {
$indent = \strlen($content) - $newlinePos - 1;
} elseif ($i === 1 && $this->tokens[0]->id === \T_OPEN_TAG &&
$this->tokens[0]->text[\strlen($this->tokens[0]->text) - 1] === "\n") {
// Special case: Newline at the end of opening tag followed by whitespace.
$indent = \strlen($content);
}
}
}

View File

@ -6,6 +6,7 @@ interface Node {
/**
* Gets the type of the node.
*
* @psalm-return non-empty-string
* @return string Type of the node
*/
public function getType(): string;
@ -21,6 +22,7 @@ interface Node {
* Gets line the node started in (alias of getStartLine).
*
* @return int Start line (or -1 if not available)
* @phpstan-return -1|positive-int
*
* @deprecated Use getStartLine() instead
*/
@ -32,6 +34,7 @@ interface Node {
* Requires the 'startLine' attribute to be enabled in the lexer (enabled by default).
*
* @return int Start line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getStartLine(): int;
@ -41,6 +44,7 @@ interface Node {
* Requires the 'endLine' attribute to be enabled in the lexer (enabled by default).
*
* @return int End line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getEndLine(): int;

View File

@ -8,7 +8,10 @@ use PhpParser\NodeAbstract;
* Represents a non-namespaced name. Namespaced names are represented using Name nodes.
*/
class Identifier extends NodeAbstract {
/** @var string Identifier as string */
/**
* @psalm-var non-empty-string
* @var string Identifier as string
*/
public string $name;
/** @var array<string, bool> */
@ -25,6 +28,10 @@ class Identifier extends NodeAbstract {
* @param array<string, mixed> $attributes Additional attributes
*/
public function __construct(string $name, array $attributes = []) {
if ($name === '') {
throw new \InvalidArgumentException('Identifier name cannot be empty');
}
$this->attributes = $attributes;
$this->name = $name;
}
@ -36,6 +43,7 @@ class Identifier extends NodeAbstract {
/**
* Get identifier as string.
*
* @psalm-return non-empty-string
* @return string Identifier as string.
*/
public function toString(): string {
@ -45,6 +53,7 @@ class Identifier extends NodeAbstract {
/**
* Get lowercased identifier as string.
*
* @psalm-return non-empty-string
* @return string Lowercased identifier as string
*/
public function toLowerString(): string {
@ -63,6 +72,7 @@ class Identifier extends NodeAbstract {
/**
* Get identifier as string.
*
* @psalm-return non-empty-string
* @return string Identifier as string
*/
public function __toString(): string {

View File

@ -5,7 +5,10 @@ namespace PhpParser\Node;
use PhpParser\NodeAbstract;
class Name extends NodeAbstract {
/** @var string Name as string */
/**
* @psalm-var non-empty-string
* @var string Name as string
*/
public string $name;
/** @var array<string, bool> */
@ -33,6 +36,7 @@ class Name extends NodeAbstract {
/**
* Get parts of name (split by the namespace separator).
*
* @psalm-return non-empty-list<string>
* @return string[] Parts of name
*/
public function getParts(): array {
@ -103,6 +107,7 @@ class Name extends NodeAbstract {
* Returns a string representation of the name itself, without taking the name type into
* account (e.g., not including a leading backslash for fully qualified names).
*
* @psalm-return non-empty-string
* @return string String representation
*/
public function toString(): string {
@ -113,6 +118,7 @@ class Name extends NodeAbstract {
* Returns a string representation of the name as it would occur in code (e.g., including
* leading backslash for fully qualified names.
*
* @psalm-return non-empty-string
* @return string String representation
*/
public function toCodeString(): string {
@ -123,6 +129,7 @@ class Name extends NodeAbstract {
* Returns lowercased string representation of the name, without taking the name type into
* account (e.g., no leading backslash for fully qualified names).
*
* @psalm-return non-empty-string
* @return string Lowercased string representation
*/
public function toLowerString(): string {
@ -142,6 +149,7 @@ class Name extends NodeAbstract {
* Returns a string representation of the name by imploding the namespace parts with the
* namespace separator.
*
* @psalm-return non-empty-string
* @return string String representation
*/
public function __toString(): string {
@ -237,6 +245,7 @@ class Name extends NodeAbstract {
*
* @param string|string[]|self $name Name to prepare
*
* @psalm-return non-empty-string
* @return string Prepared name
*/
private static function prepareName($name): string {

View File

@ -19,6 +19,7 @@ abstract class NodeAbstract implements Node, \JsonSerializable {
* Gets line the node started in (alias of getStartLine).
*
* @return int Start line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getLine(): int {
return $this->attributes['startLine'] ?? -1;
@ -30,6 +31,7 @@ abstract class NodeAbstract implements Node, \JsonSerializable {
* Requires the 'startLine' attribute to be enabled in the lexer (enabled by default).
*
* @return int Start line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getStartLine(): int {
return $this->attributes['startLine'] ?? -1;
@ -41,6 +43,7 @@ abstract class NodeAbstract implements Node, \JsonSerializable {
* Requires the 'endLine' attribute to be enabled in the lexer (enabled by default).
*
* @return int End line (or -1 if not available)
* @phpstan-return -1|positive-int
*/
public function getEndLine(): int {
return $this->attributes['endLine'] ?? -1;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -318,7 +318,7 @@ abstract class ParserAbstract implements Parser {
try {
$callback = $this->reduceCallbacks[$rule];
if ($callback !== null) {
$callback($stackPos);
$callback($this, $stackPos);
} elseif ($ruleLength > 0) {
$this->semValue = $this->semStack[$stackPos - $ruleLength + 1];
}

View File

@ -43,7 +43,7 @@ class PhpVersion {
* if it is still under development.
*/
public static function getNewestSupported(): self {
return self::fromComponents(8, 2);
return self::fromComponents(8, 3);
}
/**

View File

@ -76,7 +76,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
BinaryOp\BooleanAnd::class => [120, 121, 120],
BinaryOp\BooleanOr::class => [130, 131, 130],
BinaryOp\Coalesce::class => [140, 140, 141],
Expr\Ternary::class => [150, -1, -1],
Expr\Ternary::class => [150, 150, 150],
Expr\Assign::class => [160, -1, -1],
Expr\AssignRef::class => [160, -1, -1],
AssignOp\Plus::class => [160, -1, -1],

View File

@ -4,6 +4,7 @@
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
convertDeprecationsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="./test/bootstrap.php">
<testsuites>
@ -12,9 +13,9 @@
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">./lib/PhpParser/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>

View File

@ -20,7 +20,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
return new ClassConst($name, $value);
}
public function testModifiers() {
public function testModifiers(): void {
$node = $this->createClassConstBuilder("TEST", 1)
->makePrivate()
->getNode()
@ -82,7 +82,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
);
}
public function testDocComment() {
public function testDocComment(): void {
$node = $this->createClassConstBuilder('TEST', 1)
->setDocComment('/** Test */')
->makePublic()
@ -102,7 +102,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
);
}
public function testAddConst() {
public function testAddConst(): void {
$node = $this->createClassConstBuilder('FIRST_TEST', 1)
->addConst("SECOND_TEST", 2)
->getNode();
@ -118,7 +118,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
@ -142,7 +142,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
);
}
public function testType() {
public function testType(): void {
$node = $this->createClassConstBuilder('TYPE', 1)
->setType('int')
->getNode();
@ -157,7 +157,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestDefaultValues
*/
public function testValues($value, $expectedValueNode) {
public function testValues($value, $expectedValueNode): void {
$node = $this->createClassConstBuilder('TEST', $value)
->getNode()
;
@ -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

@ -18,7 +18,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
return new Class_($class);
}
public function testExtendsImplements() {
public function testExtendsImplements(): void {
$node = $this->createClassBuilder('SomeLogger')
->extend('BaseLogger')
->implement('Namespaced\Logger', new Name('SomeInterface'))
@ -40,7 +40,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
);
}
public function testAbstract() {
public function testAbstract(): void {
$node = $this->createClassBuilder('Test')
->makeAbstract()
->getNode()
@ -54,7 +54,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
);
}
public function testFinal() {
public function testFinal(): void {
$node = $this->createClassBuilder('Test')
->makeFinal()
->getNode()
@ -68,7 +68,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
);
}
public function testReadonly() {
public function testReadonly(): void {
$node = $this->createClassBuilder('Test')
->makeReadonly()
->getNode()
@ -82,7 +82,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
);
}
public function testStatementOrder() {
public function testStatementOrder(): void {
$method = new Stmt\ClassMethod('testMethod');
$property = new Stmt\Property(
Modifiers::PUBLIC,
@ -108,7 +108,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
);
}
public function testDocComment() {
public function testDocComment(): void {
$docComment = <<<'DOC'
/**
* Test
@ -141,7 +141,7 @@ DOC;
);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
@ -162,7 +162,7 @@ DOC;
);
}
public function testInvalidStmtError() {
public function testInvalidStmtError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"');
$this->createClassBuilder('Test')
@ -170,21 +170,21 @@ DOC;
;
}
public function testInvalidDocComment() {
public function testInvalidDocComment(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc');
$this->createClassBuilder('Test')
->setDocComment(new Comment('Test'));
}
public function testEmptyName() {
public function testEmptyName(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name cannot be empty');
$this->createClassBuilder('Test')
->extend('');
}
public function testInvalidName() {
public function testInvalidName(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name must be a string or an instance of Node\Name');
$this->createClassBuilder('Test')

View File

@ -17,7 +17,7 @@ class EnumCaseTest extends \PHPUnit\Framework\TestCase {
return new EnumCase($name);
}
public function testDocComment() {
public function testDocComment(): void {
$node = $this->createEnumCaseBuilder('TEST')
->setDocComment('/** Test */')
->getNode();
@ -35,7 +35,7 @@ class EnumCaseTest extends \PHPUnit\Framework\TestCase {
);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
@ -59,7 +59,7 @@ class EnumCaseTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestDefaultValues
*/
public function testValues($value, $expectedValueNode) {
public function testValues($value, $expectedValueNode): void {
$node = $this->createEnumCaseBuilder('TEST')
->setValue($value)
->getNode()
@ -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

@ -17,7 +17,7 @@ class EnumTest extends \PHPUnit\Framework\TestCase {
return new Enum_($class);
}
public function testImplements() {
public function testImplements(): void {
$node = $this->createEnumBuilder('SomeEnum')
->implement('Namespaced\SomeInterface', new Name('OtherInterface'))
->getNode()
@ -34,7 +34,7 @@ class EnumTest extends \PHPUnit\Framework\TestCase {
);
}
public function testSetScalarType() {
public function testSetScalarType(): void {
$node = $this->createEnumBuilder('Test')
->setScalarType('int')
->getNode()
@ -48,7 +48,7 @@ class EnumTest extends \PHPUnit\Framework\TestCase {
);
}
public function testStatementOrder() {
public function testStatementOrder(): void {
$method = new Stmt\ClassMethod('testMethod');
$enumCase = new Stmt\EnumCase(
'TEST_ENUM_CASE'
@ -73,7 +73,7 @@ class EnumTest extends \PHPUnit\Framework\TestCase {
);
}
public function testDocComment() {
public function testDocComment(): void {
$docComment = <<<'DOC'
/**
* Test
@ -106,7 +106,7 @@ DOC;
);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
@ -127,7 +127,7 @@ DOC;
);
}
public function testInvalidStmtError() {
public function testInvalidStmtError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Unexpected node of type "PropertyItem"');
$this->createEnumBuilder('Test')
@ -135,21 +135,21 @@ DOC;
;
}
public function testInvalidDocComment() {
public function testInvalidDocComment(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc');
$this->createEnumBuilder('Test')
->setDocComment(new Comment('Test'));
}
public function testEmptyName() {
public function testEmptyName(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name cannot be empty');
$this->createEnumBuilder('Test')
->implement('');
}
public function testInvalidName() {
public function testInvalidName(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name must be a string or an instance of Node\Name');
$this->createEnumBuilder('Test')

View File

@ -20,7 +20,7 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
return new Function_($name);
}
public function testReturnByRef() {
public function testReturnByRef(): void {
$node = $this->createFunctionBuilder('test')
->makeReturnByRef()
->getNode()
@ -34,7 +34,7 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
);
}
public function testParams() {
public function testParams(): void {
$param1 = new Node\Param(new Variable('test1'));
$param2 = new Node\Param(new Variable('test2'));
$param3 = new Node\Param(new Variable('test3'));
@ -53,7 +53,7 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
);
}
public function testStmts() {
public function testStmts(): void {
$stmt1 = new Print_(new String_('test1'));
$stmt2 = new Print_(new String_('test2'));
$stmt3 = new Print_(new String_('test3'));
@ -76,7 +76,7 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
);
}
public function testDocComment() {
public function testDocComment(): void {
$node = $this->createFunctionBuilder('test')
->setDocComment('/** Test */')
->getNode();
@ -86,7 +86,7 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
]), $node);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
@ -102,7 +102,7 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
], []), $node);
}
public function testReturnType() {
public function testReturnType(): void {
$node = $this->createFunctionBuilder('test')
->setReturnType('void')
->getNode();
@ -112,13 +112,13 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
], []), $node);
}
public function testInvalidNullableVoidType() {
public function testInvalidNullableVoidType(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('void type cannot be nullable');
$this->createFunctionBuilder('test')->setReturnType('?void');
}
public function testInvalidParamError() {
public function testInvalidParamError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected parameter node, got "Name"');
$this->createFunctionBuilder('test')
@ -126,7 +126,7 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
;
}
public function testAddNonStmt() {
public function testAddNonStmt(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected statement or expression node');
$this->createFunctionBuilder('test')

View File

@ -23,13 +23,13 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase {
return $pp->prettyPrint([$node]);
}
public function testEmpty() {
public function testEmpty(): void {
$contract = $this->createInterfaceBuilder()->getNode();
$this->assertInstanceOf(Stmt\Interface_::class, $contract);
$this->assertEquals(new Node\Identifier('Contract'), $contract->name);
}
public function testExtending() {
public function testExtending(): void {
$contract = $this->createInterfaceBuilder()
->extend('Space\Root1', 'Root2')->getNode();
$this->assertEquals(
@ -42,13 +42,13 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase {
);
}
public function testAddMethod() {
public function testAddMethod(): void {
$method = new Stmt\ClassMethod('doSomething');
$contract = $this->createInterfaceBuilder()->addStmt($method)->getNode();
$this->assertSame([$method], $contract->stmts);
}
public function testAddConst() {
public function testAddConst(): void {
$const = new Stmt\ClassConst([
new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458.0))
]);
@ -56,7 +56,7 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase {
$this->assertSame(299792458.0, $contract->stmts[0]->consts[0]->value->value);
}
public function testOrder() {
public function testOrder(): void {
$const = new Stmt\ClassConst([
new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458))
]);
@ -71,7 +71,7 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase {
$this->assertInstanceOf(Stmt\ClassMethod::class, $contract->stmts[1]);
}
public function testDocComment() {
public function testDocComment(): void {
$node = $this->createInterfaceBuilder()
->setDocComment('/** Test */')
->getNode();
@ -81,7 +81,7 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase {
]), $node);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
@ -97,13 +97,13 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase {
], []), $node);
}
public function testInvalidStmtError() {
public function testInvalidStmtError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Unexpected node of type "PropertyItem"');
$this->createInterfaceBuilder()->addStmt(new Node\PropertyItem('invalid'));
}
public function testFullFunctional() {
public function testFullFunctional(): void {
$const = new Stmt\ClassConst([
new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458))
]);

View File

@ -21,7 +21,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
return new Method($name);
}
public function testModifiers() {
public function testModifiers(): void {
$node = $this->createMethodBuilder('test')
->makePublic()
->makeAbstract()
@ -63,7 +63,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
);
}
public function testReturnByRef() {
public function testReturnByRef(): void {
$node = $this->createMethodBuilder('test')
->makeReturnByRef()
->getNode()
@ -77,7 +77,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
);
}
public function testParams() {
public function testParams(): void {
$param1 = new Node\Param(new Variable('test1'));
$param2 = new Node\Param(new Variable('test2'));
$param3 = new Node\Param(new Variable('test3'));
@ -96,7 +96,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
);
}
public function testStmts() {
public function testStmts(): void {
$stmt1 = new Print_(new String_('test1'));
$stmt2 = new Print_(new String_('test2'));
$stmt3 = new Print_(new String_('test3'));
@ -118,7 +118,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
$node
);
}
public function testDocComment() {
public function testDocComment(): void {
$node = $this->createMethodBuilder('test')
->setDocComment('/** Test */')
->getNode();
@ -128,7 +128,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
]), $node);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
@ -144,7 +144,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
], []), $node);
}
public function testReturnType() {
public function testReturnType(): void {
$node = $this->createMethodBuilder('test')
->setReturnType('bool')
->getNode();
@ -153,7 +153,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
], []), $node);
}
public function testAddStmtToAbstractMethodError() {
public function testAddStmtToAbstractMethodError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot add statements to an abstract method');
$this->createMethodBuilder('test')
@ -162,7 +162,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
;
}
public function testMakeMethodWithStmtsAbstractError() {
public function testMakeMethodWithStmtsAbstractError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot make method with statements abstract');
$this->createMethodBuilder('test')
@ -171,7 +171,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
;
}
public function testInvalidParamError() {
public function testInvalidParamError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected parameter node, got "Name"');
$this->createMethodBuilder('test')

View File

@ -11,7 +11,7 @@ class NamespaceTest extends \PHPUnit\Framework\TestCase {
return new Namespace_($fqn);
}
public function testCreation() {
public function testCreation(): void {
$stmt1 = new Stmt\Class_('SomeClass');
$stmt2 = new Stmt\Interface_('SomeInterface');
$stmt3 = new Stmt\Function_('someFunction');

View File

@ -21,7 +21,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestDefaultValues
*/
public function testDefaultValues($value, $expectedValueNode) {
public function testDefaultValues($value, $expectedValueNode): void {
$node = $this->createParamBuilder('test')
->setDefault($value)
->getNode()
@ -30,7 +30,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
$this->assertEquals($expectedValueNode, $node->default);
}
public function provideTestDefaultValues() {
public static function provideTestDefaultValues() {
return [
[
null,
@ -89,7 +89,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
* @dataProvider provideTestNullableTypes
* @dataProvider provideTestUnionTypes
*/
public function testTypes($typeHint, $expectedType) {
public function testTypes($typeHint, $expectedType): void {
$node = $this->createParamBuilder('test')
->setType($typeHint)
->getNode()
@ -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([
@ -169,19 +169,19 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
];
}
public function testVoidTypeError() {
public function testVoidTypeError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Parameter type cannot be void');
$this->createParamBuilder('test')->setType('void');
}
public function testInvalidTypeError() {
public function testInvalidTypeError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier or ComplexType');
$this->createParamBuilder('test')->setType(new \stdClass());
}
public function testByRef() {
public function testByRef(): void {
$node = $this->createParamBuilder('test')
->makeByRef()
->getNode()
@ -193,7 +193,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
);
}
public function testVariadic() {
public function testVariadic(): void {
$node = $this->createParamBuilder('test')
->makeVariadic()
->getNode()
@ -205,7 +205,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
);
}
public function testMakePublic() {
public function testMakePublic(): void {
$node = $this->createParamBuilder('test')
->makePublic()
->getNode()
@ -217,7 +217,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
);
}
public function testMakeProtected() {
public function testMakeProtected(): void {
$node = $this->createParamBuilder('test')
->makeProtected()
->getNode()
@ -229,7 +229,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
);
}
public function testMakePrivate() {
public function testMakePrivate(): void {
$node = $this->createParamBuilder('test')
->makePrivate()
->getNode()
@ -241,7 +241,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
);
}
public function testMakeReadonly() {
public function testMakeReadonly(): void {
$node = $this->createParamBuilder('test')
->makeReadonly()
->getNode()
@ -253,7 +253,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]

View File

@ -19,7 +19,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
return new Property($name);
}
public function testModifiers() {
public function testModifiers(): void {
$node = $this->createPropertyBuilder('test')
->makePrivate()
->makeStatic()
@ -82,7 +82,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
);
}
public function testDocComment() {
public function testDocComment(): void {
$node = $this->createPropertyBuilder('test')
->setDocComment('/** Test */')
->getNode();
@ -101,7 +101,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestDefaultValues
*/
public function testDefaultValues($value, $expectedValueNode) {
public function testDefaultValues($value, $expectedValueNode): void {
$node = $this->createPropertyBuilder('test')
->setDefault($value)
->getNode()
@ -110,7 +110,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
$this->assertEquals($expectedValueNode, $node->props[0]->default);
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
@ -136,7 +136,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
);
}
public function provideTestDefaultValues() {
public static function provideTestDefaultValues() {
return [
[
null,

View File

@ -23,7 +23,7 @@ class TraitTest extends \PHPUnit\Framework\TestCase {
return new Trait_($class);
}
public function testStmtAddition() {
public function testStmtAddition(): void {
$method1 = new Stmt\ClassMethod('test1');
$method2 = new Stmt\ClassMethod('test2');
$method3 = new Stmt\ClassMethod('test3');
@ -49,7 +49,7 @@ class TraitTest extends \PHPUnit\Framework\TestCase {
]), $trait);
}
public function testInvalidStmtError() {
public function testInvalidStmtError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"');
$this->createTraitBuilder('Test')
@ -57,7 +57,7 @@ class TraitTest extends \PHPUnit\Framework\TestCase {
;
}
public function testGetMethods() {
public function testGetMethods(): void {
$methods = [
new ClassMethod('foo'),
new ClassMethod('bar'),
@ -77,7 +77,7 @@ class TraitTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($methods, $trait->getMethods());
}
public function testGetProperties() {
public function testGetProperties(): void {
$properties = [
new Property(Modifiers::PUBLIC, [new PropertyItem('foo')]),
new Property(Modifiers::PUBLIC, [new PropertyItem('bar')]),
@ -95,7 +95,7 @@ class TraitTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($properties, $trait->getProperties());
}
public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]

View File

@ -12,7 +12,7 @@ class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase {
return new TraitUseAdaptation($trait, $method);
}
public function testAsMake() {
public function testAsMake(): void {
$builder = $this->createTraitUseAdaptationBuilder(null, 'foo');
$this->assertEquals(
@ -36,7 +36,7 @@ class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase {
);
}
public function testInsteadof() {
public function testInsteadof(): void {
$node = $this->createTraitUseAdaptationBuilder('SomeTrait', 'foo')
->insteadof('AnotherTrait')
->getNode()
@ -52,7 +52,7 @@ class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase {
);
}
public function testAsOnNotAlias() {
public function testAsOnNotAlias(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot set alias for not alias adaptation buider');
$this->createTraitUseAdaptationBuilder('Test', 'foo')
@ -61,7 +61,7 @@ class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase {
;
}
public function testInsteadofOnNotPrecedence() {
public function testInsteadofOnNotPrecedence(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot add overwritten traits for not precedence adaptation buider');
$this->createTraitUseAdaptationBuilder('Test', 'foo')
@ -70,7 +70,7 @@ class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase {
;
}
public function testInsteadofWithoutTrait() {
public function testInsteadofWithoutTrait(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Precedence adaptation must have trait');
$this->createTraitUseAdaptationBuilder(null, 'foo')
@ -78,7 +78,7 @@ class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase {
;
}
public function testMakeOnNotAlias() {
public function testMakeOnNotAlias(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot set access modifier for not alias adaptation buider');
$this->createTraitUseAdaptationBuilder('Test', 'foo')
@ -87,7 +87,7 @@ class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase {
;
}
public function testMultipleMake() {
public function testMultipleMake(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Multiple access type modifiers are not allowed');
$this->createTraitUseAdaptationBuilder(null, 'foo')
@ -96,7 +96,7 @@ class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase {
;
}
public function testUndefinedType() {
public function testUndefinedType(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Type of adaptation is not defined');
$this->createTraitUseAdaptationBuilder(null, 'foo')

View File

@ -10,7 +10,7 @@ class TraitUseTest extends \PHPUnit\Framework\TestCase {
return new TraitUse(...$traits);
}
public function testAnd() {
public function testAnd(): void {
$node = $this->createTraitUseBuilder('SomeTrait')
->and('AnotherTrait')
->getNode()
@ -25,7 +25,7 @@ class TraitUseTest extends \PHPUnit\Framework\TestCase {
);
}
public function testWith() {
public function testWith(): void {
$node = $this->createTraitUseBuilder('SomeTrait')
->with(new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar'))
->with((new TraitUseAdaptation(null, 'test'))->as('baz'))
@ -41,7 +41,7 @@ class TraitUseTest extends \PHPUnit\Framework\TestCase {
);
}
public function testInvalidAdaptationNode() {
public function testInvalidAdaptationNode(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Adaptation must have type TraitUseAdaptation');
$this->createTraitUseBuilder('Test')

View File

@ -11,7 +11,7 @@ class UseTest extends \PHPUnit\Framework\TestCase {
return new Builder\Use_($name, $type);
}
public function testCreation() {
public function testCreation(): void {
$node = $this->createUseBuilder('Foo\Bar')->getNode();
$this->assertEquals(new Stmt\Use_([
new \PhpParser\Node\UseItem(new Name('Foo\Bar'), null)

View File

@ -15,12 +15,12 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestFactory
*/
public function testFactory($methodName, $className) {
public function testFactory($methodName, $className): void {
$factory = new BuilderFactory();
$this->assertInstanceOf($className, $factory->$methodName('test'));
}
public function provideTestFactory() {
public static function provideTestFactory() {
return [
['namespace', Builder\Namespace_::class],
['class', Builder\Class_::class],
@ -38,12 +38,12 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
];
}
public function testFactoryClassConst() {
public function testFactoryClassConst(): void {
$factory = new BuilderFactory();
$this->assertInstanceOf(Builder\ClassConst::class, $factory->classConst('TEST', 1));
}
public function testAttribute() {
public function testAttribute(): void {
$factory = new BuilderFactory();
$this->assertEquals(
new Attribute(new Name('AttributeName'), [new Arg(
@ -53,7 +53,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testVal() {
public function testVal(): void {
// This method is a wrapper around BuilderHelpers::normalizeValue(),
// which is already tested elsewhere
$factory = new BuilderFactory();
@ -63,7 +63,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testConcat() {
public function testConcat(): void {
$factory = new BuilderFactory();
$varA = new Expr\Variable('a');
$varB = new Expr\Variable('b');
@ -83,19 +83,19 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testConcatOneError() {
public function testConcatOneError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected at least two expressions');
(new BuilderFactory())->concat("a");
}
public function testConcatInvalidExpr() {
public function testConcatInvalidExpr(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected string or Expr');
(new BuilderFactory())->concat("a", 42);
}
public function testArgs() {
public function testArgs(): void {
$factory = new BuilderFactory();
$unpack = new Arg(new Expr\Variable('c'), false, true);
$this->assertEquals(
@ -108,7 +108,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testNamedArgs() {
public function testNamedArgs(): void {
$factory = new BuilderFactory();
$this->assertEquals(
[
@ -119,7 +119,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testCalls() {
public function testCalls(): void {
$factory = new BuilderFactory();
// Simple function call
@ -195,7 +195,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testConstFetches() {
public function testConstFetches(): void {
$factory = new BuilderFactory();
$this->assertEquals(
new Expr\ConstFetch(new Name('FOO')),
@ -215,7 +215,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testVar() {
public function testVar(): void {
$factory = new BuilderFactory();
$this->assertEquals(
new Expr\Variable("foo"),
@ -227,7 +227,7 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testPropertyFetch() {
public function testPropertyFetch(): void {
$f = new BuilderFactory();
$this->assertEquals(
new Expr\PropertyFetch(new Expr\Variable('foo'), 'bar'),
@ -243,31 +243,31 @@ class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
);
}
public function testInvalidIdentifier() {
public function testInvalidIdentifier(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected string or instance of Node\Identifier');
(new BuilderFactory())->classConstFetch('Foo', new Name('foo'));
}
public function testInvalidIdentifierOrExpr() {
public function testInvalidIdentifierOrExpr(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected string or instance of Node\Identifier or Node\Expr');
(new BuilderFactory())->staticCall('Foo', new Name('bar'));
}
public function testInvalidNameOrExpr() {
public function testInvalidNameOrExpr(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name must be a string or an instance of Node\Name or Node\Expr');
(new BuilderFactory())->funcCall(new Node\Stmt\Return_());
}
public function testInvalidVar() {
public function testInvalidVar(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Variable name must be string or Expr');
(new BuilderFactory())->var(new Node\Stmt\Return_());
}
public function testIntegration() {
public function testIntegration(): void {
$factory = new BuilderFactory();
$node = $factory->namespace('Name\Space')
->addStmt($factory->use('Foo\Bar\SomeOtherClass'))

View File

@ -9,7 +9,7 @@ use PhpParser\Node\Stmt;
use PhpParser\Node\Expr;
class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
public function testNormalizeNode() {
public function testNormalizeNode(): void {
$builder = new Class_('SomeClass');
$this->assertEquals($builder->getNode(), BuilderHelpers::normalizeNode($builder));
@ -21,7 +21,7 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeNode('test');
}
public function testNormalizeStmt() {
public function testNormalizeStmt(): void {
$stmt = new Node\Stmt\Class_('Class');
$this->assertSame($stmt, BuilderHelpers::normalizeStmt($stmt));
@ -35,13 +35,13 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeStmt(new Node\Attribute(new Node\Name('Test')));
}
public function testNormalizeStmtInvalidType() {
public function testNormalizeStmtInvalidType(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected node or builder object');
BuilderHelpers::normalizeStmt('test');
}
public function testNormalizeIdentifier() {
public function testNormalizeIdentifier(): void {
$identifier = new Node\Identifier('fn');
$this->assertSame($identifier, BuilderHelpers::normalizeIdentifier($identifier));
$this->assertEquals($identifier, BuilderHelpers::normalizeIdentifier('fn'));
@ -51,7 +51,7 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeIdentifier(1);
}
public function testNormalizeIdentifierOrExpr() {
public function testNormalizeIdentifierOrExpr(): void {
$identifier = new Node\Identifier('fn');
$this->assertSame($identifier, BuilderHelpers::normalizeIdentifierOrExpr($identifier));
@ -64,7 +64,7 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeIdentifierOrExpr(1);
}
public function testNormalizeName() {
public function testNormalizeName(): void {
$name = new Node\Name('test');
$this->assertSame($name, BuilderHelpers::normalizeName($name));
$this->assertEquals(
@ -82,13 +82,13 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeName('');
}
public function testNormalizeNameInvalidType() {
public function testNormalizeNameInvalidType(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name must be a string or an instance of Node\Name');
BuilderHelpers::normalizeName(1);
}
public function testNormalizeNameOrExpr() {
public function testNormalizeNameOrExpr(): void {
$expr = new Expr\Variable('fn');
$this->assertSame($expr, BuilderHelpers::normalizeNameOrExpr($expr));
@ -109,13 +109,13 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeNameOrExpr('');
}
public function testNormalizeNameOrExpInvalidType() {
public function testNormalizeNameOrExpInvalidType(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name must be a string or an instance of Node\Name or Node\Expr');
BuilderHelpers::normalizeNameOrExpr(1);
}
public function testNormalizeType() {
public function testNormalizeType(): void {
$this->assertEquals(new Node\Identifier('array'), BuilderHelpers::normalizeType('array'));
$this->assertEquals(new Node\Identifier('callable'), BuilderHelpers::normalizeType('callable'));
$this->assertEquals(new Node\Identifier('string'), BuilderHelpers::normalizeType('string'));
@ -156,25 +156,25 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeType(1);
}
public function testNormalizeTypeNullableVoid() {
public function testNormalizeTypeNullableVoid(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('void type cannot be nullable');
BuilderHelpers::normalizeType('?void');
}
public function testNormalizeTypeNullableMixed() {
public function testNormalizeTypeNullableMixed(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('mixed type cannot be nullable');
BuilderHelpers::normalizeType('?mixed');
}
public function testNormalizeTypeNullableNever() {
public function testNormalizeTypeNullableNever(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('never type cannot be nullable');
BuilderHelpers::normalizeType('?never');
}
public function testNormalizeValue() {
public function testNormalizeValue(): void {
$expression = new Scalar\Int_(1);
$this->assertSame($expression, BuilderHelpers::normalizeValue($expression));
@ -200,7 +200,7 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeValue(new \stdClass());
}
public function testNormalizeDocComment() {
public function testNormalizeDocComment(): void {
$docComment = new Comment\Doc('Some doc comment');
$this->assertSame($docComment, BuilderHelpers::normalizeDocComment($docComment));
@ -211,7 +211,7 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase {
BuilderHelpers::normalizeDocComment(1);
}
public function testNormalizeAttribute() {
public function testNormalizeAttribute(): void {
$attribute = new Node\Attribute(new Node\Name('Test'));
$attributeGroup = new Node\AttributeGroup([$attribute]);

View File

@ -9,7 +9,7 @@ class CodeParsingTest extends CodeTestAbstract {
/**
* @dataProvider provideTestParse
*/
public function testParse($name, $code, $expected, $modeLine) {
public function testParse($name, $code, $expected, $modeLine): void {
$modes = $this->parseModeLine($modeLine);
$parser = $this->createParser($modes['version'] ?? null);
list($stmts, $output) = $this->getParseOutput($parser, $code, $modes);
@ -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) {
@ -62,13 +62,13 @@ class CodeParsingTest extends CodeTestAbstract {
return $e->getMessage();
}
private function checkAttributes($stmts) {
private function checkAttributes($stmts): void {
if ($stmts === null) {
return;
}
$traverser = new NodeTraverser(new class () extends NodeVisitorAbstract {
public function enterNode(Node $node) {
public function enterNode(Node $node): void {
$startLine = $node->getStartLine();
$endLine = $node->getEndLine();
$startFilePos = $node->getStartFilePos();

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

@ -3,7 +3,7 @@
namespace PhpParser;
class CommentTest extends \PHPUnit\Framework\TestCase {
public function testGetters() {
public function testGetters(): void {
$comment = new Comment('/* Some comment */',
1, 10, 2, 1, 27, 2);
@ -20,12 +20,12 @@ class CommentTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestReformatting
*/
public function testReformatting($commentText, $reformattedText) {
public function testReformatting($commentText, $reformattedText): void {
$comment = new Comment($commentText);
$this->assertSame($reformattedText, $comment->getReformattedText());
}
public function provideTestReformatting() {
public static function provideTestReformatting() {
return [
['// Some text', '// Some text'],
['/* Some text */', '/* Some text */'],

View File

@ -13,7 +13,7 @@ class CompatibilityTest extends \PHPUnit\Framework\TestCase {
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testAliases1() {
public function testAliases1(): void {
$var = new Expr\Variable('x');
$node = new Node\ClosureUse($var);
$this->assertTrue($node instanceof Expr\ClosureUse);
@ -41,7 +41,7 @@ class CompatibilityTest extends \PHPUnit\Framework\TestCase {
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testAliases2() {
public function testAliases2(): void {
$var = new Expr\Variable('x');
$node = new Node\Expr\ClosureUse($var);
$this->assertTrue($node instanceof Node\ClosureUse);

View File

@ -7,14 +7,14 @@ use PhpParser\Node\Scalar;
class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase {
/** @dataProvider provideTestEvaluate */
public function testEvaluate($exprString, $expected) {
public function testEvaluate($exprString, $expected): void {
$parser = new Parser\Php7(new Lexer());
$expr = $parser->parse('<?php ' . $exprString . ';')[0]->expr;
$evaluator = new ConstExprEvaluator();
$this->assertSame($expected, $evaluator->evaluateDirectly($expr));
}
public function provideTestEvaluate() {
public static function provideTestEvaluate() {
return [
['1', 1],
['1.0', 1.0],
@ -74,14 +74,14 @@ class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase {
];
}
public function testEvaluateFails() {
public function testEvaluateFails(): void {
$this->expectException(ConstExprEvaluationException::class);
$this->expectExceptionMessage('Expression of type Expr_Variable cannot be evaluated');
$evaluator = new ConstExprEvaluator();
$evaluator->evaluateDirectly(new Expr\Variable('a'));
}
public function testEvaluateFallback() {
public function testEvaluateFallback(): void {
$evaluator = new ConstExprEvaluator(function (Expr $expr) {
if ($expr instanceof Scalar\MagicConst\Line) {
return 42;
@ -98,7 +98,7 @@ class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestEvaluateSilently
*/
public function testEvaluateSilently($expr, $exception, $msg) {
public function testEvaluateSilently($expr, $exception, $msg): void {
$evaluator = new ConstExprEvaluator();
try {
@ -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

@ -5,7 +5,7 @@ namespace PhpParser\ErrorHandler;
use PhpParser\Error;
class CollectingTest extends \PHPUnit\Framework\TestCase {
public function testHandleError() {
public function testHandleError(): void {
$errorHandler = new Collecting();
$this->assertFalse($errorHandler->hasErrors());
$this->assertEmpty($errorHandler->getErrors());

View File

@ -5,7 +5,7 @@ namespace PhpParser\ErrorHandler;
use PhpParser\Error;
class ThrowingTest extends \PHPUnit\Framework\TestCase {
public function testHandleError() {
public function testHandleError(): void {
$this->expectException(Error::class);
$this->expectExceptionMessage('Test');
$errorHandler = new Throwing();

View File

@ -22,7 +22,7 @@ class ErrorTest extends \PHPUnit\Framework\TestCase {
/**
* @depends testConstruct
*/
public function testSetMessageAndLine(Error $error) {
public function testSetMessageAndLine(Error $error): void {
$error->setRawMessage('Some other error');
$this->assertSame('Some other error', $error->getRawMessage());
@ -31,7 +31,7 @@ class ErrorTest extends \PHPUnit\Framework\TestCase {
$this->assertSame('Some other error on line 15', $error->getMessage());
}
public function testUnknownLine() {
public function testUnknownLine(): void {
$error = new Error('Some error');
$this->assertSame(-1, $error->getStartLine());
@ -40,7 +40,7 @@ class ErrorTest extends \PHPUnit\Framework\TestCase {
}
/** @dataProvider provideTestColumnInfo */
public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn) {
public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn): void {
$error = new Error('Some error', [
'startFilePos' => $startPos,
'endFilePos' => $endPos,
@ -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],
@ -72,7 +72,7 @@ class ErrorTest extends \PHPUnit\Framework\TestCase {
];
}
public function testNoColumnInfo() {
public function testNoColumnInfo(): void {
$error = new Error('Some error', ['startLine' => 3]);
$this->assertFalse($error->hasColumnInfo());
@ -90,7 +90,7 @@ class ErrorTest extends \PHPUnit\Framework\TestCase {
}
}
public function testInvalidPosInfo() {
public function testInvalidPosInfo(): void {
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Invalid position information');
$error = new Error('Some error', [

View File

@ -28,7 +28,7 @@ class DifferTest extends \PHPUnit\Framework\TestCase {
}
/** @dataProvider provideTestDiff */
public function testDiff($oldStr, $newStr, $expectedDiffStr) {
public function testDiff($oldStr, $newStr, $expectedDiffStr): void {
$differ = new Differ(function ($a, $b) {
return $a === $b;
});
@ -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'],
@ -49,7 +49,7 @@ class DifferTest extends \PHPUnit\Framework\TestCase {
}
/** @dataProvider provideTestDiffWithReplacements */
public function testDiffWithReplacements($oldStr, $newStr, $expectedDiffStr) {
public function testDiffWithReplacements($oldStr, $newStr, $expectedDiffStr): void {
$differ = new Differ(function ($a, $b) {
return $a === $b;
});
@ -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'],
@ -66,7 +66,7 @@ class DifferTest extends \PHPUnit\Framework\TestCase {
];
}
public function testNonContiguousIndices() {
public function testNonContiguousIndices(): void {
$differ = new Differ(function ($a, $b) {
return $a === $b;
});

View File

@ -3,7 +3,7 @@
namespace PhpParser;
class JsonDecoderTest extends \PHPUnit\Framework\TestCase {
public function testRoundTrip() {
public function testRoundTrip(): void {
$code = <<<'PHP'
<?php
// comment
@ -23,14 +23,14 @@ PHP;
}
/** @dataProvider provideTestDecodingError */
public function testDecodingError($json, $expectedMessage) {
public function testDecodingError($json, $expectedMessage): void {
$jsonDecoder = new JsonDecoder();
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage($expectedMessage);
$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

@ -19,7 +19,7 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestReplaceKeywords
*/
public function testReplaceKeywords(string $keyword, int $expectedToken) {
public function testReplaceKeywords(string $keyword, int $expectedToken): void {
$lexer = $this->getLexer();
$code = '<?php ' . $keyword;
$this->assertEquals([
@ -32,7 +32,7 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestReplaceKeywords
*/
public function testReplaceKeywordsUppercase(string $keyword, int $expectedToken) {
public function testReplaceKeywordsUppercase(string $keyword, int $expectedToken): void {
$lexer = $this->getLexer();
$code = '<?php ' . strtoupper($keyword);
@ -46,7 +46,7 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestReplaceKeywords
*/
public function testNoReplaceKeywordsAfterObjectOperator(string $keyword) {
public function testNoReplaceKeywordsAfterObjectOperator(string $keyword): void {
$lexer = $this->getLexer();
$code = '<?php ->' . $keyword;
@ -61,7 +61,7 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestReplaceKeywords
*/
public function testNoReplaceKeywordsAfterObjectOperatorWithSpaces(string $keyword) {
public function testNoReplaceKeywordsAfterObjectOperatorWithSpaces(string $keyword): void {
$lexer = $this->getLexer();
$code = '<?php -> ' . $keyword;
@ -77,7 +77,7 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestReplaceKeywords
*/
public function testNoReplaceKeywordsAfterNullsafeObjectOperator(string $keyword) {
public function testNoReplaceKeywordsAfterNullsafeObjectOperator(string $keyword): void {
$lexer = $this->getLexer();
$code = '<?php ?->' . $keyword;
@ -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],
@ -115,7 +115,7 @@ class EmulativeTest extends LexerTest {
];
}
private function assertSameTokens(array $expectedTokens, array $tokens) {
private function assertSameTokens(array $expectedTokens, array $tokens): void {
$reducedTokens = [];
foreach ($tokens as $token) {
if ($token->id === 0 || $token->isIgnorable()) {
@ -129,7 +129,7 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestLexNewFeatures
*/
public function testLexNewFeatures(string $code, array $expectedTokens) {
public function testLexNewFeatures(string $code, array $expectedTokens): void {
$lexer = $this->getLexer();
$this->assertSameTokens($expectedTokens, $lexer->tokenize('<?php ' . $code));
}
@ -137,7 +137,7 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestLexNewFeatures
*/
public function testLeaveStuffAloneInStrings(string $code) {
public function testLeaveStuffAloneInStrings(string $code): void {
$stringifiedToken = '"' . addcslashes($code, '"\\') . '"';
$lexer = $this->getLexer();
@ -153,7 +153,7 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestLexNewFeatures
*/
public function testErrorAfterEmulation($code) {
public function testErrorAfterEmulation($code): void {
$errorHandler = new ErrorHandler\Collecting();
$lexer = $this->getLexer();
$lexer->tokenize('<?php ' . $code . "\0", $errorHandler);
@ -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'],
@ -396,12 +396,12 @@ class EmulativeTest extends LexerTest {
/**
* @dataProvider provideTestTargetVersion
*/
public function testTargetVersion(string $phpVersion, string $code, array $expectedTokens) {
public function testTargetVersion(string $phpVersion, string $code, array $expectedTokens): void {
$lexer = new Emulative(PhpVersion::fromString($phpVersion));
$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

@ -13,7 +13,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestError
*/
public function testError($code, $messages) {
public function testError($code, $messages): void {
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('HHVM does not throw warnings from token_get_all()');
}
@ -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"]],
@ -45,7 +45,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
];
}
public function testDefaultErrorHandler() {
public function testDefaultErrorHandler(): void {
$this->expectException(Error::class);
$this->expectExceptionMessage('Unterminated comment on line 1');
$lexer = $this->getLexer();
@ -55,7 +55,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestLex
*/
public function testLex($code, $expectedTokens) {
public function testLex($code, $expectedTokens): void {
$lexer = $this->getLexer();
$tokens = $lexer->tokenize($code);
foreach ($tokens as $token) {
@ -70,7 +70,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
}
}
public function provideTestLex() {
public static function provideTestLex() {
return [
// tests PHP 8 T_NAME_* emulation
[
@ -97,7 +97,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
];
}
public function testGetTokens() {
public function testGetTokens(): void {
$code = '<?php "a";' . "\n" . '// foo' . "\n" . '// bar' . "\n\n" . '"b";';
$expectedTokens = [
new Token(T_OPEN_TAG, '<?php ', 1, 0),

View File

@ -9,7 +9,7 @@ class NameContextTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestGetPossibleNames
*/
public function testGetPossibleNames($type, $name, $expectedPossibleNames) {
public function testGetPossibleNames($type, $name, $expectedPossibleNames): void {
$nameContext = new NameContext(new ErrorHandler\Throwing());
$nameContext->startNamespace(new Name('NS'));
$nameContext->addAlias(new Name('Foo'), 'Foo', Use_::TYPE_NORMAL);
@ -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

@ -11,14 +11,14 @@ class CallableLikeTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestIsFirstClassCallable
*/
public function testIsFirstClassCallable(CallLike $node, bool $isFirstClassCallable) {
public function testIsFirstClassCallable(CallLike $node, bool $isFirstClassCallable): void {
$this->assertSame($isFirstClassCallable, $node->isFirstClassCallable());
if (!$isFirstClassCallable) {
$this->assertSame($node->getRawArgs(), $node->getArgs());
}
}
public function provideTestIsFirstClassCallable() {
public static function provideTestIsFirstClassCallable() {
$normalArgs = [new Arg(new Int_(1))];
$callableArgs = [new VariadicPlaceholder()];
return [

View File

@ -3,7 +3,12 @@
namespace PhpParser\Node;
class IdentifierTest extends \PHPUnit\Framework\TestCase {
public function testToString() {
public function testConstructorThrows(): void {
self::expectException(\InvalidArgumentException::class);
new Identifier('');
}
public function testToString(): void {
$identifier = new Identifier('Foo');
$this->assertSame('Foo', (string) $identifier);
@ -12,12 +17,12 @@ class IdentifierTest extends \PHPUnit\Framework\TestCase {
}
/** @dataProvider provideTestIsSpecialClassName */
public function testIsSpecialClassName($identifier, $expected) {
public function testIsSpecialClassName($identifier, $expected): void {
$identifier = new Identifier($identifier);
$this->assertSame($expected, $identifier->isSpecialClassName());
}
public function provideTestIsSpecialClassName() {
public static function provideTestIsSpecialClassName() {
return [
['self', true],
['PARENT', true],

View File

@ -3,7 +3,7 @@
namespace PhpParser\Node;
class NameTest extends \PHPUnit\Framework\TestCase {
public function testConstruct() {
public function testConstruct(): void {
$name = new Name(['foo', 'bar']);
$this->assertSame('foo\bar', $name->name);
@ -14,7 +14,7 @@ class NameTest extends \PHPUnit\Framework\TestCase {
$this->assertSame('foo\bar', $name->name);
}
public function testGet() {
public function testGet(): void {
$name = new Name('foo');
$this->assertSame('foo', $name->getFirst());
$this->assertSame('foo', $name->getLast());
@ -26,7 +26,7 @@ class NameTest extends \PHPUnit\Framework\TestCase {
$this->assertSame(['foo', 'bar'], $name->getParts());
}
public function testToString() {
public function testToString(): void {
$name = new Name('Foo\Bar');
$this->assertSame('Foo\Bar', (string) $name);
@ -34,7 +34,7 @@ class NameTest extends \PHPUnit\Framework\TestCase {
$this->assertSame('foo\bar', $name->toLowerString());
}
public function testSlice() {
public function testSlice(): void {
$name = new Name('foo\bar\baz');
$this->assertEquals(new Name('foo\bar\baz'), $name->slice(0));
$this->assertEquals(new Name('bar\baz'), $name->slice(1));
@ -50,37 +50,37 @@ class NameTest extends \PHPUnit\Framework\TestCase {
$this->assertNull($name->slice(-2, -2));
}
public function testSliceOffsetTooLarge() {
public function testSliceOffsetTooLarge(): void {
$this->expectException(\OutOfBoundsException::class);
$this->expectExceptionMessage('Offset 4 is out of bounds');
(new Name('foo\bar\baz'))->slice(4);
}
public function testSliceOffsetTooSmall() {
public function testSliceOffsetTooSmall(): void {
$this->expectException(\OutOfBoundsException::class);
$this->expectExceptionMessage('Offset -4 is out of bounds');
(new Name('foo\bar\baz'))->slice(-4);
}
public function testSliceLengthTooLarge() {
public function testSliceLengthTooLarge(): void {
$this->expectException(\OutOfBoundsException::class);
$this->expectExceptionMessage('Length 4 is out of bounds');
(new Name('foo\bar\baz'))->slice(0, 4);
}
public function testSliceLengthTooSmall() {
public function testSliceLengthTooSmall(): void {
$this->expectException(\OutOfBoundsException::class);
$this->expectExceptionMessage('Length -4 is out of bounds');
(new Name('foo\bar\baz'))->slice(0, -4);
}
public function testSliceLengthTooLargeWithOffset() {
public function testSliceLengthTooLargeWithOffset(): void {
$this->expectException(\OutOfBoundsException::class);
$this->expectExceptionMessage('Length 3 is out of bounds');
(new Name('foo\bar\baz'))->slice(1, 3);
}
public function testConcat() {
public function testConcat(): void {
$this->assertEquals(new Name('foo\bar\baz'), Name::concat('foo', 'bar\baz'));
$this->assertEquals(
new Name\FullyQualified('foo\bar'),
@ -98,7 +98,7 @@ class NameTest extends \PHPUnit\Framework\TestCase {
$this->assertNull(Name::concat(null, null));
}
public function testNameTypes() {
public function testNameTypes(): void {
$name = new Name('foo');
$this->assertTrue($name->isUnqualified());
$this->assertFalse($name->isQualified());
@ -128,31 +128,31 @@ class NameTest extends \PHPUnit\Framework\TestCase {
$this->assertSame('namespace\foo', $name->toCodeString());
}
public function testInvalidArg() {
public function testInvalidArg(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected string, array of parts or Name instance');
Name::concat('foo', new \stdClass());
}
public function testInvalidEmptyString() {
public function testInvalidEmptyString(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Name cannot be empty');
new Name('');
}
public function testInvalidEmptyArray() {
public function testInvalidEmptyArray(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Name cannot be empty');
new Name([]);
}
/** @dataProvider provideTestIsSpecialClassName */
public function testIsSpecialClassName($name, $expected) {
public function testIsSpecialClassName($name, $expected): void {
$name = new Name($name);
$this->assertSame($expected, $name->isSpecialClassName());
}
public function provideTestIsSpecialClassName() {
public static function provideTestIsSpecialClassName() {
return [
['self', true],
['PARENT', true],

View File

@ -6,7 +6,7 @@ use PhpParser\Modifiers;
use PhpParser\Node\Expr\Variable;
class ParamTest extends \PHPUnit\Framework\TestCase {
public function testNoModifiers() {
public function testNoModifiers(): void {
$node = new Param(new Variable('foo'));
$this->assertFalse($node->isPromoted());
@ -19,14 +19,14 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideModifiers
*/
public function testModifiers(string $modifier) {
public function testModifiers(string $modifier): void {
$node = new Param(new Variable('foo'));
$node->flags = constant(Modifiers::class . '::' . strtoupper($modifier));
$this->assertTrue($node->isPromoted());
$this->assertTrue($node->{'is' . $modifier}());
}
public function provideModifiers() {
public static function provideModifiers() {
return [
['public'],
['protected'],

View File

@ -7,7 +7,7 @@ use PhpParser\Node\Stmt\Echo_;
use PhpParser\ParserFactory;
class DNumberTest extends \PHPUnit\Framework\TestCase {
public function testRawValue() {
public function testRawValue(): void {
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$nodes = $parser->parse('<?php echo 1_234.56;');

View File

@ -6,11 +6,11 @@ class MagicConstTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestGetName
*/
public function testGetName(MagicConst $magicConst, $name) {
public function testGetName(MagicConst $magicConst, $name): void {
$this->assertSame($name, $magicConst->getName());
}
public function provideTestGetName() {
public static function provideTestGetName() {
return [
[new MagicConst\Class_(), '__CLASS__'],
[new MagicConst\Dir(), '__DIR__'],

View File

@ -6,7 +6,7 @@ use PhpParser\Node\Stmt\Echo_;
use PhpParser\ParserFactory;
class NumberTest extends \PHPUnit\Framework\TestCase {
public function testRawValue() {
public function testRawValue(): void {
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$nodes = $parser->parse('<?php echo 1_234;');

View File

@ -6,7 +6,7 @@ use PhpParser\Node\Stmt\Echo_;
use PhpParser\ParserFactory;
class StringTest extends \PHPUnit\Framework\TestCase {
public function testRawValue() {
public function testRawValue(): void {
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$nodes = $parser->parse('<?php echo "sequence \x41";');
@ -25,7 +25,7 @@ class StringTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestParseEscapeSequences
*/
public function testParseEscapeSequences($expected, $string, $quote) {
public function testParseEscapeSequences($expected, $string, $quote): void {
$this->assertSame(
$expected,
String_::parseEscapeSequences($string, $quote)
@ -35,14 +35,14 @@ class StringTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestParse
*/
public function testCreate($expected, $string) {
public function testCreate($expected, $string): void {
$this->assertSame(
$expected,
String_::parse($string)
);
}
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

@ -8,7 +8,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideModifiers
*/
public function testModifiers($modifier) {
public function testModifiers($modifier): void {
$node = new ClassConst(
[], // invalid
constant(Modifiers::class . '::' . strtoupper($modifier))
@ -17,7 +17,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
$this->assertTrue($node->{'is' . $modifier}());
}
public function testNoModifiers() {
public function testNoModifiers(): void {
$node = new ClassConst([], 0);
$this->assertTrue($node->isPublic());
@ -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

@ -11,7 +11,7 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideModifiers
*/
public function testModifiers($modifier) {
public function testModifiers($modifier): void {
$node = new ClassMethod('foo', [
'type' => constant(Modifiers::class . '::' . strtoupper($modifier))
]);
@ -19,7 +19,7 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
$this->assertTrue($node->{'is' . $modifier}());
}
public function testNoModifiers() {
public function testNoModifiers(): void {
$node = new ClassMethod('foo', ['type' => 0]);
$this->assertTrue($node->isPublic());
@ -31,7 +31,7 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($node->isMagic());
}
public function provideModifiers() {
public static function provideModifiers() {
return [
['public'],
['protected'],
@ -49,7 +49,7 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
*
* @param string $modifier Node type modifier
*/
public function testImplicitPublic(string $modifier) {
public function testImplicitPublic(string $modifier): void {
$node = new ClassMethod('foo', [
'type' => constant(Modifiers::class . '::' . strtoupper($modifier))
]);
@ -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'],
@ -70,12 +70,12 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
*
* @param string $name Node name
*/
public function testMagic(string $name) {
public function testMagic(string $name): void {
$node = new ClassMethod($name);
$this->assertTrue($node->isMagic(), 'Method should be magic');
}
public function provideMagics() {
public static function provideMagics() {
return [
['__construct'],
['__DESTRUCT'],
@ -95,7 +95,7 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
];
}
public function testFunctionLike() {
public function testFunctionLike(): void {
$param = new Param(new Variable('a'));
$type = new Name('Foo');
$return = new Return_(new Variable('a'));

View File

@ -7,7 +7,7 @@ use PhpParser\Node\PropertyItem;
use PhpParser\Node\Scalar\String_;
class ClassTest extends \PHPUnit\Framework\TestCase {
public function testIsAbstract() {
public function testIsAbstract(): void {
$class = new Class_('Foo', ['type' => Modifiers::ABSTRACT]);
$this->assertTrue($class->isAbstract());
@ -15,7 +15,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($class->isAbstract());
}
public function testIsFinal() {
public function testIsFinal(): void {
$class = new Class_('Foo', ['type' => Modifiers::FINAL]);
$this->assertTrue($class->isFinal());
@ -23,7 +23,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($class->isFinal());
}
public function testGetTraitUses() {
public function testGetTraitUses(): void {
$traitUses = [
new TraitUse([new Trait_('foo')]),
new TraitUse([new Trait_('bar')]),
@ -39,7 +39,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($traitUses, $class->getTraitUses());
}
public function testGetMethods() {
public function testGetMethods(): void {
$methods = [
new ClassMethod('foo'),
new ClassMethod('bar'),
@ -59,7 +59,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($methods, $class->getMethods());
}
public function testGetConstants() {
public function testGetConstants(): void {
$constants = [
new ClassConst([new \PhpParser\Node\Const_('foo', new String_('foo_value'))]),
new ClassConst([new \PhpParser\Node\Const_('bar', new String_('bar_value'))]),
@ -76,7 +76,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($constants, $class->getConstants());
}
public function testGetProperties() {
public function testGetProperties(): void {
$properties = [
new Property(Modifiers::PUBLIC, [new PropertyItem('foo')]),
new Property(Modifiers::PUBLIC, [new PropertyItem('bar')]),
@ -94,7 +94,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($properties, $class->getProperties());
}
public function testGetProperty() {
public function testGetProperty(): void {
$properties = [
$fooProp = new Property(Modifiers::PUBLIC, [new PropertyItem('foo1')]),
$barProp = new Property(Modifiers::PUBLIC, [new PropertyItem('BAR1')]),
@ -119,7 +119,7 @@ class ClassTest extends \PHPUnit\Framework\TestCase {
$this->assertNull($class->getProperty('nonExisting'));
}
public function testGetMethod() {
public function testGetMethod(): void {
$methodConstruct = new ClassMethod('__CONSTRUCT');
$methodTest = new ClassMethod('test');
$class = new Class_('Foo', [

View File

@ -6,7 +6,7 @@ use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
class InterfaceTest extends \PHPUnit\Framework\TestCase {
public function testGetMethods() {
public function testGetMethods(): void {
$methods = [
new ClassMethod('foo'),
new ClassMethod('bar'),
@ -24,7 +24,7 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($methods, $interface->getMethods());
}
public function testGetConstants() {
public function testGetConstants(): void {
$constants = [
new ClassConst([new \PhpParser\Node\Const_('foo', new String_('foo_value'))]),
new ClassConst([new \PhpParser\Node\Const_('bar', new String_('bar_value'))]),

View File

@ -8,7 +8,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideModifiers
*/
public function testModifiers($modifier) {
public function testModifiers($modifier): void {
$node = new Property(
constant(Modifiers::class . '::' . strtoupper($modifier)),
[] // invalid
@ -17,7 +17,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
$this->assertTrue($node->{'is' . $modifier}());
}
public function testNoModifiers() {
public function testNoModifiers(): void {
$node = new Property(0, []);
$this->assertTrue($node->isPublic());
@ -27,7 +27,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($node->isReadonly());
}
public function testStaticImplicitlyPublic() {
public function testStaticImplicitlyPublic(): void {
$node = new Property(Modifiers::STATIC, []);
$this->assertTrue($node->isPublic());
$this->assertFalse($node->isProtected());
@ -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,
@ -75,7 +75,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideNodes
*/
public function testGetDocComment(array $attributes, Node $node) {
public function testGetDocComment(array $attributes, Node $node): void {
$this->assertSame('/** doc comment */', $node->getDocComment()->getText());
$comments = $node->getComments();
@ -88,7 +88,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
$this->assertNull($node->getDocComment());
}
public function testSetDocComment() {
public function testSetDocComment(): void {
$node = new DummyNode(null, null, null, []);
// Add doc comment to node without comments
@ -119,7 +119,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideNodes
*/
public function testChange(array $attributes, DummyNode $node) {
public function testChange(array $attributes, DummyNode $node): void {
// direct modification
$node->subNode1 = 'newValue';
$this->assertSame('newValue', $node->subNode1);
@ -137,7 +137,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideNodes
*/
public function testIteration(array $attributes, Node $node) {
public function testIteration(array $attributes, Node $node): void {
// Iteration is simple object iteration over properties,
// not over subnodes
$i = 0;
@ -159,7 +159,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
$this->assertSame(3, $i);
}
public function testAttributes() {
public function testAttributes(): void {
/** @var $node Node */
$node = $this->getMockForAbstractClass(NodeAbstract::class);
@ -201,7 +201,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
);
}
public function testJsonSerialization() {
public function testJsonSerialization(): void {
$code = <<<'PHP'
<?php
// comment

View File

@ -10,13 +10,13 @@ class NodeDumperTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestDump
*/
public function testDump($node, $dump) {
public function testDump($node, $dump): void {
$dumper = new NodeDumper();
$this->assertSame($this->canonicalize($dump), $this->canonicalize($dumper->dump($node)));
}
public function provideTestDump() {
public static function provideTestDump() {
return [
[
[],
@ -57,7 +57,7 @@ class NodeDumperTest extends \PHPUnit\Framework\TestCase {
];
}
public function testDumpWithPositions() {
public function testDumpWithPositions(): void {
$parser = (new ParserFactory())->createForHostVersion();
$dumper = new NodeDumper(['dumpPositions' => true]);
@ -90,7 +90,7 @@ OUT;
$this->assertSame($this->canonicalize($expected), $this->canonicalize($dump));
}
public function testError() {
public function testError(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Can only dump nodes and arrays.');
$dumper = new NodeDumper();

View File

@ -14,7 +14,7 @@ class NodeFinderTest extends \PHPUnit\Framework\TestCase {
return [$stmts, $vars];
}
public function testFind() {
public function testFind(): void {
$finder = new NodeFinder();
list($stmts, $vars) = $this->getStmtsAndVars();
$varFilter = function (Node $node) {
@ -29,7 +29,7 @@ class NodeFinderTest extends \PHPUnit\Framework\TestCase {
$this->assertSame([], $finder->find($stmts, $noneFilter));
}
public function testFindInstanceOf() {
public function testFindInstanceOf(): void {
$finder = new NodeFinder();
list($stmts, $vars) = $this->getStmtsAndVars();
$this->assertSame($vars, $finder->findInstanceOf($stmts, Expr\Variable::class));
@ -37,7 +37,7 @@ class NodeFinderTest extends \PHPUnit\Framework\TestCase {
$this->assertSame([], $finder->findInstanceOf($stmts, Expr\BinaryOp\Mul::class));
}
public function testFindFirst() {
public function testFindFirst(): void {
$finder = new NodeFinder();
list($stmts, $vars) = $this->getStmtsAndVars();
$varFilter = function (Node $node) {
@ -52,7 +52,7 @@ class NodeFinderTest extends \PHPUnit\Framework\TestCase {
$this->assertNull($finder->findFirst($stmts, $noneFilter));
}
public function testFindFirstInstanceOf() {
public function testFindFirstInstanceOf(): void {
$finder = new NodeFinder();
list($stmts, $vars) = $this->getStmtsAndVars();
$this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts, Expr\Variable::class));

View File

@ -9,7 +9,7 @@ use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\If_;
class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
public function testNonModifying() {
public function testNonModifying(): void {
$str1Node = new String_('Foo');
$str2Node = new String_('Bar');
$echoNode = new Node\Stmt\Echo_([$str1Node, $str2Node]);
@ -32,7 +32,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
], $visitor->trace);
}
public function testModifying() {
public function testModifying(): void {
$str1Node = new String_('Foo');
$str2Node = new String_('Bar');
$printNode = new Expr\Print_($str1Node);
@ -75,7 +75,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
], $visitor3->trace);
}
public function testRemoveFromLeave() {
public function testRemoveFromLeave(): void {
$str1Node = new String_('Foo');
$str2Node = new String_('Bar');
@ -99,7 +99,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
], $visitor2->trace);
}
public function testRemoveFromEnter() {
public function testRemoveFromEnter(): void {
$str1Node = new String_('Foo');
$str2Node = new String_('Bar');
@ -122,7 +122,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
], $visitor2->trace);
}
public function testReturnArrayFromEnter() {
public function testReturnArrayFromEnter(): void {
$str1Node = new String_('Str1');
$str2Node = new String_('Str2');
$str3Node = new String_('Str3');
@ -147,7 +147,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
], $visitor2->trace);
}
public function testMerge() {
public function testMerge(): void {
$strStart = new String_('Start');
$strMiddle = new String_('End');
$strEnd = new String_('Middle');
@ -167,7 +167,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
);
}
public function testInvalidDeepArray() {
public function testInvalidDeepArray(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Invalid node structure: Contains nested arrays');
$strNode = new String_('Foo');
@ -177,7 +177,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
$this->assertEquals($stmts, $traverser->traverse($stmts));
}
public function testDontTraverseChildren() {
public function testDontTraverseChildren(): void {
$strNode = new String_('str');
$printNode = new Expr\Print_($strNode);
$varNode = new Expr\Variable('foo');
@ -212,7 +212,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
$this->assertEquals($expectedTrace, $visitor2->trace);
}
public function testDontTraverseCurrentAndChildren() {
public function testDontTraverseCurrentAndChildren(): void {
// print 'str'; -($foo * $foo);
$strNode = new String_('str');
$printNode = new Expr\Print_($strNode);
@ -254,7 +254,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
], $visitor2->trace);
}
public function testStopTraversal() {
public function testStopTraversal(): void {
$varNode1 = new Expr\Variable('a');
$varNode2 = new Expr\Variable('b');
$varNode3 = new Expr\Variable('c');
@ -343,7 +343,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
], $visitor->trace);
}
public function testReplaceWithNull() {
public function testReplaceWithNull(): void {
$one = new Int_(1);
$else1 = new Else_();
$else2 = new Else_();
@ -381,7 +381,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
], $visitor2->trace);
}
public function testRemovingVisitor() {
public function testRemovingVisitor(): void {
$visitor1 = new class () extends NodeVisitorAbstract {};
$visitor2 = new class () extends NodeVisitorAbstract {};
$visitor3 = new class () extends NodeVisitorAbstract {};
@ -404,7 +404,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($postExpected, $getVisitors());
}
public function testNoCloneNodes() {
public function testNoCloneNodes(): void {
$stmts = [new Node\Stmt\Echo_([new String_('Foo'), new String_('Bar')])];
$traverser = new NodeTraverser();
@ -415,7 +415,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideTestInvalidReturn
*/
public function testInvalidReturn($stmts, $visitor, $message) {
public function testInvalidReturn($stmts, $visitor, $message): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage($message);
@ -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

@ -7,7 +7,7 @@ use PhpParser\Node\Expr;
use PhpParser\NodeTraverser;
class FindingVisitorTest extends \PHPUnit\Framework\TestCase {
public function testFindVariables() {
public function testFindVariables(): void {
$traverser = new NodeTraverser();
$visitor = new FindingVisitor(function (Node $node) {
return $node instanceof Node\Expr\Variable;
@ -27,7 +27,7 @@ class FindingVisitorTest extends \PHPUnit\Framework\TestCase {
], $visitor->getFoundNodes());
}
public function testFindAll() {
public function testFindAll(): void {
$traverser = new NodeTraverser();
$visitor = new FindingVisitor(function (Node $node) {
return true; // All nodes

View File

@ -7,7 +7,7 @@ use PhpParser\Node\Expr;
use PhpParser\NodeTraverser;
class FirstFindingVisitorTest extends \PHPUnit\Framework\TestCase {
public function testFindFirstVariable() {
public function testFindFirstVariable(): void {
$traverser = new NodeTraverser();
$visitor = new FirstFindingVisitor(function (Node $node) {
return $node instanceof Node\Expr\Variable;
@ -21,7 +21,7 @@ class FirstFindingVisitorTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($assign->var, $visitor->getFoundNode());
}
public function testFindNone() {
public function testFindNone(): void {
$traverser = new NodeTraverser();
$visitor = new FirstFindingVisitor(function (Node $node) {
return $node instanceof Node\Expr\BinaryOp;

View File

@ -16,7 +16,7 @@ class NameResolverTest extends \PHPUnit\Framework\TestCase {
/**
* @covers \PhpParser\NodeVisitor\NameResolver
*/
public function testResolveNames() {
public function testResolveNames(): void {
$code = <<<'EOC'
<?php
@ -176,7 +176,7 @@ EOC;
/**
* @covers \PhpParser\NodeVisitor\NameResolver
*/
public function testResolveLocations() {
public function testResolveLocations(): void {
$code = <<<'EOC'
<?php
namespace NS;
@ -328,7 +328,7 @@ EOC;
);
}
public function testNoResolveSpecialName() {
public function testNoResolveSpecialName(): void {
$stmts = [new Node\Expr\New_(new Name('self'))];
$traverser = new PhpParser\NodeTraverser();
@ -337,7 +337,7 @@ EOC;
$this->assertEquals($stmts, $traverser->traverse($stmts));
}
public function testAddDeclarationNamespacedName() {
public function testAddDeclarationNamespacedName(): void {
$nsStmts = [
new Stmt\Class_('A'),
new Stmt\Interface_('B'),
@ -372,7 +372,7 @@ EOC;
$this->assertSame('F', (string) $stmts[0]->stmts[6]->namespacedName);
}
public function testAddRuntimeResolvedNamespacedName() {
public function testAddRuntimeResolvedNamespacedName(): void {
$stmts = [
new Stmt\Namespace_(new Name('NS'), [
new Expr\FuncCall(new Name('foo')),
@ -398,7 +398,7 @@ EOC;
/**
* @dataProvider provideTestError
*/
public function testError(Node $stmt, $errorMsg) {
public function testError(Node $stmt, $errorMsg): void {
$this->expectException(\PhpParser\Error::class);
$this->expectExceptionMessage($errorMsg);
@ -407,7 +407,7 @@ EOC;
$traverser->traverse([$stmt]);
}
public function provideTestError() {
public static function provideTestError() {
return [
[
new Stmt\Use_([
@ -449,7 +449,7 @@ EOC;
];
}
public function testClassNameIsCaseInsensitive() {
public function testClassNameIsCaseInsensitive(): void {
$source = <<<'EOC'
<?php
namespace Foo;
@ -470,7 +470,7 @@ EOC;
$this->assertSame('Bar\\Baz', $assign->expr->class->name);
}
public function testSpecialClassNamesAreCaseInsensitive() {
public function testSpecialClassNamesAreCaseInsensitive(): void {
$source = <<<'EOC'
<?php
namespace Foo;
@ -501,7 +501,7 @@ EOC;
$this->assertSame('STATIC', (string) $methodStmt->stmts[2]->expr->class);
}
public function testAddOriginalNames() {
public function testAddOriginalNames(): void {
$traverser = new PhpParser\NodeTraverser();
$traverser->addVisitor(new NameResolver(null, ['preserveOriginalNames' => true]));
@ -520,7 +520,7 @@ EOC;
$this->assertSame($n2, $stmts[0]->stmts[1]->name->getAttribute('originalName'));
}
public function testAttributeOnlyMode() {
public function testAttributeOnlyMode(): void {
$traverser = new PhpParser\NodeTraverser();
$traverser->addVisitor(new NameResolver(null, ['replaceNodes' => false]));

View File

@ -10,7 +10,7 @@ use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
final class NodeConnectingVisitorTest extends \PHPUnit\Framework\TestCase {
public function testConnectsNodeToItsParentNodeAndItsSiblingNodes() {
public function testConnectsNodeToItsParentNodeAndItsSiblingNodes(): void {
$ast = (new ParserFactory())->createForNewestSupportedVersion()->parse(
'<?php if (true) {} else {}'
);

View File

@ -8,7 +8,7 @@ use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
final class ParentConnectingVisitorTest extends \PHPUnit\Framework\TestCase {
public function testConnectsChildNodeToParentNode() {
public function testConnectsChildNodeToParentNode(): void {
$ast = (new ParserFactory())->createForNewestSupportedVersion()->parse(
'<?php class C { public function m() {} }'
);

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

@ -9,7 +9,7 @@ use PhpParser\Parser\Php7;
use PhpParser\Parser\Php8;
class ParserFactoryTest extends \PHPUnit\Framework\TestCase {
public function testCreate() {
public function testCreate(): void {
$factory = new ParserFactory();
$this->assertInstanceOf(Php8::class, $factory->createForNewestSupportedVersion());
$this->assertInstanceOf(Parser::class, $factory->createForHostVersion());

View File

@ -7,32 +7,32 @@ 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);
public function testParserThrowsSyntaxError() {
public function testParserThrowsSyntaxError(): void {
$this->expectException(Error::class);
$this->expectExceptionMessage('Syntax error, unexpected EOF on line 1');
$parser = $this->getParser(new Lexer());
$parser->parse('<?php foo');
}
public function testParserThrowsSpecialError() {
public function testParserThrowsSpecialError(): void {
$this->expectException(Error::class);
$this->expectExceptionMessage('Cannot use foo as self because \'self\' is a special class name on line 1');
$parser = $this->getParser(new Lexer());
$parser->parse('<?php use foo as self;');
}
public function testParserThrowsLexerError() {
public function testParserThrowsLexerError(): void {
$this->expectException(Error::class);
$this->expectExceptionMessage('Unterminated comment on line 1');
$parser = $this->getParser(new Lexer());
$parser->parse('<?php /*');
}
public function testAttributeAssignment() {
public function testAttributeAssignment(): void {
$lexer = new Lexer();
$code = <<<'EOC'
@ -107,7 +107,7 @@ EOC;
], $var->getAttributes());
}
public function testInvalidToken() {
public function testInvalidToken(): void {
$this->expectException(\RangeException::class);
$this->expectExceptionMessage('The lexer returned an invalid token (id=999, value=foobar)');
$lexer = new InvalidTokenLexer();
@ -118,7 +118,7 @@ EOC;
/**
* @dataProvider provideTestExtraAttributes
*/
public function testExtraAttributes($code, $expectedAttributes) {
public function testExtraAttributes($code, $expectedAttributes): void {
$parser = $this->getParser(new Lexer\Emulative());
$stmts = $parser->parse("<?php $code;");
$node = $stmts[0] instanceof Stmt\Expression ? $stmts[0]->expr : $stmts[0];
@ -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]],
@ -180,7 +180,7 @@ EOC;
];
}
public function testListKindAttribute() {
public function testListKindAttribute(): void {
$parser = $this->getParser(new Lexer\Emulative());
$stmts = $parser->parse('<?php list(list($x)) = $y; [[$x]] = $y;');
$this->assertSame($stmts[0]->expr->var->getAttribute('kind'), Expr\List_::KIND_LIST);
@ -189,7 +189,7 @@ EOC;
$this->assertSame($stmts[1]->expr->var->items[0]->value->getAttribute('kind'), Expr\List_::KIND_ARRAY);
}
public function testGetTokens() {
public function testGetTokens(): void {
$lexer = new Lexer();
$parser = $this->getParser($lexer);
$parser->parse('<?php echo "Foo";');

View File

@ -3,7 +3,7 @@
namespace PhpParser;
class PhpVersionTest extends \PHPUnit\Framework\TestCase {
public function testConstruction() {
public function testConstruction(): void {
$version = PhpVersion::fromComponents(8, 2);
$this->assertSame(80200, $version->id);
@ -17,13 +17,13 @@ class PhpVersionTest extends \PHPUnit\Framework\TestCase {
$this->assertSame(80200, $version->id);
}
public function testInvalidVersion() {
public function testInvalidVersion(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Invalid PHP version "8"');
PhpVersion::fromString('8');
}
public function testEquals() {
public function testEquals(): void {
$php74 = PhpVersion::fromComponents(7, 4);
$php81 = PhpVersion::fromComponents(8, 1);
$php82 = PhpVersion::fromComponents(8, 2);

View File

@ -29,26 +29,26 @@ class PrettyPrinterTest extends CodeTestAbstract {
/**
* @dataProvider provideTestPrettyPrint
*/
public function testPrettyPrint($name, $code, $expected, $mode) {
public function testPrettyPrint($name, $code, $expected, $mode): void {
$this->doTestPrettyPrintMethod('prettyPrint', $name, $code, $expected, $mode);
}
/**
* @dataProvider provideTestPrettyPrintFile
*/
public function testPrettyPrintFile($name, $code, $expected, $mode) {
public function testPrettyPrintFile($name, $code, $expected, $mode): void {
$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() {
public function testPrettyPrintExpr(): void {
$prettyPrinter = new Standard();
$expr = new Expr\BinaryOp\Mul(
new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b')),
@ -62,7 +62,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
$this->assertEquals("function () {\n return 'a\nb';\n}", $prettyPrinter->prettyPrintExpr($expr));
}
public function testCommentBeforeInlineHTML() {
public function testCommentBeforeInlineHTML(): void {
$prettyPrinter = new PrettyPrinter\Standard();
$comment = new Comment\Doc("/**\n * This is a comment\n */");
$stmts = [new Stmt\InlineHTML('Hello World!', ['comments' => [$comment]])];
@ -70,7 +70,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
$this->assertSame($expected, $prettyPrinter->prettyPrintFile($stmts));
}
public function testArraySyntaxDefault() {
public function testArraySyntaxDefault(): void {
$prettyPrinter = new Standard(['shortArraySyntax' => true]);
$expr = new Expr\Array_([
new Node\ArrayItem(new String_('val'), new String_('key'))
@ -82,13 +82,13 @@ class PrettyPrinterTest extends CodeTestAbstract {
/**
* @dataProvider provideTestKindAttributes
*/
public function testKindAttributes($node, $expected) {
public function testKindAttributes($node, $expected): void {
$prttyPrinter = new PrettyPrinter\Standard();
$result = $prttyPrinter->prettyPrintExpr($node);
$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 [
@ -138,13 +138,13 @@ class PrettyPrinterTest extends CodeTestAbstract {
}
/** @dataProvider provideTestUnnaturalLiterals */
public function testUnnaturalLiterals($node, $expected) {
public function testUnnaturalLiterals($node, $expected): void {
$prttyPrinter = new PrettyPrinter\Standard();
$result = $prttyPrinter->prettyPrintExpr($node);
$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)'],
@ -157,7 +157,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
];
}
public function testPrettyPrintWithError() {
public function testPrettyPrintWithError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot pretty-print AST with Error nodes');
$stmts = [new Stmt\Expression(
@ -167,7 +167,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
$prettyPrinter->prettyPrint($stmts);
}
public function testPrettyPrintWithErrorInClassConstFetch() {
public function testPrettyPrintWithErrorInClassConstFetch(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Cannot pretty-print AST with Error nodes');
$stmts = [new Stmt\Expression(
@ -180,7 +180,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
/**
* @dataProvider provideTestFormatPreservingPrint
*/
public function testFormatPreservingPrint($name, $code, $modification, $expected, $modeLine) {
public function testFormatPreservingPrint($name, $code, $modification, $expected, $modeLine): void {
$lexer = new Lexer\Emulative();
$parser = new Parser\Php7($lexer);
$traverser = new NodeTraverser(new NodeVisitor\CloningVisitor());
@ -209,14 +209,14 @@ 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);
}
/**
* @dataProvider provideTestRoundTripPrint
*/
public function testRoundTripPrint($name, $code, $expected, $modeLine) {
public function testRoundTripPrint($name, $code, $expected, $modeLine): void {
/**
* This test makes sure that the format-preserving pretty printer round-trips for all
* the pretty printer tests (i.e. returns the input if no changes occurred).
@ -245,14 +245,14 @@ 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')
);
}
public function testWindowsNewline() {
public function testWindowsNewline(): void {
$prettyPrinter = new Standard([
'newline' => "\r\n",
'phpVersion' => PhpVersion::fromComponents(7, 2),
@ -294,7 +294,7 @@ CODE
$code);
}
public function testInvalidNewline() {
public function testInvalidNewline(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Option "newline" must be one of "\n" or "\r\n"');
new PrettyPrinter\Standard(['newline' => 'foo']);

View File

@ -3,14 +3,14 @@
namespace PhpParser;
class TokenTest extends \PHPUnit\Framework\TestCase {
public function testGetTokenName() {
public function testGetTokenName(): void {
$token = new Token(\ord(','), ',');
$this->assertSame(',', $token->getTokenName());
$token = new Token(\T_WHITESPACE, ' ');
$this->assertSame('T_WHITESPACE', $token->getTokenName());
}
public function testIs() {
public function testIs(): void {
$token = new Token(\ord(','), ',');
$this->assertTrue($token->is(\ord(',')));
$this->assertFalse($token->is(\ord(';')));
@ -23,12 +23,12 @@ class TokenTest extends \PHPUnit\Framework\TestCase {
}
/** @dataProvider provideTestIsIgnorable */
public function testIsIgnorable(int $id, string $text, bool $isIgnorable) {
public function testIsIgnorable(int $id, string $text, bool $isIgnorable): void {
$token = new Token($id, $text);
$this->assertSame($isIgnorable, $token->isIgnorable());
}
public function provideTestIsIgnorable() {
public static function provideTestIsIgnorable() {
return [
[\T_STRING, 'foo', false],
[\T_WHITESPACE, ' ', true],
@ -38,7 +38,7 @@ class TokenTest extends \PHPUnit\Framework\TestCase {
];
}
public function testToString() {
public function testToString(): void {
$token = new Token(\ord(','), ',');
$this->assertSame(',', (string) $token);
$token = new Token(\T_STRING, 'foo');

View File

@ -50,3 +50,14 @@ class Test {
// some code
}
}
-----
<?php
class Example {
}
-----
$stmts[0]->setDocComment(new Comment\Doc("/** foo */"));
-----
<?php
/** foo */
class Example {
}

View File

@ -0,0 +1,318 @@
New dereference without parentheses
-----
<?php
new A()->foo;
new A()->foo();
new A()::FOO;
new A()::foo();
new A()::$foo;
new A()[0];
new A(){0};
new A()();
new class {}->foo;
new class {}->foo();
new class {}::FOO;
new class {}::foo();
new class {}::$foo;
new class {}[0];
new class {}{0};
new class {}();
-----
array(
0: Stmt_Expression(
expr: Expr_PropertyFetch(
var: Expr_New(
class: Name(
name: A
)
args: array(
)
)
name: Identifier(
name: foo
)
)
)
1: Stmt_Expression(
expr: Expr_MethodCall(
var: Expr_New(
class: Name(
name: A
)
args: array(
)
)
name: Identifier(
name: foo
)
args: array(
)
)
)
2: Stmt_Expression(
expr: Expr_ClassConstFetch(
class: Expr_New(
class: Name(
name: A
)
args: array(
)
)
name: Identifier(
name: FOO
)
)
)
3: Stmt_Expression(
expr: Expr_StaticCall(
class: Expr_New(
class: Name(
name: A
)
args: array(
)
)
name: Identifier(
name: foo
)
args: array(
)
)
)
4: Stmt_Expression(
expr: Expr_StaticPropertyFetch(
class: Expr_New(
class: Name(
name: A
)
args: array(
)
)
name: VarLikeIdentifier(
name: foo
)
)
)
5: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_New(
class: Name(
name: A
)
args: array(
)
)
dim: Scalar_Int(
value: 0
)
)
)
6: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_New(
class: Name(
name: A
)
args: array(
)
)
dim: Scalar_Int(
value: 0
)
)
)
7: Stmt_Expression(
expr: Expr_FuncCall(
name: Expr_New(
class: Name(
name: A
)
args: array(
)
)
args: array(
)
)
)
8: Stmt_Expression(
expr: Expr_PropertyFetch(
var: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
name: Identifier(
name: foo
)
)
)
9: Stmt_Expression(
expr: Expr_MethodCall(
var: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
name: Identifier(
name: foo
)
args: array(
)
)
)
10: Stmt_Expression(
expr: Expr_ClassConstFetch(
class: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
name: Identifier(
name: FOO
)
)
)
11: Stmt_Expression(
expr: Expr_StaticCall(
class: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
name: Identifier(
name: foo
)
args: array(
)
)
)
12: Stmt_Expression(
expr: Expr_StaticPropertyFetch(
class: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
name: VarLikeIdentifier(
name: foo
)
)
)
13: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
dim: Scalar_Int(
value: 0
)
)
)
14: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
dim: Scalar_Int(
value: 0
)
)
)
15: Stmt_Expression(
expr: Expr_FuncCall(
name: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
args: array(
)
)
)
)

View File

@ -19,6 +19,7 @@ $a = $b = $c = $d = ($f and true);
$a ? $b : $c ? $d : $e ? $f : $g;
$a ? $b : ($c ? $d : ($e ? $f : $g));
$a ? $b ? $c : $d : $f;
$a === $b ? $c : $d;
$a ?? $b ?? $c;
($a ?? $b) ?? $c;
@ -73,6 +74,7 @@ $a = $b = $c = $d = ($f and true);
(($a ? $b : $c) ? $d : $e) ? $f : $g;
$a ? $b : ($c ? $d : ($e ? $f : $g));
$a ? $b ? $c : $d : $f;
$a === $b ? $c : $d;
$a ?? $b ?? $c;
($a ?? $b) ?? $c;
$a ?? ($b ? $c : $d);

View File

@ -39,11 +39,11 @@ $visitor = new class extends PhpParser\NodeVisitorAbstract {
private $tokens;
public $hasProblematicConstruct;
public function setTokens(array $tokens) {
public function setTokens(array $tokens): void {
$this->tokens = $tokens;
}
public function beforeTraverse(array $nodes) {
public function beforeTraverse(array $nodes): void {
$this->hasProblematicConstruct = false;
}