/**
     * Run the tests
     *
     * This method will run the tests with the correct Reporter. It will run 
     * grouped tests if asked to and filter results. It also has support for 
     * running coverage report. 
     *
     */
    public function run(){
        $testGroup = $this->testGroup;
        if (PHP_SAPI === 'cli') {
            require_once(dirname(__FILE__) . '/DoctrineTest/Reporter/Cli.php');
            $reporter = new DoctrineTest_Reporter_Cli();
            $argv = $_SERVER['argv'];
            array_shift($argv);
            $options = $this->parseOptions($argv);
        } else {
            require_once(dirname(__FILE__) . '/DoctrineTest/Reporter/Html.php');
            $options = $_GET;
            if(isset($options["filter"])){
                $options["filter"] = explode(",", $options["filter"]);
            }
            if(isset($options["group"])){
                $options["group"] = explode(",", $options["group"]);
            }
            $reporter = new DoctrineTest_Reporter_Html();
        }

        //replace global group with custom group if we have group option set
        if (isset($options['group'])) {
            $testGroup = new GroupTest('Doctrine Framework Custom test', 'custom');
            foreach($options['group'] as $group) {
                if (isset($this->groups[$group])) {
                    $testGroup->addTestCase($this->groups[$group]);
                } else if (class_exists($group)) {
                    $testGroup->addTestCase(new $group);
                } else {
                    die($group . " is not a valid group or doctrine test class\n ");
                }
            }
        } 

        if (isset($options['ticket'])) {
            $testGroup = new GroupTest('Doctrine Framework Custom test', 'custom');
            foreach ($options['ticket'] as $ticket) {
                $class = 'Doctrine_Ticket_' . $ticket. '_TestCase';
                $testGroup->addTestCase(new $class);
            }
        }

        $filter = '';
        if (isset($options['filter'])) {
            $filter = $options['filter'];
        }

        //show help text
        if (isset($options['help'])) {
            echo "Doctrine test runner help\n";
            echo "===========================\n";
            echo " To run all tests simply run this script without arguments. \n";
            echo "\n Flags:\n";
            echo " -coverage will generate coverage report data that can be viewed with the cc.php script in this folder. NB! This takes time. You need xdebug to run this\n";
            echo " -group <groupName1> <groupName2> <className1> Use this option to run just a group of tests or tests with a given classname. Groups are currently defined as the variable name they are called in this script.\n";
            echo " -filter <string1> <string2> case insensitive strings that will be applied to the className of the tests. A test_classname must contain all of these strings to be run\n"; 
            echo "\nAvailable groups:\n tickets, transaction, driver, data_dict, sequence, export, import, expression, core, relation, data_types, utility, db, event_listener, query_tests, record, cache\n";
            die();
        }

        //generate coverage report
        if (isset($options['coverage'])) {

            /*
             * The below code will not work for me (meus). It would be nice if 
             * somebody could give it a try. Just replace this block of code 
             * with the one below
             *
             define('PHPCOVERAGE_HOME', dirname(dirname(__FILE__)) . '/vendor/spikephpcoverage');
            require_once PHPCOVERAGE_HOME . '/CoverageRecorder.php';
            require_once PHPCOVERAGE_HOME . '/reporter/HtmlCoverageReporter.php';

            $covReporter = new HtmlCoverageReporter('Doctrine Code Coverage Report', '', 'coverage2');

            $includePaths = array('../lib');
            $excludePaths = array();
            $cov = new CoverageRecorder($includePaths, $excludePaths, $covReporter);

            $cov->startInstrumentation();
            $testGroup->run($reporter, $filter);
            $cov->stopInstrumentation();

            $cov->generateReport();
            $covReporter->printTextSummary();
             */
            xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
            $testGroup->run($reporter, $filter);
            $result['coverage'] = xdebug_get_code_coverage();
            xdebug_stop_code_coverage();
            file_put_contents(dirname(__FILE__) . '/coverage/coverage.txt', serialize($result));
            require_once dirname(__FILE__) . '/DoctrineTest/Coverage.php';
            $coverageGeneration = new DoctrineTest_Coverage();
            $coverageGeneration->generateReport();
            return;
            // */

        }
        $testGroup->run($reporter, $filter);
    }
 /**
  * Run the tests
  *
  * This method will run the tests with the correct Reporter. It will run 
  * grouped tests if asked to and filter results. It also has support for 
  * running coverage report. 
  *
  */
 public function run()
 {
     $testGroup = $this->testGroup;
     if (PHP_SAPI === 'cli') {
         require_once dirname(__FILE__) . '/DoctrineTest/Reporter/Cli.php';
         $reporter = new DoctrineTest_Reporter_Cli();
         $argv = $_SERVER['argv'];
         array_shift($argv);
         $options = $this->parseOptions($argv);
     } else {
         require_once dirname(__FILE__) . '/DoctrineTest/Reporter/Html.php';
         $options = $_GET;
         if (isset($options['filter'])) {
             if (!is_array($options['filter'])) {
                 $options['filter'] = explode(',', $options['filter']);
             }
         }
         if (isset($options['group'])) {
             if (!is_array($options['group'])) {
                 $options['group'] = explode(',', $options['group']);
             }
         }
         $reporter = new DoctrineTest_Reporter_Html();
     }
     //replace global group with custom group if we have group option set
     if (isset($options['group'])) {
         $testGroup = new GroupTest('Doctrine Custom Test', 'custom');
         foreach ($options['group'] as $group) {
             if (isset($this->groups[$group])) {
                 $testGroup->addTestCase($this->groups[$group]);
             } else {
                 if (class_exists($group)) {
                     $testGroup->addTestCase(new $group());
                 } else {
                     die($group . " is not a valid group or doctrine test class\n ");
                 }
             }
         }
     }
     if (isset($options['ticket'])) {
         $testGroup = new GroupTest('Doctrine Custom Test', 'custom');
         foreach ($options['ticket'] as $ticket) {
             $class = 'Doctrine_Ticket_' . $ticket . '_TestCase';
             $testGroup->addTestCase(new $class());
         }
     }
     $filter = '';
     if (isset($options['filter'])) {
         $filter = $options['filter'];
     }
     //show help text
     if (isset($options['help'])) {
         $availableGroups = sort(array_keys($this->groups));
         echo "Doctrine test runner help\n";
         echo "===========================\n";
         echo " To run all tests simply run this script without arguments. \n";
         echo "\n Flags:\n";
         echo " -coverage will generate coverage report data that can be viewed with the cc.php script in this folder. NB! This takes time. You need xdebug to run this\n";
         echo " -group <groupName1> <groupName2> <className1> Use this option to run just a group of tests or tests with a given classname. Groups are currently defined as the variable name they are called in this script.\n";
         echo " -filter <string1> <string2> case insensitive strings that will be applied to the className of the tests. A test_classname must contain all of these strings to be run\n";
         echo "\nAvailable groups:\n " . implode(', ', $availableGroups) . "\n";
         die;
     }
     //generate coverage report
     if (isset($options['coverage'])) {
         /*
         * The below code will not work for me (meus). It would be nice if 
         * somebody could give it a try. Just replace this block of code 
         * with the one below
         *
         define('PHPCOVERAGE_HOME', dirname(dirname(__FILE__)) . '/vendor/spikephpcoverage');
                     require_once PHPCOVERAGE_HOME . '/CoverageRecorder.php';
                     require_once PHPCOVERAGE_HOME . '/reporter/HtmlCoverageReporter.php';
         
                     $covReporter = new HtmlCoverageReporter('Doctrine Code Coverage Report', '', 'coverage2');
         
                     $includePaths = array('../lib');
                     $excludePaths = array();
                     $cov = new CoverageRecorder($includePaths, $excludePaths, $covReporter);
         
                     $cov->startInstrumentation();
                     $ret = $testGroup->run($reporter, $filter);
                     $cov->stopInstrumentation();
         
                     $cov->generateReport();
                     $covReporter->printTextSummary();
                     return $ret;
         */
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         $ret = $testGroup->run($reporter, $filter);
         $result['coverage'] = xdebug_get_code_coverage();
         xdebug_stop_code_coverage();
         file_put_contents(dirname(__FILE__) . '/coverage/coverage.txt', serialize($result));
         require_once dirname(__FILE__) . '/DoctrineTest/Coverage.php';
         $coverageGeneration = new DoctrineTest_Coverage();
         $coverageGeneration->generateReport();
         return $ret;
         // */
     }
     if (array_key_exists('only-failed', $options)) {
         $testGroup->onlyRunFailed(true);
     }
     $result = $testGroup->run($reporter, $filter);
     global $startTime;
     $endTime = time();
     $time = $endTime - $startTime;
     if (PHP_SAPI === 'cli') {
         echo "\nTests ran in " . $time . " seconds and used " . memory_get_peak_usage() / 1024 . " KB of memory\n\n";
     } else {
         echo "<p>Tests ran in " . $time . " seconds and used " . memory_get_peak_usage() / 1024 . " KB of memory</p>";
     }
     return $result;
 }
Exemple #3
0
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.phpdoctrine.org>.
 */

require_once dirname(__FILE__) . '/../../lib/Doctrine.php';
require_once dirname(__FILE__) . '/../DoctrineTest/Coverage.php';
$reporter = new DoctrineTest_Coverage();
$svn_info = explode(" ", exec("svn info | grep Revision"));
$revision = $svn_info[1];


?>
<html>
    <head>
        <style type="text/css">
            .covered{ background: green;}
            .normal{ background: white;}
            .red{ background: red;}
            .orange{ background: #f90;}
       </style>
</head>
<body>