“Web interface” to PHPUnit tests?

前端 未结 11 785
臣服心动
臣服心动 2020-12-02 15:37

Is there a simple \"Web interface\" to running PHPUnit test suites? i.e. a PHP script that runs the test on the command line, and outputs a nicely formatted HTML result.

相关标签:
11条回答
  • 2020-12-02 16:01

    I feel your frustration - I'm a UI guy myself. Looking at the terminal too long makes my head spin. I wrote a quick little application that you might find helpful.


    (source: mattmueller.me)

    You can find it here: http://mattmueller.me/blog/introducing-phpunit-test-report

    Cheers! Matt

    0 讨论(0)
  • 2020-12-02 16:02

    After several hours of researching recently, the best PHPUnit web frontend I have come across was https://github.com/NSinopoli/VisualPHPUnit

    0 讨论(0)
  • 2020-12-02 16:06

    I found this:

    I stumbeld upon a post from Parth Patil, whose solution was to create an xml-report from PHPUnit and then use this xml to create your own report.

    I used his solution, made it PHPUnit 3.4 compatible and also added some Reflection to see my testcase doc-comments in the report. (Note: For the refelection i use the Zend_Framework reflection class)

    0 讨论(0)
  • 2020-12-02 16:07

    You can use phing to run a PHPUnitTask and then convert the output with:

    • PHPUnitReport - This task transforms PHPUnit xml reports to HTML using XSLT.

    Example:

    <phpunitreport infile="reports/testsuites.xml" 
        format="frames" 
        todir="reports/tests" 
        styledir="/home/phing/etc"/>
    

    See phpunit --help for the various output formats.

    The 2.3 version of PHPUnit had a chapter on this, but it is gone for some time now. You might be able to find an old copy with Google somewhere.

    Since you mention this is for phpUnderControl: if you are not fixed on that, consider using Jenkins and http://jenkins-php.org.

    On a side note: unless we are talking CI servers, most people I know don't use PHPUnit through a web interface. They either just use the command line or their IDE integration.

    0 讨论(0)
  • 2020-12-02 16:08

    If you don't care about reformatting the output and just want to run PHPUnit from a web page, you can do so with some PHP code like this:

    <pre>
    <?php 
    $argv[0] = "phpunit.phar";
    $argv[1] = '--bootstrap';
    $argv[2] = 'src/load.php';
    $argv[3] = "tests/MoneyTest";
    $_SERVER['argv'] = $argv;
    include 'phpunit.phar';
    ?>
    </pre>
    

    The file src/load.php is just a bunch of includes to include the classes. The output then looks like this:

    #!/usr/bin/env php
    PHPUnit 4.1.2 by Sebastian Bergmann.
    
    ........................
    
    Time: 122 ms, Memory: 3.25Mb
    
    OK (24 tests, 43 assertions)
    

    Just ignore that first line and you can see the results.

    I'm shocked that PHPUnit does not include a basic way to do this. Some classes may be dependent on the web server. Do we just not test those? Some sites have you upload your files and don't allow command line executions.

    0 讨论(0)
提交回复
热议问题