test PhpUnitResultJunit
Test data is generated by real test suite, with phpunit 6.2
This commit is contained in:
parent
2bd6ae96cb
commit
c89a6e979c
133
tests/PHPCensor/Plugin/SampleFiles/phpunit_money_junit.xml
Normal file
133
tests/PHPCensor/Plugin/SampleFiles/phpunit_money_junit.xml
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites>
|
||||
<testsuite name="Money Test Suite" tests="18" assertions="10" errors="3" failures="7" skipped="5" time="0.047697">
|
||||
<testsuite name="Tests\Money\MoneyTest" file="/path/to/build/tests/money/tests/MoneyTest.php" tests="3" assertions="4" errors="0" failures="0" skipped="0" time="0.033813">
|
||||
<testcase name="testFactoryMethods" class="Tests\Money\MoneyTest" classname="Tests.Money.MoneyTest" file="/path/to/build/tests/money/tests/MoneyTest.php" line="10" assertions="2" time="0.032037"/>
|
||||
<testcase name="testJsonEncoding" class="Tests\Money\MoneyTest" classname="Tests.Money.MoneyTest" file="/path/to/build/tests/money/tests/MoneyTest.php" line="23" assertions="1" time="0.000073"/>
|
||||
<testcase name="testMaxInit" class="Tests\Money\MoneyTest" classname="Tests.Money.MoneyTest" file="/path/to/build/tests/money/tests/MoneyTest.php" line="31" assertions="1" time="0.001703"/>
|
||||
</testsuite>
|
||||
<testsuite name="ExampleResults\ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" tests="12" assertions="6" errors="1" failures="6" skipped="5" time="0.009710">
|
||||
<testcase name="testFailure" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="12" assertions="0" time="0.000107">
|
||||
<error type="InvalidArgumentException">ExampleResults\ExampleFailuresTest::testFailure
|
||||
InvalidArgumentException: Division by zero
|
||||
|
||||
/path/to/build/src/Money.php:320
|
||||
/path/to/build/tests/ExampleFailuresTest.php:15
|
||||
</error>
|
||||
</testcase>
|
||||
<testcase name="testFailure2" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="18" assertions="1" time="0.002911">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">ExampleResults\ExampleFailuresTest::testFailure2
|
||||
Failed asserting that two objects are equal.
|
||||
--- Expected
|
||||
+++ Actual
|
||||
@@ @@
|
||||
Money\Money Object (
|
||||
- 'amount' => '2'
|
||||
+ 'amount' => '3'
|
||||
'currency' => Money\Currency Object (...)
|
||||
)
|
||||
|
||||
/path/to/build/tests/ExampleFailuresTest.php:20
|
||||
</failure>
|
||||
</testcase>
|
||||
<testcase name="testIncomplete" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="23" assertions="0" time="0.001158">
|
||||
<skipped/>
|
||||
</testcase>
|
||||
<testcase name="testFailure3" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="28" assertions="1" time="0.000169">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">ExampleResults\ExampleFailuresTest::testFailure3
|
||||
Failed asserting that two arrays are equal.
|
||||
--- Expected
|
||||
+++ Actual
|
||||
@@ @@
|
||||
Array (
|
||||
+ 0 => 3
|
||||
+ 1 => 33
|
||||
)
|
||||
|
||||
/path/to/build/tests/ExampleFailuresTest.php:30
|
||||
</failure>
|
||||
</testcase>
|
||||
<testcase name="testFailure4" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="33" assertions="1" time="0.000648">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">ExampleResults\ExampleFailuresTest::testFailure4
|
||||
Failed asserting that false is true.
|
||||
|
||||
/path/to/build/tests/ExampleFailuresTest.php:35
|
||||
</failure>
|
||||
<system-out>some output
|
||||
from f4</system-out>
|
||||
</testcase>
|
||||
<testsuite name="ExampleResults\ExampleFailuresTest::testFailure5" tests="3" assertions="3" errors="0" failures="3" skipped="0" time="0.001377">
|
||||
<testcase name="testFailure5 with data set #0" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="41" assertions="1" time="0.001043">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">ExampleResults\ExampleFailuresTest::testFailure5 with data set #0 (1, 2, 3, 4, 5, 6)
|
||||
Failed asserting that 3 is identical to 1.
|
||||
|
||||
/path/to/build/tests/ExampleFailuresTest.php:43
|
||||
</failure>
|
||||
</testcase>
|
||||
<testcase name="testFailure5 with data set #1" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="41" assertions="1" time="0.000188">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">ExampleResults\ExampleFailuresTest::testFailure5 with data set #1 ('one', 'two', 'three', 'four', 'five', 'six')
|
||||
Failed asserting that two strings are identical.
|
||||
--- Expected
|
||||
+++ Actual
|
||||
@@ @@
|
||||
-'one'
|
||||
+'three'
|
||||
|
||||
/path/to/build/tests/ExampleFailuresTest.php:43
|
||||
</failure>
|
||||
</testcase>
|
||||
<testcase name="testFailure5 with data set #2" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="41" assertions="1" time="0.000146">
|
||||
<failure type="PHPUnit\Framework\ExpectationFailedException">ExampleResults\ExampleFailuresTest::testFailure5 with data set #2 (array(1, 'one'), array(2, 'two'), array(3, 'three'), array(4, 'four'), array(5, 'five'), array(6, 'six'))
|
||||
Failed asserting that Array &0 (
|
||||
0 => 3
|
||||
1 => 'three'
|
||||
) is identical to Array &0 (
|
||||
0 => 1
|
||||
1 => 'one'
|
||||
).
|
||||
|
||||
/path/to/build/tests/ExampleFailuresTest.php:43
|
||||
</failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="ExampleResults\ExampleFailuresTest::testSkipped" tests="3" assertions="0" errors="0" failures="0" skipped="3" time="0.003340">
|
||||
<testcase name="testSkipped with data set #0" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="49" assertions="0" time="0.003184">
|
||||
<skipped/>
|
||||
</testcase>
|
||||
<testcase name="testSkipped with data set #1" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="49" assertions="0" time="0.000100">
|
||||
<skipped/>
|
||||
</testcase>
|
||||
<testcase name="testSkipped with data set #2" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="49" assertions="0" time="0.000056">
|
||||
<skipped/>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testcase name="testDepends1" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/path/to/build/tests/ExampleFailuresTest.php" line="57" assertions="0" time="0.000000">
|
||||
<skipped/>
|
||||
</testcase>
|
||||
<testcase name="testOutput" class="ExampleResults\ExampleFailuresTest" classname="ExampleResults.ExampleFailuresTest" file="/home/simon/var_src/php-censor.local/TMP/testResultGeneration-php-censor/ExampleResults/ExampleFailuresTest.php" line="60" assertions="1" time="0.000048">
|
||||
<system-out>has output
|
||||
on lines</system-out>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="ExampleResults\EmptyWillWarnTest" file="/path/to/build/tests/EmptyWillWarnTest.php" tests="1" assertions="0" errors="0" failures="1" skipped="0" time="0.003860">
|
||||
<testcase name="Warning" assertions="0" time="0.003860">
|
||||
<warning type="PHPUnit\Framework\Warning">Warning
|
||||
No tests found in class "ExampleResults\EmptyWillWarnTest".
|
||||
|
||||
</warning>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="Tests\IntlMoneyParserTest" file="/path/to/build/tests/IntlMoneyParserTest.php" tests="2" assertions="0" errors="2" failures="0" skipped="0" time="0.000314">
|
||||
<testsuite name="Tests\IntlMoneyParserTest::testIntlParser" tests="2" assertions="0" errors="2" failures="0" skipped="0" time="0.000314">
|
||||
<testcase name="testIntlParser with data set #0" class="Tests\IntlMoneyParserTest" classname="Tests.IntlMoneyParserTest" file="/path/to/build/tests/IntlMoneyParserTest.php" line="14" assertions="0" time="0.000066">
|
||||
<error type="PHPUnit\Framework\RiskyTestError">Risky Test
|
||||
</error>
|
||||
</testcase>
|
||||
<testcase name="testIntlParser with data set #1" class="Tests\IntlMoneyParserTest" classname="Tests.IntlMoneyParserTest" file="/path/to/build/tests/IntlMoneyParserTest.php" line="14" assertions="0" time="0.000248">
|
||||
<error type="PHPUnit\Framework\RiskyTestError">Risky Test
|
||||
</error>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuite>
|
||||
</testsuite>
|
||||
</testsuites>
|
|
@ -4,6 +4,7 @@ namespace Tests\PHPCensor\Plugin\Util;
|
|||
|
||||
use PHPCensor\Plugin\Util\PhpUnitResult;
|
||||
use PHPCensor\Plugin\Util\PhpUnitResultJson;
|
||||
use PHPCensor\Plugin\Util\PhpUnitResultJunit;
|
||||
|
||||
/**
|
||||
* Class PhpUnitResultTest parses the results for the PhpUnitV2 plugin
|
||||
|
@ -13,11 +14,20 @@ use PHPCensor\Plugin\Util\PhpUnitResultJson;
|
|||
*/
|
||||
class PhpUnitResultTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Skipped test results
|
||||
*
|
||||
* @var array[]
|
||||
*/
|
||||
static $skipped = [];
|
||||
|
||||
public function testInitParse()
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testInitParse($resultClass, $testFile)
|
||||
{
|
||||
$buildPath = '/path/to/build';
|
||||
$parser = new PhpUnitResultJson(ROOT_DIR . 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money.txt', $buildPath);
|
||||
$parser = new $resultClass(ROOT_DIR . $testFile, $buildPath);
|
||||
$output = $parser->parse()->getResults();
|
||||
$errors = $parser->getErrors();
|
||||
|
||||
|
@ -35,9 +45,47 @@ class PhpUnitResultTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals("has output\non lines", $output[15]['output']);
|
||||
|
||||
$this->assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[5]['severity']);
|
||||
try {
|
||||
$this->assertContains('Incomplete Test:', $output[5]['message']);
|
||||
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
self::$skipped[] = ['cls' => $resultClass, 'ex' => $e];
|
||||
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
|
||||
self::$skipped[] = ['cls' => $resultClass, 'ex' => $e];
|
||||
}
|
||||
|
||||
$this->assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[11]['severity']);
|
||||
try {
|
||||
$this->assertContains('Skipped Test:', $output[11]['message']);
|
||||
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
self::$skipped[] = ['cls' => $resultClass, 'ex' => $e];
|
||||
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
|
||||
self::$skipped[] = ['cls' => $resultClass, 'ex' => $e];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* used as long as junit format does not provide message for skipped tests
|
||||
*/
|
||||
public function testSkippedAnything()
|
||||
{
|
||||
if (self::$skipped) {
|
||||
$msg = "Skipped result tests:\n";
|
||||
foreach (self::$skipped as $skip) {
|
||||
$exMsg = strstr((string)$skip['ex'], "\n", true);
|
||||
if (false === $exMsg) {
|
||||
$exMsg = (string)$skip['ex'];
|
||||
}
|
||||
$msg .= sprintf(" * %s: %s \n", $skip['cls'], $exMsg);
|
||||
}
|
||||
$this->markTestSkipped($msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getTestData()
|
||||
{
|
||||
return [
|
||||
'json' => [PhpUnitResultJson::class, 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money.txt'],
|
||||
'junit' => [PhpUnitResultJunit::class, 'tests/PHPCensor/Plugin/SampleFiles/phpunit_money_junit.xml'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue