[ 'code' => ' 'ForbiddenCode', ], 'varDumpCased' => [ 'code' => ' 'ForbiddenCode', ], 'execTicks' => [ 'code' => ' 'ForbiddenCode', ], 'exec' => [ 'code' => ' 'ForbiddenCode', ], 'execCased' => [ 'code' => ' 'ForbiddenCode', ], ]; } public function providerValidCodeParse(): iterable { return [ 'execWithSuppression' => [ 'code' => '&1", $output, $returnValue); if ($returnValue === 0) { echo "success"; }', ], 'execWithoutSuppression' => [ 'code' => '&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 testForbiddenCodeFunctionViaFunctions(): 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 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; } }