Skip to content

Commit

Permalink
Merge branch 'feature/php8-add-tests-for-type-mixed' of https://githu…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jul 20, 2020
2 parents 285f465 + 6d6b0eb commit 4eb94f8
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/Core/File/GetMemberPropertiesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,12 @@ function_call( 'param', new class {
/* testNestedMethodParam 2 */
public function __construct( $open, $post_id ) {}
}, 10, 2 );

class PHP8Mixed {
/* testPHP8MixedTypeHint */
public static miXed $mixed;

/* testPHP8MixedTypeHintNullable */
// Intentional fatal error - nullability is not allowed with mixed, but that's not the concern of the method.
private ?mixed $nullableMixed;
}
20 changes: 20 additions & 0 deletions tests/Core/File/GetMemberPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,26 @@ public function dataGetMemberProperties()
'nullable_type' => false,
],
],
[
'/* testPHP8MixedTypeHint */',
[
'scope' => 'public',
'scope_specified' => true,
'is_static' => true,
'type' => 'miXed',
'nullable_type' => false,
],
],
[
'/* testPHP8MixedTypeHintNullable */',
[
'scope' => 'private',
'scope_specified' => true,
'is_static' => false,
'type' => '?mixed',
'nullable_type' => true,
],
],
];

}//end dataGetMemberProperties()
Expand Down
7 changes: 7 additions & 0 deletions tests/Core/File/GetMethodParametersTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ function myFunction($a = 10 & 20) {}

/* testArrowFunction */
fn(int $a, ...$b) => $b;

/* testPHP8MixedTypeHint */
function mixedTypeHint(mixed &...$var1) {}

/* testPHP8MixedTypeHintNullable */
// Intentional fatal error - nullability is not allowed with mixed, but that's not the concern of the method.
function mixedTypeHintNullable(?Mixed $var1) {}
44 changes: 44 additions & 0 deletions tests/Core/File/GetMethodParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,50 @@ public function testArrowFunction()
}//end testArrowFunction()


/**
* Verify recognition of PHP8 mixed type declaration.
*
* @return void
*/
public function testPHP8MixedTypeHint()
{
$expected = [];
$expected[0] = [
'name' => '$var1',
'content' => 'mixed &...$var1',
'pass_by_reference' => true,
'variable_length' => true,
'type_hint' => 'mixed',
'nullable_type' => false,
];

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

}//end testPHP8MixedTypeHint()


/**
* Verify recognition of PHP8 mixed type declaration with nullability.
*
* @return void
*/
public function testPHP8MixedTypeHintNullable()
{
$expected = [];
$expected[0] = [
'name' => '$var1',
'content' => '?Mixed $var1',
'pass_by_reference' => false,
'variable_length' => false,
'type_hint' => '?Mixed',
'nullable_type' => true,
];

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

}//end testPHP8MixedTypeHintNullable()


/**
* Test helper.
*
Expand Down
7 changes: 7 additions & 0 deletions tests/Core/File/GetMethodPropertiesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@ class ReturnMe {
return $this;
}
}

/* testPHP8MixedTypeHint */
function mixedTypeHint() :mixed {}

/* testPHP8MixedTypeHintNullable */
// Intentional fatal error - nullability is not allowed with mixed, but that's not the concern of the method.
function mixedTypeHintNullable(): ?mixed {}
46 changes: 46 additions & 0 deletions tests/Core/File/GetMethodPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,52 @@ public function testReturnTypeStatic()
}//end testReturnTypeStatic()


/**
* Test a function with return type "mixed".
*
* @return void
*/
public function testPHP8MixedTypeHint()
{
$expected = [
'scope' => 'public',
'scope_specified' => false,
'return_type' => 'mixed',
'nullable_return_type' => false,
'is_abstract' => false,
'is_final' => false,
'is_static' => false,
'has_body' => true,
];

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

}//end testPHP8MixedTypeHint()


/**
* Test a function with return type "mixed" and nullability.
*
* @return void
*/
public function testPHP8MixedTypeHintNullable()
{
$expected = [
'scope' => 'public',
'scope_specified' => false,
'return_type' => '?mixed',
'nullable_return_type' => true,
'is_abstract' => false,
'is_final' => false,
'is_static' => false,
'has_body' => true,
];

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

}//end testPHP8MixedTypeHintNullable()


/**
* Test helper.
*
Expand Down

0 comments on commit 4eb94f8

Please sign in to comment.