Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARPHP-1466 Replace nested classes in it-php-plugin-tests:Tests with a more elegant solution #1312

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .cirrus/modules/qa.star
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
}

Expand All @@ -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"
GabinL21 marked this conversation as resolved.
Show resolved Hide resolved
]


Expand Down
4 changes: 0 additions & 4 deletions its/plugin/tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Issue> 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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -47,15 +41,15 @@ void shouldDetectIssueWhenFrameworkDetectionEnabled() {
}

List<Issues.Issue> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,40 @@
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)
.setProjectName(PROJECT_NAME)
.setSourceEncoding("UTF-8")
.setSourceDirs(".");

Tests.executeBuildWithExpectedWarnings(orchestrator, build);
executeBuildWithExpectedWarnings(ORCHESTRATOR, build);
}

@Test
void test() {
List<Issue> issues = Tests.issuesForComponent(PROJECT_KEY);
List<Issue> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
}

Expand Down
Loading