2017-01-05 11:59:58 +01:00
|
|
|
<?php
|
2017-01-05 14:01:53 +01:00
|
|
|
|
|
|
|
namespace Tests\PHPCensor\Plugin\Util;
|
2017-01-05 11:59:58 +01:00
|
|
|
|
2017-01-05 14:01:53 +01:00
|
|
|
use PHPCensor\Plugin\Util\PhpUnitResult;
|
2017-07-15 02:18:07 +02:00
|
|
|
use PHPCensor\Plugin\Util\PhpUnitResultJson;
|
2017-07-17 21:26:59 +02:00
|
|
|
use PHPCensor\Plugin\Util\PhpUnitResultJunit;
|
2017-01-05 11:59:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PhpUnitResultTest parses the results for the PhpUnitV2 plugin
|
2017-10-21 10:51:05 +02:00
|
|
|
*
|
|
|
|
* @author Pablo Tejada <pablo@ptejada.com>
|
2017-01-05 11:59:58 +01:00
|
|
|
*/
|
2017-07-24 08:45:52 +02:00
|
|
|
class PhpUnitResultTest extends \PHPUnit\Framework\TestCase
|
2017-01-05 11:59:58 +01:00
|
|
|
{
|
2017-07-17 21:26:59 +02:00
|
|
|
/**
|
|
|
|
* Skipped test results
|
|
|
|
*
|
|
|
|
* @var array[]
|
|
|
|
*/
|
|
|
|
static $skipped = [];
|
2017-01-05 11:59:58 +01:00
|
|
|
|
2017-07-17 21:26:59 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider getTestData
|
|
|
|
*/
|
|
|
|
public function testInitParse($resultClass, $testFile)
|
2017-01-05 11:59:58 +01:00
|
|
|
{
|
|
|
|
$buildPath = '/path/to/build';
|
2017-07-17 21:26:59 +02:00
|
|
|
$parser = new $resultClass(ROOT_DIR . $testFile, $buildPath);
|
2017-01-05 11:59:58 +01:00
|
|
|
$output = $parser->parse()->getResults();
|
|
|
|
$errors = $parser->getErrors();
|
|
|
|
|
2018-02-16 10:41:56 +01:00
|
|
|
self::assertEquals(7, $parser->getFailures());
|
|
|
|
self::assertInternalType('array', $output);
|
|
|
|
self::assertInternalType('array', $errors);
|
|
|
|
self::assertNotEmpty($output);
|
|
|
|
self::assertNotEmpty($errors);
|
2017-01-05 11:59:58 +01:00
|
|
|
|
|
|
|
// The trace elements should not include the build path
|
2018-02-16 10:41:56 +01:00
|
|
|
self::assertStringStartsNotWith($buildPath, $output[3]['trace'][0]);
|
|
|
|
self::assertStringStartsNotWith($buildPath, $output[3]['trace'][1]);
|
2017-01-05 11:59:58 +01:00
|
|
|
|
2018-02-16 10:41:56 +01:00
|
|
|
self::assertEquals("some output\nfrom f4", $output[7]['output']);
|
|
|
|
self::assertEquals("has output\non lines", $output[15]['output']);
|
2017-07-18 01:13:47 +02:00
|
|
|
|
2018-02-16 10:41:56 +01:00
|
|
|
self::assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[5]['severity']);
|
2017-07-17 21:26:59 +02:00
|
|
|
try {
|
2018-02-16 10:41:56 +01:00
|
|
|
self::assertContains('Incomplete Test:', $output[5]['message']);
|
2017-07-17 21:26:59 +02:00
|
|
|
} catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
|
|
|
self::$skipped[] = ['cls' => $resultClass, 'ex' => $e];
|
|
|
|
}
|
2017-01-05 11:59:58 +01:00
|
|
|
|
2018-02-16 10:41:56 +01:00
|
|
|
self::assertEquals(PhpUnitResult::SEVERITY_SKIPPED, $output[11]['severity']);
|
2017-07-17 21:26:59 +02:00
|
|
|
try {
|
2018-02-16 10:41:56 +01:00
|
|
|
self::assertContains('Skipped Test:', $output[11]['message']);
|
2017-07-17 21:26:59 +02:00
|
|
|
} 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 [
|
2018-03-04 12:04:15 +01:00
|
|
|
'json' => [PhpUnitResultJson::class, 'tests/data/Plugin/PhpUnit/phpunit_money.txt'],
|
|
|
|
'junit' => [PhpUnitResultJunit::class, 'tests/data/Plugin/PhpUnit/phpunit_money_junit.xml'],
|
2017-07-17 21:26:59 +02:00
|
|
|
];
|
2017-01-05 11:59:58 +01:00
|
|
|
}
|
|
|
|
}
|