-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8871459
commit 5825293
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
use Symfony\Component\Process\Process; | ||
|
||
$run = function () { | ||
$junitLogFile = tempnam(sys_get_temp_dir(), 'junit'); | ||
|
||
$process = new Process( | ||
array_merge(['php', 'bin/pest', '--log-junit', $junitLogFile], func_get_args()), | ||
dirname(__DIR__, 2), | ||
['COLLISION_PRINTER' => '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()); | ||
} | ||
}; | ||
|
||
test('junit output', function () use ($run) { | ||
$result = $run('tests/.tests/SuccessOnly.php'); | ||
|
||
expect($result['testsuite']['@attributes']) | ||
->name->toBe('Tests\tests\SuccessOnly') | ||
->file->toBe('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('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 ($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('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('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'); | ||
}); |