Skip to content

Commit

Permalink
[SONARPHP-1024] Do not save metrics for test files.
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-ouerghemmi-sonarsource committed Aug 13, 2020
1 parent 91ffbba commit 6d39f27
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ void scanFile(InputFile inputFile) {
if (!inSonarLint(context)) {
phpAnalyzer.getSyntaxHighlighting(context, inputFile).save();
phpAnalyzer.getSymbolHighlighting(context, inputFile).save();
saveNewFileMeasures(context,
phpAnalyzer.computeMeasures(fileLinesContextFactory.createFor(inputFile)),
inputFile);
if (inputFile.type() == Type.MAIN) {
saveNewFileMeasures(context,
phpAnalyzer.computeMeasures(fileLinesContextFactory.createFor(inputFile)),
inputFile);
saveCpdData(phpAnalyzer.computeCpdTokens(), inputFile, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class PHPSensorTest {

private static final String PARSE_ERROR_FILE = "parseError.php";
private static final String ANALYZED_FILE = "PHPSquidSensor.php";
private static final String TEST_FILE = "Test.php";

private Set<File> tempReportFiles = new HashSet<>();

Expand Down Expand Up @@ -449,6 +450,26 @@ public void should_disable_unnecessary_features_for_sonarlint() throws Exception
assertThat(context.referencesForSymbolAt(mainFileKey, 6, 7)).isNotNull();
}

@Test
public void no_measures_for_test_files() {
checkFactory = new CheckFactory(new ActiveRulesBuilder()
.addRule(newActiveRule("S2187"))
.build());

InputFile testFile = inputFile(TEST_FILE, Type.TEST);

String testFileKey = testFile.key();

context.fileSystem().add(testFile);
context.setRuntime(NOT_SONARLINT_RUNTIME);

createSensor().execute(context);

assertThat(context.allIssues()).isNotEmpty();
assertThat(context.measure(testFileKey, CoreMetrics.NCLOC)).isNull();

}

@Test
public void should_use_multi_path_coverage() throws Exception {
context.setRuntime(SONARQUBE_6_7);
Expand Down
5 changes: 5 additions & 0 deletions sonar-php-plugin/src/test/resources/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use PHPUnit\Framework\TestCase;

class MyTest extends TestCase {}

0 comments on commit 6d39f27

Please sign in to comment.