phpunit-merger
phpunit-merger copied to clipboard
Fixed addTestSuites-Call in case the name attribute is empty and there is only one testsuite within the testsuite.
We are using phpunit-merger to merge the result of named testsuites of phpunit. Handling of testsuites with only one testsuite as a child is already handled in case of subtestsuites. But was not handled correctly on the top level.
Are you still maintaining the project @IchHabRecht? If yes, I have two other features that I can create pull-requests for.
Hi @thirsch,
Thank you for your pull request. To understand the problem and fix, I kindly ask you to share an example of your xml file(s).
Hi @IchHabRecht,
I mixed up the issue description and the root cause a bit. Here is why the fix is required:
If you have for example these two xml files:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="" tests="1" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.030092">
<testsuite name="Tests1" tests="1" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.030092">
<testsuite name="Tests\One\MyTest" file="/opt/project/tests/one/MyTest.php" tests="1" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.030092">
<testcase name="testOne" class="Tests\One\MyTest" classname="Tests.One.MyTest" file="/opt/project/tests/one/MyTest.php" line="9" assertions="1" time="0.030092"/>
</testsuite>
</testsuite>
</testsuite>
</testsuites>
and
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="" tests="2" assertions="2" errors="0" warnings="0" failures="0" skipped="0" time="0.043921">
<testsuite name="Tests2" tests="2" assertions="2" errors="0" warnings="0" failures="0" skipped="0" time="0.043921">
<testsuite name="Tests\Two\MySecondTest" file="/opt/project/tests/two/MySecondTest.php" tests="1" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.043866">
<testcase name="testTwo" class="Tests\Two\MySecondTest" classname="Tests.Two.MySecondTest" file="/opt/project/tests/two/MySecondTest.php" line="9" assertions="1" time="0.043866"/>
</testsuite>
<testsuite name="Tests\Two\MyThirdTest" file="/opt/project/tests/two/MyThirdTest.php" tests="1" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.000055">
<testcase name="testThree" class="Tests\Two\MyThirdTest" classname="Tests.Two.MyThirdTest" file="/opt/project/tests/two/MyThirdTest.php" line="9" assertions="1" time="0.000055"/>
</testsuite>
</testsuite>
</testsuite>
</testsuites>
with more then one nested testsuites in the second file, the output of the merge will be:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Tests\One\MyTest" file="0" tests="0" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.030092" line="9">
<testcase name="testOne" class="Tests\One\MyTest" classname="Tests.One.MyTest" file="/opt/project/tests/one/MyTest.php" line="9" assertions="1" time="0.030092"/>
</testsuite>
</testsuites>
The problem: In the second file, testsuite "Tests2" does not only contain one testsuite, but two (Tests\Two\MySecondTest and Tests\Two\MyThirdTest). The example project used to produce the files contains the following structure:
- tests
- one
- MyTest.php
- function testOne()
- MyTest.php
- two
- MySecondTest.php
- function testTwo()
- MyThirdTest.php
- function testThree()
- MySecondTest.php
- one
and the following phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<testsuites>
<testsuite name="Tests1">
<directory>tests/one</directory>
</testsuite>
<testsuite name="Tests2">
<directory>tests/two</directory>
</testsuite>
</testsuites>
</phpunit>
I've executed the two testsuites separately by invoking vendor/bin/phpunit --testsuite Tests1 --log-junit logs/tests-one.xml
and vendor/bin/phpunit --testsuite Tests2 --log-junit logs/tests-two.xml
and merged them by calling vendor/bin/phpunit-merger log logs result.xml
.
With the provided fix, the script merges the two example files correctly to the following result:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="Tests1" tests="0" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.030092" line="9">
<testsuite name="Tests\One\MyTest" file="0" tests="0" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.030092" line="9">
<testcase name="testOne" class="Tests\One\MyTest" classname="Tests.One.MyTest" file="/opt/project/tests/one/MyTest.php" line="9" assertions="1" time="0.030092"/>
</testsuite>
</testsuite>
<testsuite name="Tests2" tests="0" assertions="2" errors="0" warnings="0" failures="0" skipped="0" time="0.043921" line="18">
<testsuite name="Tests\Two\MySecondTest" file="0" tests="0" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="0.043866" line="9">
<testcase name="testTwo" class="Tests\Two\MySecondTest" classname="Tests.Two.MySecondTest" file="/opt/project/tests/two/MySecondTest.php" line="9" assertions="1" time="0.043866"/>
</testsuite>
<testsuite name="Tests\Two\MyThirdTest" file="0" tests="0" assertions="1" errors="0" warnings="0" failures="0" skipped="0" time="5.5E-5" line="9">
<testcase name="testThree" class="Tests\Two\MyThirdTest" classname="Tests.Two.MyThirdTest" file="/opt/project/tests/two/MyThirdTest.php" line="9" assertions="1" time="0.000055"/>
</testsuite>
</testsuite>
</testsuites>
Any update, if this will be merged? I've got some more improvements to phpunit-merger and would like to know if you are interested in gettings pullrequests for them?
I'm also interested in this fix. Is there any indication whether/when it will get merged?
this PR would also fix my usage of this