Skip to content

Commit

Permalink
Merge pull request apache#2203 from KacerCZ/netbeans-4478-fix-php-cod…
Browse files Browse the repository at this point in the history
…e-analysis-tests

[NETBEANS-4478] Fixed tests for PHP Code analysis on Windows
  • Loading branch information
tmysik authored Jun 29, 2020
2 parents f8ad6ea + b618c33 commit a50d78a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
ant -f php/php.api.testing test
ant -f php/php.apigen test
ant -f php/php.atoum test
# ant -f php/php.code.analysis test
ant -f php/php.code.analysis test
ant -f php/php.codeception test
ant -f php/php.composer test
ant -f php/php.dbgp test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
-->
<checkstyle>
<file name="/home/junichi11/NetBeansProjects/PHPStan/app/Test1.php">
<file name="%WORKDIR%/Test1.php">
<error line="13" column="1" severity="error" message="Binary operation &quot;+&quot; between string and 2 results in an error." />
</file>
<file name="/home/junichi11/NetBeansProjects/PHPStan/app/Test2.php">
<file name="%WORKDIR%/Test2.php">
<error line="9" column="1" severity="error" message="Anonymous function should return string but returns void." />
<error line="9" column="1" severity="error" message="Result of closure (void) is used." />
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
package org.netbeans.modules.php.analysis.parsers;

import java.io.File;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
Expand Down Expand Up @@ -47,7 +51,6 @@ public void testParse() throws Exception {
assertEquals("error: Parameter $date of method HelloWorld::sayHello() has invalid typehint type DateTimeImutable.", result.getCategory());
assertEquals("Parameter $date of method HelloWorld::sayHello() has invalid typehint type DateTimeImutable.", result.getDescription());


result = results.get(2);
assertEquals(FileUtil.toFile(root.getFileObject("vendor/nette/php-generator/src/PhpGenerator/Traits/CommentAware.php")).getAbsolutePath(), result.getFilePath());
assertEquals(28, result.getLine());
Expand Down Expand Up @@ -88,7 +91,9 @@ public void testParseNetBeans3022Win() throws Exception {
public void testParseNetBeans3022WithoutWorkDir() throws Exception {
FileObject root = getDataDir("phpstan/PHPStanSupport/netbeans3022");
FileObject workDir = null;
List<Result> results = PHPStanReportParser.parse(getLogFile("phpstan-log-netbeans-3022-without-workdir.xml"), root, workDir);
File logFile = getLogFile("phpstan-log-netbeans-3022-without-workdir.xml");
fixContent(logFile);
List<Result> results = PHPStanReportParser.parse(logFile, root, workDir);
assertNotNull(results);
assertEquals(3, results.size());
}
Expand All @@ -107,4 +112,12 @@ private FileObject getDataDir(String name) {
return dataDir.getFileObject(name);
}

private void fixContent(File file) throws Exception {
Path path = file.toPath();
Charset charset = StandardCharsets.UTF_8;
String content = new String(Files.readAllBytes(path), charset);
content = content.replace("%WORKDIR%", getDataDir().getAbsolutePath());
Files.write(path, content.getBytes(charset));
}

}

0 comments on commit a50d78a

Please sign in to comment.