diff --git a/.cirrus/modules/qa.star b/.cirrus/modules/qa.star index 7e3ba392f..b711b66b9 100644 --- a/.cirrus/modules/qa.star +++ b/.cirrus/modules/qa.star @@ -115,16 +115,6 @@ def qa_ruling_env(): "GRADLE_TASK": QA_RULING_GRADLE_TASK, "SQ_VERSION": QA_QUBE_LATEST_RELEASE, "KEEP_ORCHESTRATOR_RUNNING": "true", - "matrix": [ - {"PHP_PROJECT": "Flysystem"}, - {"PHP_PROJECT": "Monica"}, - {"PHP_PROJECT": "PhpCodeSniffer"}, - {"PHP_PROJECT": "PhpMailer"}, - {"PHP_PROJECT": "Psysh"}, - {"PHP_PROJECT": "PhpWord"}, - {"PHP_PROJECT": "RubixML"}, - {"PHP_PROJECT": "PhpSpreadsheet"}, - ], "GITHUB_TOKEN": "VAULT[development/github/token/licenses-ro token]", } @@ -134,7 +124,7 @@ def qa_ruling_script(): "git submodule update --init --depth 1", "source cirrus-env QA", "source .cirrus/use-gradle-wrapper.sh", - "./gradlew \"${GRADLE_TASK}\" \"-Dsonar.runtimeVersion=${SQ_VERSION}\" --tests \"PhpGeneralRulingTest.test${PHP_PROJECT}\" --info --build-cache --console plain --no-daemon" + "./gradlew \"${GRADLE_TASK}\" \"-Dsonar.runtimeVersion=${SQ_VERSION}\" --info --build-cache --console plain --no-daemon" ] diff --git a/its/plugin/tests/build.gradle.kts b/its/plugin/tests/build.gradle.kts index d882521ca..f5aabaff4 100644 --- a/its/plugin/tests/build.gradle.kts +++ b/its/plugin/tests/build.gradle.kts @@ -19,10 +19,6 @@ dependencies { "integrationTestCompileOnly"(libs.jsr305) } -(tasks["integrationTest"] as Test).filter { - setIncludePatterns("Tests") -} - // Mandatory for the orchestrator in the "Tests" class, since it requires the custom rules plugin JAR tasks.named("integrationTest") { dependsOn(":php-custom-rules-plugin:shadowJar") diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/CpdTokenTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/CpdTokenTest.java index 9e4cefbff..7fe1ae0d1 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/CpdTokenTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/CpdTokenTest.java @@ -20,26 +20,19 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import static com.sonar.it.php.Tests.createScanner; - -public class CpdTokenTest { - - @RegisterExtension - public static OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; +public class CpdTokenTest extends OrchestratorTest { private static final String PROJECT = "php8-features"; @Test void supportPhp8Features() { - Tests.provisionProject(PROJECT, PROJECT, "php", "it-profile"); + provisionProject(PROJECT, PROJECT, "php", "it-profile"); SonarScanner build = createScanner() .setProjectKey(PROJECT) .setProjectName(PROJECT) - .setProjectDir(Tests.projectDirectoryFor(PROJECT)); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + .setProjectDir(projectDirectoryFor(PROJECT)); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); } } diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/CustomRulesTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/CustomRulesTest.java index 2520dc84d..0f42c1a9c 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/CustomRulesTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/CustomRulesTest.java @@ -20,33 +20,28 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.util.List; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import static com.sonar.it.php.Tests.createScanner; import static org.assertj.core.api.Assertions.assertThat; import static org.sonarqube.ws.Issues.Issue; -class CustomRulesTest { +class CustomRulesTest extends OrchestratorTest { - @RegisterExtension - public static final OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; private static final String PROJECT_KEY = "custom-rules"; private static final String PROJECT_NAME = "Custom Rules"; private static List issues; @BeforeAll static void prepare() { - Tests.provisionProject(PROJECT_KEY, PROJECT_NAME, "php", "php-custom-rules-profile"); + provisionProject(PROJECT_KEY, PROJECT_NAME, "php", "php-custom-rules-profile"); SonarScanner build = createScanner() - .setProjectDir(Tests.projectDirectoryFor("custom_rules")) + .setProjectDir(projectDirectoryFor("custom_rules")) .setProjectKey(PROJECT_KEY) .setProjectName(PROJECT_NAME); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); - issues = Tests.issuesForComponent(PROJECT_KEY); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); + issues = issuesForComponent(PROJECT_KEY); } @Test @@ -60,8 +55,8 @@ void subscriptionBaseVisitorCheck() { } private static void assertSingleIssue(String ruleKey, int expectedLine, String expectedMessage, String expectedDebt) { - assertThat(Tests.issuesForRule(issues, ruleKey)).hasSize(1); - var issue = Tests.issuesForRule(issues, ruleKey).get(0); + assertThat(issuesForRule(issues, ruleKey)).hasSize(1); + var issue = issuesForRule(issues, ruleKey).get(0); assertThat(issue.getLine()).isEqualTo(expectedLine); assertThat(issue.getMessage()).isEqualTo(expectedMessage); assertThat(issue.getDebt()).isEqualTo(expectedDebt); diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/FrameworkDetectionPHPTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/FrameworkDetectionPHPTest.java index be576b9e4..ba9930c8a 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/FrameworkDetectionPHPTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/FrameworkDetectionPHPTest.java @@ -20,19 +20,13 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.util.List; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Issues; -import static com.sonar.it.php.Tests.createScanner; import static org.assertj.core.api.Assertions.assertThat; -class FrameworkDetectionPHPTest { - - @RegisterExtension - public static final OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; +class FrameworkDetectionPHPTest extends OrchestratorTest { @Test void shouldNotDetectIssueWhenFrameworkDetectionDisabled() { @@ -47,15 +41,15 @@ void shouldDetectIssueWhenFrameworkDetectionEnabled() { } List scanDrupalProject(String name, String key, boolean frameworkDetectionEnabled) { - Tests.provisionProject(key, name, "php", "drupal-profile"); + provisionProject(key, name, "php", "drupal-profile"); SonarScanner build = createScanner() - .setProjectDir(Tests.projectDirectoryFor("drupal_project")) + .setProjectDir(projectDirectoryFor("drupal_project")) .setProjectKey(key) .setProjectName(name) .setSourceEncoding("UTF-8") .setSourceDirs(".") .setProperty("sonar.php.frameworkDetection", "" + frameworkDetectionEnabled); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); - return Tests.issuesForComponent(key); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); + return issuesForComponent(key); } } diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/NoSonarTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/NoSonarTest.java index 312387a18..dc0cf3f20 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/NoSonarTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/NoSonarTest.java @@ -20,29 +20,24 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import java.util.List; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Issues.Issue; -import static com.sonar.it.php.Tests.createScanner; import static org.assertj.core.api.Assertions.assertThat; -class NoSonarTest { +class NoSonarTest extends OrchestratorTest { - @RegisterExtension - public static OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; private static final String PROJECT_KEY = "nosonar-project"; private static final String PROJECT_NAME = "NOSONAR Project"; - private static final File PROJECT_DIR = Tests.projectDirectoryFor("nosonar"); + private static final File PROJECT_DIR = projectDirectoryFor("nosonar"); @BeforeAll static void startServer() { - Tests.provisionProject(PROJECT_KEY, PROJECT_NAME, "php", "nosonar-profile"); + provisionProject(PROJECT_KEY, PROJECT_NAME, "php", "nosonar-profile"); SonarScanner build = createScanner() .setProjectDir(PROJECT_DIR) .setProjectKey(PROJECT_KEY) @@ -50,15 +45,15 @@ static void startServer() { .setSourceEncoding("UTF-8") .setSourceDirs("."); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); } @Test void test() { - List issues = Tests.issuesForComponent(PROJECT_KEY); + List issues = issuesForComponent(PROJECT_KEY); - assertThat(Tests.issuesForRule(issues, "php:S1116")).hasSize(1); - assertThat(Tests.issuesForRule(issues, "php:NoSonar")).hasSize(2); + assertThat(issuesForRule(issues, "php:S1116")).hasSize(1); + assertThat(issuesForRule(issues, "php:NoSonar")).hasSize(2); } } diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/NonPhpProjectTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/NonPhpProjectTest.java index 1957e00b4..bc7dc55a2 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/NonPhpProjectTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/NonPhpProjectTest.java @@ -21,23 +21,18 @@ import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import static com.sonar.it.php.Tests.createScanner; import static org.assertj.core.api.Assertions.assertThat; -class NonPhpProjectTest { +class NonPhpProjectTest extends OrchestratorTest { - @RegisterExtension - public static OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; private static final String PROJECT_KEY = "non-php-project"; private static final String PROJECT_NAME = "Non Php Project"; - private static final File PROJECT_DIR = Tests.projectDirectoryFor("js-project"); + private static final File PROJECT_DIR = projectDirectoryFor("js-project"); private static BuildResult buildResult; @@ -51,13 +46,13 @@ static void startServer() { // workaround following a change on SonarQube .setProperty("sonar.plugins.downloadOnlyRequired", "false"); - buildResult = orchestrator.executeBuild(build); + buildResult = ORCHESTRATOR.executeBuild(build); } @Test void testExecutionOfSensors() { - assertThat(buildResult.getLogs()).doesNotContain(Tests.PHP_SENSOR_NAME); - assertThat(buildResult.getLogs()).doesNotContain(Tests.PHP_INI_SENSOR_NAME); + assertThat(buildResult.getLogs()).doesNotContain(PHP_SENSOR_NAME); + assertThat(buildResult.getLogs()).doesNotContain(PHP_INI_SENSOR_NAME); assertThat(buildResult.getLogs()).contains("1 file indexed"); } diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/Tests.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/OrchestratorTest.java similarity index 75% rename from its/plugin/tests/src/integrationTest/java/com/sonar/it/php/Tests.java rename to its/plugin/tests/src/integrationTest/java/com/sonar/it/php/OrchestratorTest.java index b53f01065..a7c833352 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/Tests.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/OrchestratorTest.java @@ -32,7 +32,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.CheckForNull; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Components; import org.sonarqube.ws.Issues; @@ -49,23 +48,23 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; -class Tests { +class OrchestratorTest { - public static final String PROJECT_ROOT_DIR = "../projects/"; + private static final String PROJECT_ROOT_DIR = "../projects/"; private static final String RESOURCE_DIRECTORY = "/com/sonar/it/php/"; - public static final String PHP_SENSOR_NAME = "PHP sensor"; + protected static final String PHP_SENSOR_NAME = "PHP sensor"; - public static final String PHP_INI_SENSOR_NAME = "Analyzer for \"php.ini\" files"; + protected static final String PHP_INI_SENSOR_NAME = "Analyzer for \"php.ini\" files"; public static final FileLocation PHP_PLUGIN_LOCATION = FileLocation.byWildcardFilename(new File("../../../sonar-php-plugin/build/libs"), "sonar-php-plugin-*-all.jar"); - public static final String SCANNER_VERSION = "6.1.0.4477"; + private static final String SCANNER_VERSION = "6.1.0.4477"; private static final Pattern DEBUG_AND_INFO_LOG_LINE_PATTERN = Pattern.compile("\\d{2}:\\d{2}:\\d{2}\\.\\d{3}\\s(INFO|DEBUG)\\s.*"); @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = OrchestratorExtension.builderEnv() + protected static final OrchestratorExtension ORCHESTRATOR = OrchestratorExtension.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE")) // PHP Plugin @@ -80,7 +79,7 @@ class Tests { .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "sleep.xml")) .build(); - public static SonarScanner createScanner() { + protected static SonarScanner createScanner() { return SonarScanner.create() .setScannerVersion(SCANNER_VERSION) .setProjectVersion("1.0") @@ -91,18 +90,18 @@ public static SonarScanner createScanner() { private static final Pattern TASK_ID_PATTERN = Pattern.compile("/api/ce/task\\?id=(\\S+)"); - public static void provisionProject(String projectKey, String projectName, String languageKey, String profileName) { + protected static void provisionProject(String projectKey, String projectName, String languageKey, String profileName) { Server server = ORCHESTRATOR.getServer(); server.provisionProject(projectKey, projectName); server.associateProjectToQualityProfile(projectKey, languageKey, profileName); } - static File projectDirectoryFor(String projectDirName) { - return new File(Tests.PROJECT_ROOT_DIR + projectDirName + "/"); + public static File projectDirectoryFor(String projectDirName) { + return new File(OrchestratorTest.PROJECT_ROOT_DIR + projectDirName + "/"); } @CheckForNull - static Measures.Measure getMeasure(String componentKey, String metricKey) { + protected static Measures.Measure getMeasure(String componentKey, String metricKey) { Measures.ComponentWsResponse response = newWsClient().measures().component(new ComponentRequest() .setComponent(componentKey) .setMetricKeys(singletonList(metricKey))); @@ -111,19 +110,19 @@ static Measures.Measure getMeasure(String componentKey, String metricKey) { } @CheckForNull - static Integer getMeasureAsInt(String componentKey, String metricKey) { + protected static Integer getMeasureAsInt(String componentKey, String metricKey) { Measures.Measure measure = getMeasure(componentKey, metricKey); return (measure == null) ? null : Integer.parseInt(measure.getValue()); } @CheckForNull - static Double getMeasureAsDouble(String componentKey, String metricKey) { + protected static Double getMeasureAsDouble(String componentKey, String metricKey) { Measures.Measure measure = getMeasure(componentKey, metricKey); return (measure == null) ? null : Double.parseDouble(measure.getValue()); } @CheckForNull - static Components.Component getComponent(String projectKey, String componentKey) { + protected static Components.Component getComponent(String projectKey, String componentKey) { List components = newWsClient().components().tree(new TreeRequest() .setComponent(projectKey) .setQ(componentKey)) @@ -134,7 +133,7 @@ static Components.Component getComponent(String projectKey, String componentKey) /** * Extract analysis warnings from component task to evaluate if expected warnings are send to the server */ - static List getAnalysisWarnings(BuildResult result) { + protected static List getAnalysisWarnings(BuildResult result) { String taskId = getTaskId(result); if (taskId == null) { throw new RuntimeException("Task id can not be processed from BuildResult"); @@ -144,7 +143,7 @@ static List getAnalysisWarnings(BuildResult result) { } @CheckForNull - static String getTaskId(BuildResult result) { + private static String getTaskId(BuildResult result) { Matcher m = TASK_ID_PATTERN.matcher(result.getLogs()); if (m.find()) { return m.group(1); @@ -152,27 +151,27 @@ static String getTaskId(BuildResult result) { return null; } - static WsClient newWsClient() { + private static WsClient newWsClient() { return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder() .url(ORCHESTRATOR.getServer().getUrl()) .credentials("admin", "admin") .build()); } - static List issuesForComponent(String componentKey) { + protected static List issuesForComponent(String componentKey) { return newWsClient() .issues() .search(new SearchRequest().setComponentKeys(Collections.singletonList(componentKey))) .getIssuesList(); } - static List issuesForRule(List issues, String ruleKey) { + protected static List issuesForRule(List issues, String ruleKey) { return issues.stream() .filter(i -> i.getRule().equals(ruleKey)) .toList(); } - public static void executeBuildWithExpectedWarnings(Orchestrator orchestrator, SonarScanner build) { + protected static void executeBuildWithExpectedWarnings(Orchestrator orchestrator, SonarScanner build) { BuildResult result = orchestrator.executeBuild(build); assertAnalyzerLogs(result.getLogs()); } @@ -196,47 +195,4 @@ private static void assertAnalyzerLogs(String logs) { .describedAs("There should be no unexpected lines in the analysis logs") .isEmpty(); } - - // TODO SONARPHP-1466 Replace nested classes in it-php-plugin-tests:Tests with a more elegant solution - - @Nested - class NestedCustomRulesTest extends CustomRulesTest { - } - - @Nested - class NestedFrameworkDetectionPHPTest extends FrameworkDetectionPHPTest { - } - - @Nested - class NestedNonPhpProjectTest extends NonPhpProjectTest { - } - - @Nested - class NestedNoSonarTest extends NoSonarTest { - } - - @Nested - class NestedPHPIntegrationTest extends PHPIntegrationTest { - } - - @Nested - class NestedPHPTest extends PHPTest { - } - - @Nested - class NestedPHPUnitTest extends PHPUnitTest { - } - - @Nested - class NestedSonarLintTest extends SonarLintTest { - } - - @Nested - class NestedPhpStanReportTest extends PhpStanReportTest { - } - - @Nested - class NestedPsalmReportTest extends PsalmReportTest { - } - } diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPIntegrationTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPIntegrationTest.java index 61685ba49..06a8cd5b2 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPIntegrationTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPIntegrationTest.java @@ -20,25 +20,18 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import com.sonar.orchestrator.locator.FileLocation; import java.util.HashSet; import java.util.Set; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Measures; -import static com.sonar.it.php.Tests.createScanner; -import static com.sonar.it.php.Tests.getMeasure; -import static com.sonar.it.php.Tests.getMeasureAsDouble; import static org.assertj.core.api.Assertions.assertThat; -class PHPIntegrationTest { +class PHPIntegrationTest extends OrchestratorTest { - @RegisterExtension - public static OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; private static final String PROJECT_KEY = "php-integration"; private static final String PROJECT_NAME = "PHP Integration"; @@ -46,7 +39,7 @@ class PHPIntegrationTest { @BeforeAll static void startServer() { - Tests.provisionProject(PROJECT_KEY, PROJECT_NAME, "php", "it-profile"); + provisionProject(PROJECT_KEY, PROJECT_NAME, "php", "it-profile"); SonarScanner build = createScanner() .setProjectDir(FileLocation.of("../../sources/src/psysh/").getFile()) .setProjectKey(PROJECT_KEY) @@ -56,7 +49,7 @@ static void startServer() { .setProperty("sonar.exclusions", "**/Component/**/*.php, **/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php") .setProperty("sonar.internal.analysis.failFast", "false"); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); } @Test diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPTest.java index abf376950..e8d848db4 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPTest.java @@ -20,18 +20,13 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.util.List; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Issues; -import static com.sonar.it.php.Tests.createScanner; -import static com.sonar.it.php.Tests.getComponent; -import static com.sonar.it.php.Tests.getMeasureAsInt; import static org.assertj.core.api.Assertions.assertThat; -class PHPTest { +class PHPTest extends OrchestratorTest { private static final String MULTI_MODULE_PROJECT_KEY = "multimodule-php"; private static final String EMPTY_FILE_PROJECT_KEY = "empty_file_project_key"; @@ -40,19 +35,16 @@ class PHPTest { private static final String PROJECT_WITH_VENDOR_KEY = "project-with-vendor"; private static final String SRC_DIR_NAME = "src"; - @RegisterExtension - public static OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; - /** * SONARPLUGINS-1657 */ @Test void shouldImportSourcesWithUserDefinedFileSuffixes() { - Tests.provisionProject(SEVERAL_EXTENSIONS_PROJECT_KEY, "Project with several extensions", "php", "it-profile"); + provisionProject(SEVERAL_EXTENSIONS_PROJECT_KEY, "Project with several extensions", "php", "it-profile"); SonarScanner build = createScanner() - .setProjectDir(Tests.projectDirectoryFor("project-with-several-extensions")) + .setProjectDir(projectDirectoryFor("project-with-several-extensions")) .setProperty("sonar.php.file.suffixes", "php,php3,php4,myphp,html"); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); assertThat(getMeasureAsInt(SEVERAL_EXTENSIONS_PROJECT_KEY, "files")).isEqualTo(3); assertThat(getMeasureAsInt(getResourceKey(SEVERAL_EXTENSIONS_PROJECT_KEY, "Math2.myphp"), "lines")).isGreaterThan(1); @@ -61,10 +53,10 @@ void shouldImportSourcesWithUserDefinedFileSuffixes() { @Test void shouldExcludeVendorDir() { - Tests.provisionProject(PROJECT_WITH_VENDOR_KEY, "Project with vendor dir", "php", "it-profile"); + provisionProject(PROJECT_WITH_VENDOR_KEY, "Project with vendor dir", "php", "it-profile"); SonarScanner build = createScanner() - .setProjectDir(Tests.projectDirectoryFor("project-with-vendor")); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + .setProjectDir(projectDirectoryFor("project-with-vendor")); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); assertThat(getMeasureAsInt(PROJECT_WITH_VENDOR_KEY, "files")).isEqualTo(1); } @@ -74,10 +66,10 @@ void shouldExcludeVendorDir() { */ @Test void shouldSupportMultimoduleProjects() { - Tests.provisionProject(MULTI_MODULE_PROJECT_KEY, "Multimodule PHP Project", "php", "it-profile"); + provisionProject(MULTI_MODULE_PROJECT_KEY, "Multimodule PHP Project", "php", "it-profile"); SonarScanner build = createScanner() - .setProjectDir(Tests.projectDirectoryFor("multimodule")); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + .setProjectDir(projectDirectoryFor("multimodule")); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); String componentKey1 = MULTI_MODULE_PROJECT_KEY + ":module1/src"; String componentKey2 = MULTI_MODULE_PROJECT_KEY + ":module2/src"; @@ -92,30 +84,30 @@ void shouldSupportMultimoduleProjects() { */ @Test void shouldNotFailOnEmptyFile() { - Tests.provisionProject(EMPTY_FILE_PROJECT_KEY, "Empty file test project", "php", "it-profile"); + provisionProject(EMPTY_FILE_PROJECT_KEY, "Empty file test project", "php", "it-profile"); SonarScanner build = createScanner() .setProjectKey(EMPTY_FILE_PROJECT_KEY) .setProjectName("Empty file test project") .setSourceEncoding("UTF-8") .setSourceDirs(".") - .setProjectDir(Tests.projectDirectoryFor("empty_file")); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + .setProjectDir(projectDirectoryFor("empty_file")); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); assertThat(getMeasureAsInt(EMPTY_FILE_PROJECT_KEY, "files")).isEqualTo(3); } @Test void shouldNotFailOnDeeplyNestedTrees() { - Tests.provisionProject("big_concat_key", "Big Concat", "php", "sleep-profile"); + provisionProject("big_concat_key", "Big Concat", "php", "sleep-profile"); SonarScanner build = createScanner() .setProjectKey("big_concat_key") .setProjectName("Big Concat") .setSourceEncoding("UTF-8") .setSourceDirs(".") - .setProjectDir(Tests.projectDirectoryFor("big_concat")); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + .setProjectDir(projectDirectoryFor("big_concat")); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); - List issues = Tests.issuesForComponent("big_concat_key"); + List issues = issuesForComponent("big_concat_key"); // The file actually contains two calls to sleep(), but only one is visited due to the depth limit of the visitor. assertThat(issues).hasSize(1); assertThat(issues.get(0).getLine()).isEqualTo(105); @@ -123,17 +115,17 @@ void shouldNotFailOnDeeplyNestedTrees() { @Test void shouldHandleProjectWithOnlyTestFiles() { - Tests.provisionProject(PROJECT_WITH_MAIN_AND_TEST_KEY, "project main and test files", "php", "it-profile"); + provisionProject(PROJECT_WITH_MAIN_AND_TEST_KEY, "project main and test files", "php", "it-profile"); SonarScanner build = createScanner() .setProjectKey(PROJECT_WITH_MAIN_AND_TEST_KEY) .setProjectName("Test project") .setSourceEncoding("UTF-8") .setTestDirs("tests") .setSourceDirs("") - .setProjectDir(Tests.projectDirectoryFor("project-with-main-and-test")); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); + .setProjectDir(projectDirectoryFor("project-with-main-and-test")); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); - List issues = Tests.issuesForComponent(PROJECT_WITH_MAIN_AND_TEST_KEY); + List issues = issuesForComponent(PROJECT_WITH_MAIN_AND_TEST_KEY); assertThat(issues).hasSize(1); } diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPUnitTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPUnitTest.java index 8fd8a3ba0..102bdd0c5 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPUnitTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PHPUnitTest.java @@ -21,25 +21,18 @@ import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.io.File; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import static com.sonar.it.php.Tests.createScanner; -import static com.sonar.it.php.Tests.getAnalysisWarnings; -import static com.sonar.it.php.Tests.getMeasureAsInt; import static org.assertj.core.api.Assertions.assertThat; -class PHPUnitTest { +class PHPUnitTest extends OrchestratorTest { - @RegisterExtension - public static OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; private static final String PROJECT_KEY = "php-unit"; private static final String PROJECT_NAME = "PHP Unit"; - private static final File PROJECT_DIR = Tests.projectDirectoryFor("phpunit"); + private static final File PROJECT_DIR = projectDirectoryFor("phpunit"); private static final String SOURCE_DIR = "src"; private static final String TESTS_DIR = "tests"; @@ -58,7 +51,7 @@ class PHPUnitTest { @BeforeAll static void startServer() { - Tests.provisionProject(PROJECT_KEY, PROJECT_NAME, "php", "it-profile"); + provisionProject(PROJECT_KEY, PROJECT_NAME, "php", "it-profile"); } public void setTestReportPath(String reportPath) { @@ -70,7 +63,7 @@ public void setCoverageReportPaths(String reportPaths) { } public BuildResult executeBuild() { - return orchestrator.executeBuild(BUILD); + return ORCHESTRATOR.executeBuild(BUILD); } @Test diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PhpStanReportTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PhpStanReportTest.java index 9f6eed3e4..33d82b52f 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PhpStanReportTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PhpStanReportTest.java @@ -20,31 +20,25 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.util.List; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Common; import org.sonarqube.ws.Issues; -import static com.sonar.it.php.Tests.createScanner; import static org.assertj.core.api.Assertions.assertThat; -class PhpStanReportTest { +class PhpStanReportTest extends OrchestratorTest { private static final String PROJECT = "phpstan_project"; - @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = Tests.ORCHESTRATOR; - @Test void importReport() { - Tests.provisionProject(PROJECT, PROJECT, "php", "no_rules"); + provisionProject(PROJECT, PROJECT, "php", "no_rules"); SonarScanner build = createScanner() - .setProjectDir(Tests.projectDirectoryFor("phpstan_project")); - Tests.executeBuildWithExpectedWarnings(ORCHESTRATOR, build); + .setProjectDir(projectDirectoryFor("phpstan_project")); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); - List issues = Tests.issuesForComponent("phpstan_project"); + List issues = issuesForComponent("phpstan_project"); assertThat(issues).hasSize(2); Issues.Issue first = issues.get(0); assertThat(first.getComponent()).isEqualTo("phpstan_project:src/test.php"); diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PsalmReportTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PsalmReportTest.java index e89e0ee04..ddf124be9 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PsalmReportTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/PsalmReportTest.java @@ -20,31 +20,25 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.util.List; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Common; import org.sonarqube.ws.Issues; -import static com.sonar.it.php.Tests.createScanner; import static org.assertj.core.api.Assertions.assertThat; -class PsalmReportTest { +class PsalmReportTest extends OrchestratorTest { private static final String PROJECT = "psalm_project"; - @RegisterExtension - public static final OrchestratorExtension ORCHESTRATOR = Tests.ORCHESTRATOR; - @Test void importReport() { - Tests.provisionProject(PROJECT, PROJECT, "php", "no_rules"); + provisionProject(PROJECT, PROJECT, "php", "no_rules"); SonarScanner build = createScanner() - .setProjectDir(Tests.projectDirectoryFor(PROJECT)); - Tests.executeBuildWithExpectedWarnings(ORCHESTRATOR, build); + .setProjectDir(projectDirectoryFor(PROJECT)); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); - List issues = Tests.issuesForComponent(PROJECT); + List issues = issuesForComponent(PROJECT); assertThat(issues).hasSize(2); Issues.Issue first = issues.get(0); assertThat(first.getComponent()).isEqualTo("psalm_project:src/test.php"); diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/SonarLintTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/SonarLintTest.java index 256810421..abcb5e14c 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/SonarLintTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/SonarLintTest.java @@ -41,6 +41,8 @@ import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine; import org.sonarsource.sonarlint.core.commons.Language; +import static com.sonar.it.php.OrchestratorTest.PHP_PLUGIN_LOCATION; +import static com.sonar.it.php.OrchestratorTest.projectDirectoryFor; import static org.assertj.core.api.Assertions.assertThat; class SonarLintTest { @@ -55,7 +57,7 @@ class SonarLintTest { @BeforeAll static void prepare() { StandaloneGlobalConfiguration sonarLintConfig = StandaloneGlobalConfiguration.builder() - .addPlugin(Tests.PHP_PLUGIN_LOCATION.getFile().toPath()) + .addPlugin(PHP_PLUGIN_LOCATION.getFile().toPath()) .addEnabledLanguage(Language.PHP) .setSonarLintUserHome(tempDirectory.toPath()) .setLogOutput((formattedMessage, level) -> { @@ -73,7 +75,7 @@ static void stop() { @Test void shouldRaiseIssues() throws IOException { - Path filePath = Tests.projectDirectoryFor("sonarlint").toPath().resolve("Math.php"); + Path filePath = projectDirectoryFor("sonarlint").toPath().resolve("Math.php"); filePath = Files.copy(filePath, baseDir.resolve("Math.php")); ClientInputFile inputFile = prepareInputFile(filePath, false); diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/SuppressWarningsTest.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/SuppressWarningsTest.java index 946cc7436..95d6944fa 100644 --- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/SuppressWarningsTest.java +++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/SuppressWarningsTest.java @@ -20,29 +20,23 @@ package com.sonar.it.php; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.util.List; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Issues; -import static com.sonar.it.php.Tests.createScanner; import static org.assertj.core.api.Assertions.assertThat; -public class SuppressWarningsTest { - - @RegisterExtension - public static OrchestratorExtension orchestrator = Tests.ORCHESTRATOR; +public class SuppressWarningsTest extends OrchestratorTest { private static final String PROJECT_KEY = "suppress_warnings"; @Test void shouldSuppressIssueWithAnnotation() { - Tests.provisionProject(PROJECT_KEY, "SuppressWarningsTest", "php", "nosonar-profile"); + provisionProject(PROJECT_KEY, "SuppressWarningsTest", "php", "nosonar-profile"); SonarScanner build = createScanner() - .setProjectDir(Tests.projectDirectoryFor(PROJECT_KEY)); - Tests.executeBuildWithExpectedWarnings(orchestrator, build); - List issues = Tests.issuesForComponent(PROJECT_KEY); + .setProjectDir(projectDirectoryFor(PROJECT_KEY)); + executeBuildWithExpectedWarnings(ORCHESTRATOR, build); + List issues = issuesForComponent(PROJECT_KEY); assertThat(issues).isEmpty(); }