diff --git a/Makefile b/Makefile index ca2fdefa..3efcffd5 100644 --- a/Makefile +++ b/Makefile @@ -72,19 +72,21 @@ clean: .PHONY: regenerate-fixture-results regenerate-fixture-results: vendor $(DOCKER_PHP_EXEC) vendor/bin/phpunit \ - --log-junit test/fixtures/special_chars/data-provider-with-special-chars.xml \ + --log-junit test/fixtures/special_chars/junit-data-provider-with-special-chars.xml \ + --log-otr test/fixtures/special_chars/otr-data-provider-with-special-chars.xml \ --no-configuration \ test/fixtures/special_chars/UnitTestWithDataProviderSpecialCharsTest.php \ > /dev/null || true - $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/ErrorTest.php --log-junit test/fixtures/common_results/junit/ErrorTest.xml > /dev/null || true - $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/FailureTest.php --log-junit test/fixtures/common_results/junit/FailureTest.xml > /dev/null || true - $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/IncompleteTest.php --log-junit test/fixtures/common_results/junit/IncompleteTest.xml > /dev/null || true - $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/RiskyTest.php --log-junit test/fixtures/common_results/junit/RiskyTest.xml > /dev/null || true - $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/SkippedTest.php --log-junit test/fixtures/common_results/junit/SkippedTest.xml > /dev/null || true - $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/SuccessTest.php --log-junit test/fixtures/common_results/junit/SuccessTest.xml > /dev/null || true - $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/WarningTest.php --log-junit test/fixtures/common_results/junit/WarningTest.xml > /dev/null || true - $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/ --log-junit test/fixtures/common_results/combined.xml > /dev/null || true + $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/ErrorTest.php --log-junit test/fixtures/common_results/junit/ErrorTest.xml --log-otr test/fixtures/common_results/otr/ErrorTest.xml > /dev/null || true + $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/FailureTest.php --log-junit test/fixtures/common_results/junit/FailureTest.xml --log-otr test/fixtures/common_results/otr/FailureTest.xml > /dev/null || true + $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/IncompleteTest.php --log-junit test/fixtures/common_results/junit/IncompleteTest.xml --log-otr test/fixtures/common_results/otr/IncompleteTest.xml > /dev/null || true + $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/RiskyTest.php --log-junit test/fixtures/common_results/junit/RiskyTest.xml --log-otr test/fixtures/common_results/otr/RiskyTest.xml > /dev/null || true + $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/SkippedTest.php --log-junit test/fixtures/common_results/junit/SkippedTest.xml --log-otr test/fixtures/common_results/otr/SkippedTest.xml > /dev/null || true + $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/SuccessTest.php --log-junit test/fixtures/common_results/junit/SuccessTest.xml --log-otr test/fixtures/common_results/otr/SuccessTest.xml > /dev/null || true + $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/WarningTest.php --log-junit test/fixtures/common_results/junit/WarningTest.xml --log-otr test/fixtures/common_results/otr/WarningTest.xml > /dev/null || true + $(DOCKER_PHP_EXEC) vendor/bin/phpunit --no-configuration test/fixtures/common_results/ --log-junit test/fixtures/common_results/junit-combined.xml --log-otr test/fixtures/common_results/otr-combined.xml > /dev/null || true find test/fixtures/ -type f -name "*.xml" -print0 | xargs -0 sed -i 's#$(PWD)#.#g' find test/fixtures/ -type f -name "*.xml" -print0 | xargs -0 sed -i 's#time="........"#time="1.234567"#g' - sed -i 's#name="./test/fixtures/common_results"#name=""#g' test/fixtures/common_results/combined.xml - sed -i 's#name="CLI Arguments"#name=""#g' test/fixtures/common_results/combined.xml + find test/fixtures/ -type f -name "*.xml" -print0 | xargs -0 sed -i 's#time="..........................."#time="2026-02-01T12:13:14.567890Z"#g' + sed -i 's#name="./test/fixtures/common_results"#name=""#g' test/fixtures/common_results/junit-combined.xml test/fixtures/common_results/otr-combined.xml + sed -i 's#name="CLI Arguments"#name=""#g' test/fixtures/common_results/junit-combined.xml test/fixtures/common_results/otr-combined.xml diff --git a/src/Otr/Event.php b/src/Otr/Event.php new file mode 100644 index 00000000..6622f196 --- /dev/null +++ b/src/Otr/Event.php @@ -0,0 +1,8 @@ +isFile() && 0 < (int) $logFile->getSize()); + + $logFileContents = file_get_contents($logFile->getPathname()); + assert($logFileContents !== false); +$xml = new SimpleXMLElement($logFileContents); +var_dump($xml->children('e', true)); +foreach ($xml->children('e', true) as $event) { + var_dump($event);exit(); +} +var_dump('end');exit; +print_r($xml);exit; + return self::parseTestSuite( + new SimpleXMLElement($logFileContents), + true, + ); + } +} \ No newline at end of file diff --git a/src/Otr/LogMerger.php b/src/Otr/LogMerger.php new file mode 100644 index 00000000..88fbb51b --- /dev/null +++ b/src/Otr/LogMerger.php @@ -0,0 +1,68 @@ + $otrFiles */ + public function merge(array $otrFiles) + { + $mainSuite = null; + foreach ($otrFiles as $otrFile) { + if (! $otrFile->isFile()) { + continue; + } + + $otherSuite = Events::fromFile($otrFile); + if ($mainSuite === null) { + $mainSuite = $otherSuite; + continue; + } + + if ($mainSuite->name !== $otherSuite->name) { + if ($mainSuite->name !== '') { + $mainSuite = new TestSuite( + '', + $mainSuite->tests, + $mainSuite->assertions, + $mainSuite->failures, + $mainSuite->errors, + $mainSuite->skipped, + $mainSuite->time, + '', + [$mainSuite->name => $mainSuite], + [], + ); + } + + if ($otherSuite->name !== '') { + $otherSuite = new TestSuite( + '', + $otherSuite->tests, + $otherSuite->assertions, + $otherSuite->failures, + $otherSuite->errors, + $otherSuite->skipped, + $otherSuite->time, + '', + [$otherSuite->name => $otherSuite], + [], + ); + } + } + + $mainSuite = $mainSuite->mergeWith($otherSuite); + } + + return $mainSuite; + } +} diff --git a/test/Unit/JUnitTest.php b/test/Unit/JUnitTest.php index 2bfcb43b..a48cd7da 100644 --- a/test/Unit/JUnitTest.php +++ b/test/Unit/JUnitTest.php @@ -53,14 +53,14 @@ public function testMergeJunitLogs(): void $xml = str_replace('time="8.641969"', 'time="1.234567"', $xml); file_put_contents($outputFile, $xml); - self::assertXmlFileEqualsXmlFile(FIXTURES . '/common_results/combined.xml', $outputFile); + self::assertXmlFileEqualsXmlFile(FIXTURES . '/common_results/junit-combined.xml', $outputFile); } public function testHandleSpecialChars(): void { $tmpDir = (new TmpDirCreator())->create(); - $junitLog = FIXTURES . '/special_chars/data-provider-with-special-chars.xml'; + $junitLog = FIXTURES . '/special_chars/junit-data-provider-with-special-chars.xml'; $testSuite = (new LogMerger())->merge([new SplFileInfo($junitLog)]); self::assertNotNull($testSuite); diff --git a/test/Unit/OtrTest.php b/test/Unit/OtrTest.php new file mode 100644 index 00000000..a8678928 --- /dev/null +++ b/test/Unit/OtrTest.php @@ -0,0 +1,50 @@ +create(); + + $otrFiles = []; + $glob = glob(FIXTURES . '/common_results/otr/*'); + self::assertNotFalse($glob); + foreach ($glob as $file) { + $otrFiles[] = new SplFileInfo($file); + } + + self::assertNotSame([], $otrFiles); + $testSuite = (new LogMerger())->merge($otrFiles); + self::assertNotNull($testSuite); + + $outputFile = $tmpDir . '/result.xml'; + (new Writer())->write( + $testSuite, + $outputFile, + ); + + $xml = file_get_contents($outputFile); + self::assertNotFalse($xml); + file_put_contents($outputFile, $xml); + + self::assertXmlFileEqualsXmlFile(FIXTURES . '/common_results/otr-combined.xml', $outputFile); + } +} diff --git a/test/Unit/WrapperRunner/WrapperRunnerTest.php b/test/Unit/WrapperRunner/WrapperRunnerTest.php index aec946b9..df6651f4 100644 --- a/test/Unit/WrapperRunner/WrapperRunnerTest.php +++ b/test/Unit/WrapperRunner/WrapperRunnerTest.php @@ -542,7 +542,7 @@ public function testWritesLogWithEmptyNameWhenPathIsNotProvided(): void $xml = preg_replace('/time="[^"]+"/', 'time="1.234567"', $xml); file_put_contents($outputFile, $xml); - self::assertXmlFileEqualsXmlFile(FIXTURES . '/common_results/combined.xml', $outputFile); + self::assertXmlFileEqualsXmlFile(FIXTURES . '/common_results/junit-combined.xml', $outputFile); } public function testRunnerReversed(): void diff --git a/test/fixtures/common_results/combined.xml b/test/fixtures/common_results/junit-combined.xml similarity index 100% rename from test/fixtures/common_results/combined.xml rename to test/fixtures/common_results/junit-combined.xml diff --git a/test/fixtures/common_results/otr-combined.xml b/test/fixtures/common_results/otr-combined.xml new file mode 100644 index 00000000..d0e3e4c3 --- /dev/null +++ b/test/fixtures/common_results/otr-combined.xml @@ -0,0 +1,171 @@ + + + + 398c61687e1b + code + Linux 398c61687e1b 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + + Error here! + + + + + + + + + + + + + + + + + + + + + + + Failed asserting that false is true. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/fixtures/common_results/otr/ErrorTest.xml b/test/fixtures/common_results/otr/ErrorTest.xml new file mode 100644 index 00000000..d8b53bcd --- /dev/null +++ b/test/fixtures/common_results/otr/ErrorTest.xml @@ -0,0 +1,36 @@ + + + + 931720dd8f74 + code + Linux 931720dd8f74 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + Error here! + + + + + diff --git a/test/fixtures/common_results/otr/FailureTest.xml b/test/fixtures/common_results/otr/FailureTest.xml new file mode 100644 index 00000000..425f1e0f --- /dev/null +++ b/test/fixtures/common_results/otr/FailureTest.xml @@ -0,0 +1,36 @@ + + + + fdf0a93f2d54 + code + Linux fdf0a93f2d54 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + Failed asserting that false is true. + + + + + diff --git a/test/fixtures/common_results/otr/IncompleteTest.xml b/test/fixtures/common_results/otr/IncompleteTest.xml new file mode 100644 index 00000000..47ef219d --- /dev/null +++ b/test/fixtures/common_results/otr/IncompleteTest.xml @@ -0,0 +1,35 @@ + + + + 9abde680f765 + code + Linux 9abde680f765 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/fixtures/common_results/otr/RiskyTest.xml b/test/fixtures/common_results/otr/RiskyTest.xml new file mode 100644 index 00000000..4f5d532d --- /dev/null +++ b/test/fixtures/common_results/otr/RiskyTest.xml @@ -0,0 +1,30 @@ + + + + bf97c0526199 + code + Linux bf97c0526199 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/fixtures/common_results/otr/SkippedTest.xml b/test/fixtures/common_results/otr/SkippedTest.xml new file mode 100644 index 00000000..ebba32bf --- /dev/null +++ b/test/fixtures/common_results/otr/SkippedTest.xml @@ -0,0 +1,32 @@ + + + + 25e66a83083a + code + Linux 25e66a83083a 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/fixtures/common_results/otr/SuccessTest.xml b/test/fixtures/common_results/otr/SuccessTest.xml new file mode 100644 index 00000000..e08d9efd --- /dev/null +++ b/test/fixtures/common_results/otr/SuccessTest.xml @@ -0,0 +1,30 @@ + + + + 4a750c3af83d + code + Linux 4a750c3af83d 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/fixtures/common_results/otr/WarningTest.xml b/test/fixtures/common_results/otr/WarningTest.xml new file mode 100644 index 00000000..6d2916eb --- /dev/null +++ b/test/fixtures/common_results/otr/WarningTest.xml @@ -0,0 +1,30 @@ + + + + ec5e72506720 + code + Linux ec5e72506720 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/fixtures/special_chars/data-provider-with-special-chars.xml b/test/fixtures/special_chars/junit-data-provider-with-special-chars.xml similarity index 100% rename from test/fixtures/special_chars/data-provider-with-special-chars.xml rename to test/fixtures/special_chars/junit-data-provider-with-special-chars.xml diff --git a/test/fixtures/special_chars/otr-data-provider-with-special-chars.xml b/test/fixtures/special_chars/otr-data-provider-with-special-chars.xml new file mode 100644 index 00000000..59e24f9c --- /dev/null +++ b/test/fixtures/special_chars/otr-data-provider-with-special-chars.xml @@ -0,0 +1,819 @@ + + + + 5cd4b06b41d1 + code + Linux 5cd4b06b41d1 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 + 8.3.30 + NTS + + + + + + + + + + + + + + + + + + + + + 0 +Failed asserting that '' is false. + + + + + + + + + + + + + + 65 +Failed asserting that 'A' is false. + + + + + + + + + + + + + + 92 +Failed asserting that '\' is false. + + + + + + + + + + + + + + 124 +Failed asserting that '|' is false. + + + + + + + + + + + + + + 33 +Failed asserting that '!' is false. + + + + + + + + + + + + + + 34 +Failed asserting that '"' is false. + + + + + + + + + + + + + + 194 +Failed asserting that '£' is false. + + + + + + + + + + + + + + 36 +Failed asserting that '$' is false. + + + + + + + + + + + + + + 37 +Failed asserting that '%' is false. + + + + + + + + + + + + + + 38 +Failed asserting that '&' is false. + + + + + + + + + + + + + + 40 +Failed asserting that '(' is false. + + + + + + + + + + + + + + 41 +Failed asserting that ')' is false. + + + + + + + + + + + + + + 61 +Failed asserting that '=' is false. + + + + + + + + + + + + + + 63 +Failed asserting that '?' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'à' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'è' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'ì' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'ò' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'ù' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'À' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'È' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'Ì' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'Ò' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'Ù' is false. + + + + + + + + + + + + + + 60 +Failed asserting that '<' is false. + + + + + + + + + + + + + + 62 +Failed asserting that '>' is false. + ' is false. + +./test/fixtures/special_chars/UnitTestWithDataProviderSpecialCharsTest.php:19 +]]> + + + + + + + + + + + + + 45 +Failed asserting that '-' is false. + + + + + + + + + + + + + + 95 +Failed asserting that '_' is false. + + + + + + + + + + + + + + 64 +Failed asserting that '@' is false. + + + + + + + + + + + + + + 35 +Failed asserting that '#' is false. + + + + + + + + + + + + + + 91 +Failed asserting that '[' is false. + + + + + + + + + + + + + + 93 +Failed asserting that ']' is false. + + + + + + + + + + + + + + 195 +Failed asserting that 'ß' is false. + + + + + + + + + + + + + + 208 +Failed asserting that 'б' is false. + + + + + + + + + + + + + + 207 +Failed asserting that 'π' is false. + + + + + + + + + + + + + + 226 +Failed asserting that '€' is false. + + + + + + + + + + + + + + 226 +Failed asserting that '✔' is false. + + + + + + + + + + + + + + 228 +Failed asserting that '你' is false. + + + + + + + + + + + + + + 217 +Failed asserting that 'ي' is false. + + + + + + + + + + + + + + 216 +Failed asserting that 'د' is false. + + + + + + + + + + + + + + 90 +Failed asserting that 'Z' is false. + + + + + + + + + + + + + + 0 +Failed asserting that '' is false. + + + + + +