GithubHelp home page GithubHelp logo

php-junit-merge's Introduction

andreas-weber/php-junit-merge

Build Status

php-junit-merge is a library that merges multiple junit result xml files.

Installation

Simply add a dependency on andreas-weber/php-junit-merge to your project's composer.json file if you use Composer to manage the dependencies of your project.

Usage

After updating dependencies by composer a new binary php-junit-merge is available for usage.

root@dev:~/projects/sample/vendor/bin ./phpjunitmerge
phpjunitmerge 1.0.5 by Andreas Weber

Usage:
 phpjunitmerge [--names="..."] [--ignore="..."] dir file

Arguments:
 dir                   Directory where all files ready to get merged are stored
 file                  The target file in which the merged result should be written

Options:
 --names               A comma-separated list of file names to check (default: "*.xml")
 --ignore              A comma-separated list of file names to ignore (default: "result.xml")
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question
 --no-suffix           Do not add suffix for test suites with duplicate names

The binary expects at least two parameters:

  • dir is the directory, where the application should search for xml files
  • file is the result file, in which the application should write the merged content

A simple call could look like this:

root@dev:~/projects/sample/vendor/bin ./phpjunitmerge src/Tests/Unit/Fixtures result.xml
phpjunitmerge 1.0.0 by Andreas Weber

Found and processed 3 files. Wrote merged content in 'result.xml'.

Example

Single Result Files

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite name="/Some_PHPUnit_Testsuite1" tests="2" assertions="2" failures="0" errors="0" time="1.234567">
        <testsuite name="Unit\Testsuite2" file="/Unit/Testsuite1.php" tests="2" assertions="2" failures="0" errors="0" time="0.003623">
            <testcase name="someRandomTestName1" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="8" assertions="1" time="0.002003"/>
            <testcase name="someRandomTestName2" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="13" assertions="1" time="0.000795"/>
        </testsuite>
    </testsuite>
</testsuites>

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite name="/Some_PHPUnit_Testsuite2" tests="3" assertions="3" failures="0" errors="0" time="1.234567">
        <testsuite name="Unit\Testsuite1" file="/Unit/Testsuite1.php" tests="3" assertions="3" failures="0" errors="0" time="0.003623">
            <testcase name="someRandomTestName1" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="8" assertions="1" time="0.002003"/>
            <testcase name="someRandomTestName2" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="13" assertions="1" time="0.000795"/>
            <testcase name="someRandomTestName3" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="18" assertions="1" time="0.000825"/>
        </testsuite>
    </testsuite>
</testsuites>

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite name="/Some_PHPUnit_Testsuite3" tests="6" assertions="6" failures="0" errors="0" time="1.234567">
        <testsuite name="Unit\Testsuite3" file="/Unit/Testsuite1.php" tests="2" assertions="2" failures="0" errors="0" time="0.003623">
            <testcase name="someRandomTestName1" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="8" assertions="1" time="0.002003"/>
            <testcase name="someRandomTestName2" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="13" assertions="1" time="0.000795"/>
        </testsuite>
        <testsuite name="Unit\Testsuite4" file="/Unit/Testsuite1.php" tests="4" assertions="4" failures="0" errors="0" time="0.003623">
            <testcase name="someRandomTestName1" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="8" assertions="1" time="0.002003"/>
            <testcase name="someRandomTestName2" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="13" assertions="1" time="0.000795"/>
            <testcase name="someRandomTestName3" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="16" assertions="1" time="0.000795"/>
            <testcase name="someRandomTestName4" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="21" assertions="1" time="0.000795"/>
        </testsuite>
    </testsuite>
</testsuites>

Merged Result File

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
  <testsuite tests="11" assertions="11" failures="0" errors="0" time="3.703701">
    <testsuite name="/Some_PHPUnit_Testsuite1" tests="2" assertions="2" failures="0" errors="0" time="1.234567">
        <testsuite name="Unit\Testsuite2" file="/Unit/Testsuite1.php" tests="2" assertions="2" failures="0" errors="0" time="0.003623">
            <testcase name="someRandomTestName1" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="8" assertions="1" time="0.002003"/>
            <testcase name="someRandomTestName2" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="13" assertions="1" time="0.000795"/>
        </testsuite>
    </testsuite>
    <testsuite name="/Some_PHPUnit_Testsuite2" tests="3" assertions="3" failures="0" errors="0" time="1.234567">
        <testsuite name="Unit\Testsuite1" file="/Unit/Testsuite1.php" tests="3" assertions="3" failures="0" errors="0" time="0.003623">
            <testcase name="someRandomTestName1" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="8" assertions="1" time="0.002003"/>
            <testcase name="someRandomTestName2" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="13" assertions="1" time="0.000795"/>
            <testcase name="someRandomTestName3" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="18" assertions="1" time="0.000825"/>
        </testsuite>
    </testsuite>
    <testsuite name="/Some_PHPUnit_Testsuite3" tests="6" assertions="6" failures="0" errors="0" time="1.234567">
        <testsuite name="Unit\Testsuite3" file="/Unit/Testsuite1.php" tests="2" assertions="2" failures="0" errors="0" time="0.003623">
            <testcase name="someRandomTestName1" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="8" assertions="1" time="0.002003"/>
            <testcase name="someRandomTestName2" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="13" assertions="1" time="0.000795"/>
        </testsuite>
        <testsuite name="Unit\Testsuite4" file="/Unit/Testsuite1.php" tests="4" assertions="4" failures="0" errors="0" time="0.003623">
            <testcase name="someRandomTestName1" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="8" assertions="1" time="0.002003"/>
            <testcase name="someRandomTestName2" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="13" assertions="1" time="0.000795"/>
            <testcase name="someRandomTestName3" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="16" assertions="1" time="0.000795"/>
            <testcase name="someRandomTestName4" class="Unit\Testsuite1" file="/Unit/Testsuite1.php" line="21" assertions="1" time="0.000795"/>
        </testsuite>
    </testsuite>
  </testsuite>
</testsuites>

Developer

Environment

Boot:

vagrant up

Enter virtual machine:

vagrant ssh

Run tests:

cd /vagrant
vendor/bin/phpunit src/Test/

Build targets

vagrant@andreas-weber:/vagrant$ ant
Buildfile: /vagrant/build.xml

help:
     [echo]
     [echo] The following commands are available:
     [echo]
     [echo] |   +++ Build +++
     [echo] |-- build                (Run the build)
     [echo] |   |-- dependencies     (Install dependencies)
     [echo] |   |-- tests            (Lint all files and run tests)
     [echo] |   |-- metrics          (Generate quality metrics)
     [echo] |-- cleanup              (Cleanup the build directory)
     [echo] |
     [echo] |   +++ Composer +++
     [echo] |-- composer             -> composer-download, composer-install
     [echo] |-- composer-download    (Downloads composer.phar to project)
     [echo] |-- composer-install     (Install all dependencies)
     [echo] |
     [echo] |   +++ Testing +++
     [echo] |-- phpunit              -> phpunit-full
     [echo] |-- phpunit-tests        (Run unit tests)
     [echo] |-- phpunit-full         (Run unit tests and generate code coverage report / logs)
     [echo] |
     [echo] |   +++ Metrics +++
     [echo] |-- coverage             (Show code coverage metric)
     [echo] |-- phploc               (Show lines of code metric)
     [echo] |-- qa                   (Run quality assurance tools)
     [echo] |-- |-- phpcpd           (Show copy paste metric)
     [echo] |-- |-- phpcs            (Show code sniffer metric)
     [echo] |-- |-- phpmd            (Show mess detector metric)
     [echo] |
     [echo] |   +++ Metric Reports +++
     [echo] |-- phploc-report        (Generate lines of code metric report)
     [echo] |-- phpcpd-report        (Generate copy paste metric report)
     [echo] |-- phpcs-report         (Generate code sniffer metric report)
     [echo] |-- phpmd-report         (Generate mess detector metric report)
     [echo] |
     [echo] |   +++ Tools +++
     [echo] |-- lint                 (Lint all php files)
     [echo]

Attributions

Thanks to Sebastian Bergmann for his gist merge-phpunit-xml.php, which was the base and inspired me to develop this library.

Thoughts

Pull requests are highly appreciated. Built with love. Hope you'll enjoy.. :-)

php-junit-merge's People

Contributors

albertodimaio3 avatar andreaskweber avatar sakharovmaksim avatar tarlepp avatar tomzx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-junit-merge's Issues

Skip invalid files with a warning

phpunit-merge-ouput:
     [exec] phpjunitmerge 1.0.1 by Andreas Weber
     [exec] 
     [exec] 
     [exec] 
     [exec]                                                                                                                                                                                                                          
     [exec]   [TheSeer\fDOM\fDOMException]                                                                                                                                                                                           
     [exec]   loading file '/var/lib/jenkins/jobs/ia-backend-md-trunk-nightly/workspace/build/phpunit/junit-api-affilinet.xml' failed.                                                                                               
     [exec]   [/var/lib/jenkins/jobs/ia-backend-md-trunk-nightly/workspace/build/phpunit/junit-api-affilinet.xml] [Line: 707 - Column: 147] Fatal Error 9: Input is not proper UTF-8, indicate encoding !Bytes: 0xE6 0xBB 0xFF 0xC3  
     [exec]   [/var/lib/jenkins/jobs/ia-backend-md-trunk-nightly/workspace/build/phpunit/junit-api-affilinet.xml] [Line: 89158 - Column: 109] Error 2: xmlSAX2Characters: huge text node                                             
     [exec]   [/var/lib/jenkins/jobs/ia-backend-md-trunk-nightly/workspace/build/phpunit/junit-api-affilinet.xml] [Line: 89158 - Column: 110] Fatal Error 5: Extra content at the end of the document                                
     [exec]                                                                                                                                                                                                                          
     [exec] 
     [exec] 
     [exec] phpjunitmerge [--names="..."] [--ignore="..."] dir file
     [exec] 
     [exec] 

Updating dependencies

Hey!

I just wanted to try this package but I cannot install it as it required "symfony/finder" in either "^3.0 || ^4.0".
Can we bump the version up to be able to use this package along "symfony/finder" version ^5.0?
Would really appreciate that! I created a PR for this.

Cannot pass a single value to --names

Your function Command::findFiles expects an array, yet symfony's console will return it a string. You should probably explicitly cast the result to an array.

$names = (array)$input->getOption('names');
PHP Catchable fatal error:  Argument 2 passed to AndreasWeber\PHPJUNITMERGE\Console\Command::findFiles() must be of the type array, string given, called in /path/vendor/andreas-weber/php-junit-merge/src/Console/Command.php on line 108 and defined in /path/vendor/andreas-weber/php-junit-merge/src/Console/Command.php on line 129
PHP Stack trace:
PHP   1. {main}() /path/vendor/andreas-weber/php-junit-merge/phpjunitmerge:0
PHP   2. Symfony\Component\Console\Application->run() /path/vendor/andreas-weber/php-junit-merge/phpjunitmerge:57
PHP   3. AndreasWeber\PHPJUNITMERGE\Console\Application->doRun() /path/vendor/symfony/console/Symfony/Component/Console/Application.php:124
PHP   4. Symfony\Component\Console\Application->doRun() /path/vendor/andreas-weber/php-junit-merge/src/Console/Application.php:135
PHP   5. Symfony\Component\Console\Application->doRunCommand() /path/vendor/symfony/console/Symfony/Component/Console/Application.php:193
PHP   6. Symfony\Component\Console\Command\Command->run() /path/vendor/symfony/console/Symfony/Component/Console/Application.php:889
PHP   7. AndreasWeber\PHPJUNITMERGE\Console\Command->execute() /path/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:253
PHP   8. AndreasWeber\PHPJUNITMERGE\Console\Command->findFiles() /path/vendor/andreas-weber/php-junit-merge/src/Console/Command.php:108

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.