private static SourceUnit ParseFile( TextWriter consoleOutput, PhpParseOptions parseOptions, PhpParseOptions scriptParseOptions, SourceText content, CommandLineSourceFile file) { // TODO: new parser implementation based on Roslyn // TODO: file.IsScript ? scriptParseOptions : parseOptions var tree = CodeSourceUnit.ParseCode(content.ToString(), file.Path, new TextErrorSink(consoleOutput)); return(tree); }
private static void ProcessTestsXml(Pchp.Core.Context ctx, string source, string path, ITestCaseDiscoverySink discoverySink) { var testsEl = XElement.Load(path); foreach (var testCaseClassEl in testsEl.Descendants("testCaseClass")) { var phpClassName = testCaseClassEl.Attribute("name").Value; var classInfo = ctx.GetDeclaredType(phpClassName, autoload: false); var filePath = Path.GetFullPath(Path.Combine(ctx.RootPath, classInfo.RelativePath)); // The file might not exist as PHPUnit may mistakenly select classes and methods in its own PHAR, // namely PHPUnit\Framework\WarningTestCase::Warning (happened with PHPUnit 7.5.9) var unit = File.Exists(filePath) ? CodeSourceUnit.ParseCode(File.ReadAllText(filePath), filePath) : null; foreach (var testCaseMethodEl in testCaseClassEl.Descendants("testCaseMethod")) { var methodName = testCaseMethodEl.Attribute("name").Value; var testName = PhpUnitHelper.GetTestNameFromPhp(classInfo, methodName); var testCase = new TestCase(testName, PhpUnitTestExecutor.ExecutorUri, source); if (unit != null) { testCase.DisplayName = $"{classInfo.Name}::{methodName}"; testCase.CodeFilePath = filePath; testCase.LineNumber = GetLineNumber(unit, phpClassName, methodName); } ; ProcessTraits(testCase, testCaseMethodEl.Attribute("groups")?.Value); discoverySink.SendTestCase(testCase); } } }