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

Source for file BaseTestRunner.php

Documentation is available at BaseTestRunner.php

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: PHPUnit2                                                       |
  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: BaseTestRunner.php,v 1.10.2.4 2005/03/06 07:53:32 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit2/Framework/AssertionFailedError.php';
  19. require_once 'PHPUnit2/Framework/Test.php';
  20. require_once 'PHPUnit2/Framework/TestListener.php';
  21. require_once 'PHPUnit2/Framework/TestSuite.php';
  22. require_once 'PHPUnit2/Runner/StandardTestSuiteLoader.php';
  23. require_once 'PHPUnit2/Runner/TestRunListener.php';
  24.  
  25. /**
  26.  * Base class for all test runners.
  27.  *
  28.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  29.  * @copyright   Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  30.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  31.  * @category    Testing
  32.  * @package     PHPUnit2
  33.  * @subpackage  Runner
  34.  * @abstract
  35.  */
  36. abstract class PHPUnit2_Runner_BaseTestRunner implements PHPUnit2_Framework_TestListener {
  37.     // {{{ Constants
  38.  
  39.     const SUITE_METHODNAME = 'suite';
  40.  
  41.     // }}}
  42.     // {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
  43.  
  44.     /**
  45.     * An error occurred.
  46.     *
  47.     * @param  PHPUnit2_Framework_Test $test 
  48.     * @param  Exception               $e 
  49.     * @access public
  50.     */
  51.     public function addError(PHPUnit2_Framework_Test $testException $e{
  52.         $this->testFailed(PHPUnit2_Runner_TestRunListener::STATUS_ERROR$test$e);
  53.     }
  54.  
  55.     // }}}
  56.     // {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
  57.  
  58.     /**
  59.     * A failure occurred.
  60.     *
  61.     * @param  PHPUnit2_Framework_Test                 $test 
  62.     * @param  PHPUnit2_Framework_AssertionFailedError $e 
  63.     * @access public
  64.     */
  65.     public function addFailure(PHPUnit2_Framework_Test $testPHPUnit2_Framework_AssertionFailedError $e{
  66.         $this->testFailed(PHPUnit2_Runner_TestRunListener::STATUS_FAILURE$test$e);
  67.     }
  68.  
  69.     // }}}
  70.     // {{{ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e)
  71.  
  72.     /**
  73.     * Incomplete test.
  74.     *
  75.     * @param  PHPUnit2_Framework_Test $test 
  76.     * @param  Exception               $e 
  77.     * @access public
  78.     */
  79.     public function addIncompleteTest(PHPUnit2_Framework_Test $testException $e{
  80.         $this->testFailed(PHPUnit2_Runner_TestRunListener::STATUS_INCOMPLETE$test$e);
  81.     }
  82.  
  83.     // }}}
  84.     // {{{ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite)
  85.  
  86.     /**
  87.     * A testsuite started.
  88.     *
  89.     * @param  PHPUnit2_Framework_TestSuite $suite 
  90.     * @access public
  91.     * @since  2.2.0
  92.     */
  93.     public function startTestSuite(PHPUnit2_Framework_TestSuite $suite{
  94.     }
  95.  
  96.     // }}}
  97.     // {{{ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite)
  98.  
  99.     /**
  100.     * A testsuite ended.
  101.     *
  102.     * @param  PHPUnit2_Framework_TestSuite $suite 
  103.     * @access public
  104.     * @since  2.2.0
  105.     */
  106.     public function endTestSuite(PHPUnit2_Framework_TestSuite $suite{
  107.     }
  108.  
  109.     // }}}
  110.     // {{{ public function startTest(PHPUnit2_Framework_Test $test)
  111.  
  112.     /**
  113.     * A test started.
  114.     *
  115.     * @param  PHPUnit2_Framework_Test  $test 
  116.     * @access public
  117.     */
  118.     public function startTest(PHPUnit2_Framework_Test $test{
  119.         $this->testStarted($test->getName());
  120.     }
  121.  
  122.     // }}}
  123.     // {{{ public function endTest(PHPUnit2_Framework_Test $test)
  124.  
  125.     /**
  126.     * A test ended.
  127.     *
  128.     * @param  PHPUnit2_Framework_Test  $test 
  129.     * @access public
  130.     */
  131.     public function endTest(PHPUnit2_Framework_Test $test{
  132.         $this->testEnded($test->getName());
  133.     }
  134.  
  135.     // }}}
  136.     // {{{ public function getLoader()
  137.  
  138.     /**
  139.     * Returns the loader to be used.
  140.     *
  141.     * @return PHPUnit2_Runner_TestSuiteLoader 
  142.     * @access protected
  143.     */
  144.     public function getLoader({
  145.         return new PHPUnit2_Runner_StandardTestSuiteLoader;
  146.     }
  147.  
  148.     // }}}
  149.     // {{{ public function getTest($suiteClassName, $suiteClassFile = '')
  150.  
  151.     /**
  152.     * Returns the Test corresponding to the given suite.
  153.     * This is a template method, subclasses override
  154.     * the runFailed() and clearStatus() methods.
  155.     *
  156.     * @param  string  $suiteClassName 
  157.     * @param  string  $suiteClassFile 
  158.     * @return PHPUnit2_Framework_Test 
  159.     * @access public
  160.     */
  161.     public function getTest($suiteClassName$suiteClassFile ''{
  162.         if ($suiteClassFile == $suiteClassName '.php'{
  163.             $suiteClassFile '';
  164.         }
  165.  
  166.         try {
  167.             $testClass $this->loadSuiteClass($suiteClassName$suiteClassFile);
  168.         }
  169.  
  170.         catch (Exception $e{
  171.             $this->runFailed($e->getMessage());
  172.             return NULL;
  173.         }
  174.  
  175.         try {
  176.             $suiteMethod $testClass->getMethod(self::SUITE_METHODNAME);
  177.  
  178.             if (!$suiteMethod->isStatic()) {
  179.                 $this->runFailed(
  180.                   'suite() method must be static.'
  181.                 );
  182.  
  183.                 return NULL;
  184.             }
  185.  
  186.             try {
  187.                 $test $suiteMethod->invoke(NULL);
  188.             }
  189.  
  190.             catch (ReflectionException $e{
  191.                 $this->runFailed(
  192.                   sprintf(
  193.                     "Failed to invoke suite() method.\n%s",
  194.  
  195.                     $e->getMessage()
  196.                   )
  197.                 );
  198.  
  199.                 return NULL;
  200.             }
  201.         }
  202.  
  203.         catch (ReflectionException $e{
  204.             $test = new PHPUnit2_Framework_TestSuite($testClass);
  205.         }
  206.  
  207.         $this->clearStatus();
  208.  
  209.         return $test;
  210.     }
  211.  
  212.     // }}}
  213.     // {{{ protected abstract function runFailed($message)
  214.  
  215.     /**
  216.     * Override to define how to handle a failed loading of
  217.     * a test suite.
  218.     *
  219.     * @param  string  $message 
  220.     * @access protected
  221.     * @abstract
  222.     */
  223.     protected abstract function runFailed($message);
  224.  
  225.     // }}}
  226.     // {{{ protected function loadSuiteClass($suiteClassName, $suiteClassFile = '')
  227.  
  228.     /**
  229.     * Returns the loaded ReflectionClass for a suite name.
  230.     *
  231.     * @param  string  $suiteClassName 
  232.     * @param  string  $suiteClassFile 
  233.     * @return ReflectionClass 
  234.     * @access protected
  235.     */
  236.     protected function loadSuiteClass($suiteClassName$suiteClassFile ''{
  237.         return $this->getLoader()->load($suiteClassName$suiteClassFile);
  238.     }
  239.  
  240.     // }}}
  241.     // {{{ protected function clearStatus()
  242.  
  243.     /**
  244.     * Clears the status message.
  245.     *
  246.     * @access protected
  247.     */
  248.     protected function clearStatus({
  249.     }
  250.  
  251.     // }}}
  252.     // {{{ public abstract function testStarted($testName)
  253.  
  254.     /**
  255.     * A test started.
  256.     *
  257.     * @param  string  $testName 
  258.     * @access public
  259.     * @abstract
  260.     */
  261.     public abstract function testStarted($testName);
  262.  
  263.     // }}}
  264.     // {{{ public abstract function testEnded($testName)
  265.  
  266.     /**
  267.     * A test ended.
  268.     *
  269.     * @param  string  $testName 
  270.     * @access public
  271.     * @abstract
  272.     */
  273.     public abstract function testEnded($testName);
  274.  
  275.     // }}}
  276.     // {{{ public abstract function testFailed($status, PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
  277.  
  278.     /**
  279.     * A test failed.
  280.     *
  281.     * @param  integer                                 $status 
  282.     * @param  PHPUnit2_Framework_Test                 $test 
  283.     * @param  PHPUnit2_Framework_AssertionFailedError $e 
  284.     * @access public
  285.     * @abstract
  286.     */
  287.     public abstract function testFailed($statusPHPUnit2_Framework_Test $testPHPUnit2_Framework_AssertionFailedError $e);
  288.  
  289.     // }}}
  290. }
  291.  
  292. /*
  293.  * vim600:  et sw=2 ts=2 fdm=marker
  294.  * vim<600: et sw=2 ts=2
  295.  */
  296. ?>

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