Skip to content

Commit

Permalink
fix tests string unpack only from PHP 8.1 and similar PHP version res…
Browse files Browse the repository at this point in the history
…tricted errors and fix tests
  • Loading branch information
kkmuffme committed Mar 12, 2024
1 parent 2fe13f9 commit 3b0d5c6
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions tests/ArgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,24 @@ function Foo(string $a, string ...$b) : void {}
/** @return array<array-key, string> */
function Baz(string ...$c) {
Foo(...$c);
if ($c !== array()) {
Foo(...array_values($c));
}
return $c;
}',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1',
],
'unpackArgNonNamed' => [
'code' => '<?php
function Foo(string $a, string ...$b) : void {}
/** @param non-empty-array<int, string> $c */
function Baz($c): void {
Foo(...$c);
}',
],
'unpackByRefArg' => [
'code' => '<?php
Expand All @@ -100,7 +115,7 @@ function example (int &...$x): void {}
example(...$z);',
'assertions' => [
'$y' => 'int',
'$z' => 'array<int, int>',
'$z' => 'list<int>',
],
],
'namedArgAfterUnpack' => [
Expand Down Expand Up @@ -134,6 +149,9 @@ function Foo(string $a, string ...$b) : void {}
function Baz($c) : void {
Foo("hello", ...$c);
}',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1',
],
'callMapClassOptionalArg' => [
'code' => '<?php
Expand Down Expand Up @@ -281,13 +299,19 @@ function foo(array $input) : CustomerData {
email: $input["email"],
);
}',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
],
'useNamedArgumentsSimple' => [
'code' => '<?php
function takesArguments(string $name, int $age) : void {}
takesArguments(name: "hello", age: 5);
takesArguments(age: 5, name: "hello");',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
],
'useNamedArgumentsSpread' => [
'code' => '<?php
Expand All @@ -297,7 +321,7 @@ function takesArguments(string $name, int $age) : void {}
takesArguments(...$args);',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
'php_version' => '8.1',
],
'useNamedVariadicArguments' => [
'code' => '<?php
Expand All @@ -315,7 +339,7 @@ function takesArguments(int ...$args) : void {}
takesArguments(...["age" => 5]);',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
'php_version' => '8.1',
],
'variadicArgsOptional' => [
'code' => '<?php
Expand Down Expand Up @@ -407,6 +431,20 @@ public function __construct(public mixed $default = null) {
public function providerInvalidCodeParse(): iterable
{
return [
'unpackArgPossiblyPositionalArrayKeyOrdering' => [
'code' => '<?php
function Foo(string $a, string ...$b) : void {}
/** @return array<array-key, string> */
function Baz(string ...$c) {
Foo(...$c);
return $c;
}',
// possibly positional after named
'error_message' => 'PossiblyInvalidArgument',
'ignored_issues' => [],
'php_version' => '8.1',
],
'arrayPushArgumentUnpackingWithBadArg' => [
'code' => '<?php
$a = [];
Expand Down Expand Up @@ -666,7 +704,7 @@ function processUserDataInvalid(array $data) : User {
}',
'error_message' => 'MixedArgument',
'ignored_issues' => [],
'php_version' => '8.0',
'php_version' => '8.1',
],
'arrayWithoutAllNamedParametersSuppressMixed' => [
'code' => '<?php
Expand All @@ -687,7 +725,7 @@ function processUserDataInvalid(array $data) : User {
}',
'error_message' => 'TooFewArguments',
'ignored_issues' => [],
'php_version' => '8.0',
'php_version' => '8.1',
],
'wrongTypeVariadicArguments' => [
'code' => '<?php
Expand Down Expand Up @@ -782,6 +820,8 @@ function foo(int ...$values): array
}
',
'error_message' => 'LessSpecificReturnStatement',
'ignored_issues' => [],
'php_version' => '8.0',
],
'preventUnpackingPossiblyIterable' => [
'code' => '<?php
Expand All @@ -802,6 +842,7 @@ function foo(int $arg1, int $arg2): void {}
foo(...$test);
',
'error_message' => 'PossiblyInvalidArgument',
'ignored_issues' => ['TooFewArguments'],
],
'noNamedArguments' => [
'code' => '<?php
Expand Down Expand Up @@ -831,7 +872,7 @@ function foo(int $arg1, int $arg2): void {}
',
'error_message' => 'NamedArgumentNotAllowed',
'ignored_issues' => [],
'php_version' => '8.0',
'php_version' => '8.1',
],
'variadicArgumentWithNoNamedArgumentsPreventsPassingArrayWithStringKey' => [
'code' => '<?php
Expand All @@ -847,6 +888,8 @@ function foo(int ...$values): array
foo(...["a" => 0]);
',
'error_message' => 'NamedArgumentNotAllowed',
'ignored_issues' => [],
'php_version' => '8.1',
],
'unpackNonArrayKeyIterable' => [
'code' => '<?php
Expand Down Expand Up @@ -921,6 +964,8 @@ public function __construct(
);
',
'error_message' => 'TooFewArguments',
'ignored_issues' => [],
'php_version' => '8.0',
],
'SealedRefuseUnsealed' => [
'code' => '<?php
Expand Down

0 comments on commit 3b0d5c6

Please sign in to comment.