diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 71c65700..c339f9fe 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1379,6 +1379,10 @@ PASS Tests\Visual\Help ✓ visual snapshot of help command output + PASS Tests\Visual\JUnit + ✓ junit output + ✓ junit with parallel + PASS Tests\Visual\Parallel ✓ parallel ✓ a parallel test can extend another test with same name @@ -1404,4 +1408,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 999 passed (2359 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 1001 passed (2387 assertions) \ No newline at end of file diff --git a/tests/Visual/JUnit.php b/tests/Visual/JUnit.php new file mode 100644 index 00000000..59562b1d --- /dev/null +++ b/tests/Visual/JUnit.php @@ -0,0 +1,79 @@ + 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ); + + $process->run(); + + $rawXmlContent = file_get_contents($junitLogFile); + unlink($junitLogFile); + + // convert xml to array + try { + $xml = new SimpleXMLElement(preg_replace("/(<\/?)(\w+):([^>]*>)/", '$1$2$3', $rawXmlContent)); + + return json_decode(json_encode((array) $xml), true); + } catch (Exception $exception) { + throw new XmlParseException($exception->getMessage(), $exception->getCode(), $exception->getPrevious()); + } +}; + +$normalizedPath = function (string $path) { + return str_replace('/', DIRECTORY_SEPARATOR, $path); +}; + +test('junit output', function () use ($normalizedPath, $run) { + $result = $run('tests/.tests/SuccessOnly.php'); + + expect($result['testsuite']['@attributes']) + ->name->toBe('Tests\tests\SuccessOnly') + ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php')) + ->tests->toBe('2') + ->assertions->toBe('2') + ->errors->toBe('0') + ->failures->toBe('0') + ->skipped->toBe('0'); + + expect($result['testsuite']['testcase']) + ->toHaveCount(2); + + expect($result['testsuite']['testcase'][0]['@attributes']) + ->name->toBe('it can pass with comparison') + ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison')) + ->class->toBe('Tests\tests\SuccessOnly') + ->classname->toBe('Tests.tests.SuccessOnly') + ->assertions->toBe('1') + ->time->toStartWith('0.0'); +}); + +test('junit with parallel', function () use ($normalizedPath, $run) { + $result = $run('tests/.tests/SuccessOnly.php', '--parallel', '--processes=1', '--filter', 'can pass with comparison'); + + expect($result['testsuite']['@attributes']) + ->name->toBe('Tests\tests\SuccessOnly') + ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php')) + ->tests->toBe('1') + ->assertions->toBe('1') + ->errors->toBe('0') + ->failures->toBe('0') + ->skipped->toBe('0'); + + expect($result['testsuite']['testcase']) + ->toHaveCount(1); + + expect($result['testsuite']['testcase']['@attributes']) + ->name->toBe('it can pass with comparison') + ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison')) + ->class->toBe('Tests\tests\SuccessOnly') + ->classname->toBe('Tests.tests.SuccessOnly') + ->assertions->toBe('1') + ->time->toStartWith('0.0'); +});