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

PHP: Fixed incorrect display of skipped tests in the Test Results window for PHPUnit. #7836

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public final class PhpUnitLogParser extends DefaultHandler {

enum Content { NONE, ERROR, FAILURE };
enum Content { NONE, ERROR, FAILURE, SKIPPED };
private static final Logger LOGGER = Logger.getLogger(PhpUnitLogParser.class.getName());
private static final String NO_FILE = "NO_FILE"; // NOI18N

Expand Down Expand Up @@ -90,6 +90,8 @@ public void startElement(String uri, String localName, String qName, Attributes
startTestFailure(attributes);
} else if ("error".equals(qName)) { // NOI18N
startTestError(attributes);
} else if ("skipped".equals(qName)) { // NOI18N
startTestSkipped(attributes);
}
}

Expand All @@ -111,6 +113,7 @@ public void characters(char[] ch, int start, int length) throws SAXException {
switch (content) {
case FAILURE:
case ERROR:
case SKIPPED:
buffer.append(new String(ch, start, length));
break;
case NONE:
Expand Down Expand Up @@ -169,6 +172,11 @@ private void startTestFailure(Attributes attributes) {
content = Content.FAILURE;
}

private void startTestSkipped(Attributes attributes) {
content = Content.SKIPPED;
testCase.setSkippedStatus();
}

private void endTestContent() {
assert testCase != null;
assert buffer.length() > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public void setFailureStatus() {
status = TestCase.Status.FAILED;
}

public void setSkippedStatus() {
assert status == TestCase.Status.PASSED : "Expected PASSED status but was: " + status; // NOI18N
status = TestCase.Status.SKIPPED;
}

public TestCase.Status getStatus() {
return status;
}
Expand All @@ -167,6 +172,10 @@ public boolean isFailure() {
return status.equals(TestCase.Status.FAILED);
}

public boolean isSkipped() {
return status.equals(TestCase.Status.SKIPPED);
}

@Override
public String toString() {
return String.format("TestCaseVo{name: %s, file: %s, line: %d, time: %d, status: %s, stacktrace: %s}", name, file, line, time, status, stacktrace); // NOI18N
Expand Down
40 changes: 40 additions & 0 deletions php/php.phpunit/test/unit/data/phpunit-log-skipped-tests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="CLI Arguments" tests="17" assertions="14" errors="0" failures="2" skipped="3" time="0.035194">
<testsuite name="CalculatorTest" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" tests="17" assertions="14" errors="0" failures="2" skipped="3" time="0.035194">
<testcase name="testPlus" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="47" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.007517"/>
<testcase name="testPlus2" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="54" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.012255">
<failure type="PHPUnit\Framework\ExpectationFailedException">CalculatorTest::testPlus2
Failed asserting that 1 matches expected 2.

/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php:55</failure>
</testcase>
<testcase name="testPlus3" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="64" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.001137"/>
<testcase name="testPlus4" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="71" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.000984"/>
<testcase name="testMinus" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="78" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.001094"/>
<testcase name="testMinus2" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="85" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.000989"/>
<testcase name="testMinus3" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="92" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.000950"/>
<testcase name="testMinus4" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="99" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.000978"/>
<testcase name="testMultiply" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="106" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.000964"/>
<testcase name="testMultiply2" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="113" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.000983"/>
<testcase name="testMultiply3" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="120" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.000961"/>
<testcase name="testMultiply4" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="127" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.001048"/>
<testcase name="testMultiply5" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="134" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.001190"/>
<testcase name="testDivide" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="141" class="CalculatorTest" classname="CalculatorTest" assertions="1" time="0.001630">
<failure type="PHPUnit\Framework\ExpectationFailedException">CalculatorTest::testDivide
Failed asserting that 0 matches expected 2.

/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php:142</failure>
</testcase>
<testcase name="testDivide2" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="149" class="CalculatorTest" classname="CalculatorTest" assertions="0" time="0.000000">
<skipped/>
</testcase>
<testcase name="testDivide3" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="160" class="CalculatorTest" classname="CalculatorTest" assertions="0" time="0.001233">
<skipped/>
</testcase>
<testcase name="testModulo" file="/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php" line="170" class="CalculatorTest" classname="CalculatorTest" assertions="0" time="0.001281">
<skipped/>
</testcase>
</testsuite>
</testsuite>
</testsuites>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.Arrays;
import org.netbeans.junit.NbTestCase;
import org.netbeans.modules.php.spi.testing.run.TestCase;

Expand Down Expand Up @@ -295,6 +296,22 @@ public void testParseLogNETBEANS1851() throws Exception {
assertEquals("Risky Test", testCase.getStackTrace()[0]);
}

public void testParseLogSkippedTests() throws Exception {
Reader reader = createReader("phpunit-log-skipped-tests.xml");
TestSessionVo testSession = new TestSessionVo(null);

PhpUnitLogParser.parse(reader, testSession);

assertSame(1, testSession.getTestSuites().size());
TestSuiteVo testSuite = testSession.getTestSuites().get(0);
assertEquals("CalculatorTest", testSuite.getName());
assertEquals("/home/troizet/NetBeansProjects/Calculator-PHPUnit/test/src/CalculatorTest.php", testSuite.getFile());
TestCaseVo testCase = testSuite.getTestCases().get(15);
assertEquals("testDivide3", testCase.getName());
assertTrue(testCase.isSkipped());
assertTrue(Arrays.asList(testCase.getStackTrace()).isEmpty());
}

private Reader createReader(String filename) throws FileNotFoundException {
return new BufferedReader(new FileReader(new File(getDataDir(), filename)));
}
Expand Down
Loading