Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Tests/BackCompat/BCFile/GetMethodPropertiesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ interface FooBar {
// Intentional fatal error - duplicate types are not allowed in union types, but that's not the concern of the method.
function duplicateTypeInUnion(): int | /*comment*/ string | INT {}

/* testPHP81NeverType */
function never(): never {}

/* testPHP81NullableNeverType */
// Intentional fatal error - nullability is not allowed with never, but that's not the concern of the method.
function nullableNever(): ?never {}

/* testNotAFunction */
return true;

Expand Down
46 changes: 46 additions & 0 deletions Tests/BackCompat/BCFile/GetMethodPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,52 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment()
$this->getMethodPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected);
}

/**
* Verify recognition of PHP8.1 type "never".
*
* @return void
*/
public function testPHP81NeverType()
{
$expected = [
'scope' => 'public',
'scope_specified' => false,
'return_type' => 'never',
'return_type_token' => 7, // Offset from the T_FUNCTION token.
'return_type_end_token' => 7, // Offset from the T_FUNCTION token.
'nullable_return_type' => false,
'is_abstract' => false,
'is_final' => false,
'is_static' => false,
'has_body' => true,
];

$this->getMethodPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected);
}

/**
* Verify recognition of PHP8.1 type "never" with (illegal) nullability.
*
* @return void
*/
public function testPHP81NullableNeverType()
{
$expected = [
'scope' => 'public',
'scope_specified' => false,
'return_type' => '?never',
'return_type_token' => 8, // Offset from the T_FUNCTION token.
'return_type_end_token' => 8, // Offset from the T_FUNCTION token.
'nullable_return_type' => true,
'is_abstract' => false,
'is_final' => false,
'is_static' => false,
'has_body' => true,
];

$this->getMethodPropertiesTestHelper('/* ' . __FUNCTION__ . ' */', $expected);
}

/**
* Test for incorrect tokenization of array return type declarations in PHPCS < 2.8.0.
*
Expand Down