expectExceptionMessage('InvalidScalarArgument');
$this->expectException(CodeException::class);
$this->addFile(
'somefile.php',
'analyzeFile('somefile.php', new Context());
}
/**
* @throws ConfigException
* @runInSeparateProcess
*/
public function testVariadicFunctionFromAutoloadFile(): void
{
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
TestConfig::loadFromXML(
dirname(__DIR__),
'
',
),
);
$file_path = getcwd() . '/src/somefile.php';
$this->addFile(
$file_path,
'analyzeFile($file_path, new Context());
}
/**
* @return iterable
*/
public function providerValidCodeParse(): iterable
{
return [
'variadic' => [
'code' => '
*/
function f($req, $opt = null, ...$params) {
return $params;
}
f(1);
f(1, 2);
f(1, 2, 3);
f(1, 2, 3, 4);
f(1, 2, 3, 4, 5);',
],
'funcNumArgsVariadic' => [
'code' => ' [
'code' => '
*/
function f(int ...$a_list) {
return array_map(
/**
* @return int
*/
function (int $a) {
return $a + 1;
},
$a_list
);
}
f(1);
f(1, 2);
f(1, 2, 3);
/**
* @param string ...$a_list
* @return void
*/
function g(string ...$a_list) {
}',
],
];
}
private function getProjectAnalyzerWithConfig(Config $config): ProjectAnalyzer
{
$project_analyzer = new ProjectAnalyzer(
$config,
new Providers(
$this->file_provider,
new FakeParserCacheProvider(),
),
);
$project_analyzer->setPhpVersion('7.3', 'tests');
$config->setIncludeCollector(new IncludeCollector());
$config->visitComposerAutoloadFiles($project_analyzer, null);
return $project_analyzer;
}
}