, * ignored_issues?: list, * php_version?: string, * } * > */ abstract public function providerValidCodeParse(): iterable; /** * @dataProvider providerValidCodeParse * @param array $assertions * @param list $ignored_issues * @small */ public function testValidCode( string $code, array $assertions = [], array $ignored_issues = [], string $php_version = '7.4', ): void { $test_name = $this->getTestName(); if (strpos($test_name, 'PHP80-') !== false) { if (version_compare(PHP_VERSION, '8.0.0', '<')) { $this->markTestSkipped('Test case requires PHP 8.0.'); } } elseif (strpos($test_name, 'PHP81-') !== false) { if (version_compare(PHP_VERSION, '8.1.0', '<')) { $this->markTestSkipped('Test case requires PHP 8.1.'); } } elseif (strpos($test_name, 'SKIPPED-') !== false) { $this->markTestSkipped('Skipped due to a bug.'); } // sanity check - do we have a PHP tag? if (strpos($code, 'fail('Test case must have a setCustomErrorLevel($issue_name, Config::REPORT_SUPPRESS); } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $code = str_replace("\n", "\r\n", $code); } $context = new Context(); $this->project_analyzer->setPhpVersion($php_version, 'tests'); $codebase = $this->project_analyzer->getCodebase(); $codebase->enterServerMode(); $codebase->config->visitPreloadedStubFiles($codebase); // avoid MethodSignatureMismatch for __unserialize/() when extending DateTime if (PHP_VERSION_ID >= 8_02_00) { $this->addStubFile( 'stubOne.phpstub', 'addFile($file_path, $code); $this->analyzeFile($file_path, $context); $actual_vars = []; foreach ($assertions as $var => $_) { $exact = false; if ($var && strpos($var, '===') === strlen($var) - 3) { $var = substr($var, 0, -3); $exact = true; } if (isset($context->vars_in_scope[$var])) { $value = $context->vars_in_scope[$var]->getId($exact); if ($exact) { $actual_vars[$var . '==='] = $value; } else { $actual_vars[$var] = $value; } } } $this->assertSame($assertions, $actual_vars); } }