PHPUnit
[ class tree: PHPUnit ] [ index: PHPUnit ] [ all elements ]

Source for file TestSuite.php

Documentation is available at TestSuite.php

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: PHPUnit                                                        |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  7. // +------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,        |
  9. // | that is available at http://www.php.net/license/3_0.txt.               |
  10. // | If you did not receive a copy of the PHP license and are unable to     |
  11. // | obtain it through the world-wide-web, please send a note to            |
  12. // | license@php.net so we can mail you a copy immediately.                 |
  13. // +------------------------------------------------------------------------+
  14. //
  15. // $Id: TestSuite.php,v 1.13 2004/12/22 08:06:11 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit/TestCase.php';
  19.  
  20. /**
  21.  * A TestSuite is a Composite of Tests. It runs a collection of test cases.
  22.  *
  23.  * Here is an example using the dynamic test definition.
  24.  *
  25.  * <code>
  26.  * <?php
  27.  * $suite = new PHPUnit_TestSuite();
  28.  * $suite->addTest(new MathTest('testPass'));
  29.  * ?>
  30.  * </code>
  31.  *
  32.  * Alternatively, a TestSuite can extract the tests to be run automatically.
  33.  * To do so you pass the classname of your TestCase class to the TestSuite
  34.  * constructor.
  35.  *
  36.  * <code>
  37.  * <?php
  38.  * $suite = new TestSuite('classname');
  39.  * ?>
  40.  * </code>
  41.  *
  42.  * This constructor creates a suite with all the methods starting with
  43.  * "test" that take no arguments.
  44.  *
  45.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  46.  * @copyright   Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  47.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  48.  * @category    Testing
  49.  * @package     PHPUnit
  50.  */
  51.     /**
  52.     * The name of the test suite.
  53.     *
  54.     * @var    string 
  55.     * @access private
  56.     */
  57.     var $_name '';
  58.  
  59.     /**
  60.     * The tests in the test suite.
  61.     *
  62.     * @var    array 
  63.     * @access private
  64.     */
  65.     var $_tests = array();
  66.  
  67.     /**
  68.     * Constructs a TestSuite.
  69.     *
  70.     * @param  mixed 
  71.     * @access public
  72.     */
  73.     function PHPUnit_TestSuite($test = FALSE{
  74.         if ($test !== FALSE{
  75.             $this->setName($test);
  76.             $this->addTestSuite($test);
  77.         }
  78.     }
  79.  
  80.     /**
  81.     * Adds a test to the suite.
  82.     *
  83.     * @param  object 
  84.     * @access public
  85.     */
  86.     function addTest(&$test{
  87.         $this->_tests[$test;
  88.     }
  89.  
  90.     /**
  91.     * Adds the tests from the given class to the suite.
  92.     *
  93.     * @param  string 
  94.     * @access public
  95.     */
  96.     function addTestSuite($testClass{
  97.         if (class_exists($testClass)) {
  98.             $methods       get_class_methods($testClass);
  99.             $parentClasses = array(strtolower($testClass));
  100.             $parentClass   $testClass;
  101.  
  102.             while(is_string($parentClass get_parent_class($parentClass))) {
  103.                 $parentClasses[$parentClass;
  104.             }
  105.  
  106.             foreach ($methods as $method{
  107.                 if (substr($method04== 'test' &&
  108.                     !in_array($method$parentClasses)) {
  109.                     $this->addTest(new $testClass($method));
  110.                 }
  111.             }
  112.         }
  113.     }
  114.  
  115.     /**
  116.     * Counts the number of test cases that will be run by this test.
  117.     *
  118.     * @return integer 
  119.     * @access public
  120.     */
  121.     function countTestCases({
  122.         $count = 0;
  123.  
  124.         foreach ($this->_tests as $test{
  125.             $count += $test->countTestCases();
  126.         }
  127.  
  128.         return $count;
  129.     }
  130.  
  131.     /**
  132.     * Returns the name of the suite.
  133.     *
  134.     * @return string 
  135.     * @access public
  136.     */
  137.     function getName({
  138.         return $this->_name;
  139.     }
  140.  
  141.     /**
  142.     * Runs the tests and collects their result in a TestResult.
  143.     *
  144.     * @param  object 
  145.     * @access public
  146.     */
  147.     function run(&$result{
  148.         for ($i = 0; $i sizeof($this->_tests&& !$result->shouldStop()$i++{
  149.             $this->_tests[$i]->run($result);
  150.         }
  151.     }
  152.  
  153.     /**
  154.     * Runs a test.
  155.     *
  156.     * @param  object 
  157.     * @param  object 
  158.     * @access public
  159.     */
  160.     function runTest(&$test&$result{
  161.         $test->run($result);
  162.     }
  163.  
  164.     /**
  165.     * Sets the name of the suite.
  166.     *
  167.     * @param  string 
  168.     * @access public
  169.     */
  170.     function setName($name{
  171.         $this->_name $name;
  172.     }
  173.  
  174.     /**
  175.     * Returns the test at the given index.
  176.     *
  177.     * @param  integer 
  178.     * @return object 
  179.     * @access public
  180.     */
  181.     function &testAt($index{
  182.         if (isset($this->_tests[$index])) {
  183.             return $this->_tests[$index];
  184.         else {
  185.             return FALSE;
  186.         }
  187.     }
  188.  
  189.     /**
  190.     * Returns the number of tests in this suite.
  191.     *
  192.     * @return integer 
  193.     * @access public
  194.     */
  195.     function testCount({
  196.         return sizeof($this->_tests);
  197.     }
  198.  
  199.     /**
  200.     * Returns the tests as an enumeration.
  201.     *
  202.     * @return array 
  203.     * @access public
  204.     */
  205.     function &tests({
  206.         return $this->_tests;
  207.     }
  208.  
  209.     /**
  210.     * Returns a string representation of the test suite.
  211.     *
  212.     * @return string 
  213.     * @access public
  214.     */
  215.     function toString({
  216.         return '';
  217.     }
  218. }
  219. ?>

Documentation generated on Mon, 11 Mar 2019 14:22:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.