/** * @param result * @return phpunit configuration option followed by the generated phpunit.xml launcher file. Or the test directory if only one. */ private String getTestDirectoryOrFiles() { List<File> testDirs = project.getFileSystem().getTestDirs(); String directoryOrFiles = null; if (testDirs.size() == 1) { directoryOrFiles = testDirs.get(0).toString(); } else { // in case of multiple source directories, phpunit.xml file is generated and passed to phpunit. LOG.warn("Phpunit does not support multiple source directories for the moment."); LOG.warn("Group your tests folder under the same directory or use phpunit.xml file"); List<File> testFiles = project.getFileSystem().getTestFiles(PHP); LOG.info("Generating phpunit.xml file containing all your test files..."); File phpunitXml = createPhpunitConfigurationFile(testFiles); LOG.warn(phpunitXml + " file generated."); directoryOrFiles = PHPUNIT_CONFIGURATION_OPTION + phpunitXml.toString(); } return directoryOrFiles; }
/** * From absolute path. * * @param path * the path * @param project * the current project * @return the php file */ public PhpFile fromAbsolutePath(String path, Project project) { PhpFile phpFile = null; if (path != null) { File file = new File(path); ProjectFileSystem fileSystem = project.getFileSystem(); List<File> sourceFiles = fileSystem.getSourceFiles(PHP); List<File> testFiles = fileSystem.getTestFiles(PHP); if (sourceFiles.contains(file)) { phpFile = fromIOFile(file, fileSystem.getSourceDirs(), false); } if (phpFile == null && testFiles.contains(file)) { phpFile = fromIOFile(file, fileSystem.getTestDirs(), true); } } return phpFile; }
/** * Imports php file contains in the source and tests folders. * * @param project * the project * @param context * the context * @throws IOException * Signals that an I/O exception has occurred. */ protected void doAnalyse(Project project, SensorContext context) throws IOException { // Importing source files ProjectFileSystem fileSystem = project.getFileSystem(); Charset sourceCharset = fileSystem.getSourceCharset(); List<File> sourceDirs = fileSystem.getSourceDirs(); List<File> sourceFiles = fileSystem.getSourceFiles(PHP); parseDirs(context, sourceFiles, sourceDirs, false, sourceCharset); for (File directory : sourceDirs) { LOG.info(directory.getName()); } // Importing tests files List<File> testDirs = fileSystem.getTestDirs(); List<File> testFiles = fileSystem.getTestFiles(PHP); parseDirs(context, testFiles, testDirs, true, sourceCharset); // Display source dirs and tests directories if info level is enabled. for (File directory : testDirs) { LOG.info(directory.getName()); } }