From b5396f2974733593a69a6c6022bd36ce796fef94 Mon Sep 17 00:00:00 2001 From: Rudy Regazzoni <110470341+rudy-regazzoni-sonarsource@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:08:40 +0100 Subject: [PATCH] SONARPHP-1559 Fix framework detection tests --- its/plugin/projects/drupal_project/test.php | 2 +- .../it/php/FrameworkDetectionPHPTest.java | 31 +++++++++---------- .../java/com/sonar/it/php/Tests.java | 5 +++ .../com/sonar/it/php/drupal_profile.xml | 11 +++++++ 4 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 its/plugin/tests/src/integrationTest/resources/com/sonar/it/php/drupal_profile.xml diff --git a/its/plugin/projects/drupal_project/test.php b/its/plugin/projects/drupal_project/test.php index cc86970162..a0eacc5af7 100644 --- a/its/plugin/projects/drupal_project/test.php +++ b/its/plugin/projects/drupal_project/test.php @@ -1,4 +1,4 @@ issues = Tests.issuesForComponent(DRUPAL_PROJECT_KEY); + var issues = scanDrupalProject("Drupal project 1", "drupal-project-1", false); assertThat(issues).isEmpty(); } @Test - void shouldDetectIssueWhenFrameworkDetectionDisabled() { - Tests.provisionProject(DRUPAL_PROJECT_KEY, "Project with several extensions", "php", "it-profile"); + void shouldDetectIssueWhenFrameworkDetectionEnabled() { + var issues = scanDrupalProject("Drupal project 2", "drupal-project-2", true); + assertThat(issues).hasSize(1); + } + + List scanDrupalProject(String name, String key, boolean frameworkDetectionEnabled) { + Tests.provisionProject(key, name, "php", "drupal-profile"); SonarScanner build = createScanner() .setProjectDir(Tests.projectDirectoryFor("drupal_project")) - .setProperty("sonar.php.frameworkDetection", "false"); + .setProjectKey(key) + .setProjectName(name) + .setSourceEncoding("UTF-8") + .setSourceDirs(".") + .setProperty("sonar.php.frameworkDetection", "" + frameworkDetectionEnabled); Tests.executeBuildWithExpectedWarnings(orchestrator, build); - - List issues = Tests.issuesForComponent(DRUPAL_PROJECT_KEY); - assertThat(issues).hasSize(1); + return Tests.issuesForComponent(key); } } 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/Tests.java index 7ad635fd59..a89e21ce88 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/Tests.java @@ -72,6 +72,7 @@ class Tests { // PHP Plugin .addPlugin(PHP_PLUGIN_LOCATION) .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "profile.xml")) + .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "drupal_profile.xml")) .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "no_rules.xml")) // Custom rules plugin // TODO Fix in SONARPHP-1520 Migrate Custom Rules module to Gradle @@ -206,6 +207,10 @@ private static void assertAnalyzerLogs(String logs) { class NestedCustomRulesTest extends CustomRulesTest { } + @Nested + class NestedFrameworkDetectionPHPTest extends FrameworkDetectionPHPTest { + } + @Nested class NestedNonPhpProjectTest extends NonPhpProjectTest { } diff --git a/its/plugin/tests/src/integrationTest/resources/com/sonar/it/php/drupal_profile.xml b/its/plugin/tests/src/integrationTest/resources/com/sonar/it/php/drupal_profile.xml new file mode 100644 index 0000000000..d954cc35b9 --- /dev/null +++ b/its/plugin/tests/src/integrationTest/resources/com/sonar/it/php/drupal_profile.xml @@ -0,0 +1,11 @@ + + + drupal-profile + php + + + php + S1781 + + +