*/ public function providerInvalidCodeParse(): iterable { return [ 'varDump' => [ ' 'ForbiddenCode', ], 'varDumpCased' => [ ' 'ForbiddenCode', ], 'execTicks' => [ ' 'ForbiddenCode', ], 'exec' => [ ' 'ForbiddenCode', ], 'execCased' => [ ' 'ForbiddenCode', ], ]; } /** * @return iterable,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'execWithSuppression' => [ '&1", $output, $returnValue); if ($returnValue === 0) { echo "success"; }', ], 'execWithoutSuppression' => [ '&1", $output, $returnValue); if ($returnValue === 0) { echo "success"; }', ], ]; } public function testAllowedEchoFunction(): void { $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testForbiddenEchoFunctionViaFunctions(): void { $this->expectExceptionMessage('ForbiddenCode'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testForbiddenEchoFunctionViaFlag(): void { $this->expectExceptionMessage('ForbiddenEcho'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testAllowedPrintFunction(): void { $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testForbiddenPrintFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testAllowedVarExportFunction(): void { $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testForbiddenVarExportFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testForbiddenEmptyFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testForbiddenExitFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testForbiddenDieFunction(): void { $this->expectExceptionMessage('ForbiddenCode'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } public function testForbiddenEvalExpression(): void { $this->expectExceptionMessage('ForbiddenCode'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), ' ' ) ); $file_path = getcwd() . '/src/somefile.php'; $this->addFile( $file_path, 'analyzeFile($file_path, new Context()); } private function getProjectAnalyzerWithConfig(Config $config): ProjectAnalyzer { $p = new ProjectAnalyzer( $config, new Providers( $this->file_provider, new FakeParserCacheProvider() ) ); $p->setPhpVersion('7.4', 'tests'); return $p; } }