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

Source for file TestDecorator.php

Documentation is available at TestDecorator.php

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: PHPUnit2                                                       |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 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: TestDecorator.php,v 1.4 2004/05/26 06:24:04 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit2/Framework/Assert.php';
  19. require_once 'PHPUnit2/Framework/Test.php';
  20. require_once 'PHPUnit2/Framework/TestResult.php';
  21.  
  22. /**
  23.  * A Decorator for Tests.
  24.  *
  25.  * Use TestDecorator as the base class for defining new
  26.  * test decorators. Test decorator subclasses can be introduced
  27.  * to add behaviour before or after a test is run.
  28.  *
  29.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  30.  * @copyright   Copyright &copy; 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>
  31.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  32.  * @category    PHP
  33.  * @package     PHPUnit2
  34.  * @subpackage  Extensions
  35.  */
  36.     // {{{ Members
  37.  
  38.     /**
  39.     * The Test to be decorated.
  40.     *
  41.     * @var    object 
  42.     * @access protected
  43.     */
  44.     protected $test = null;
  45.  
  46.     // }}}
  47.     // {{{ public function __construct(PHPUnit2_Framework_Test $test)
  48.  
  49.     /**
  50.     * Constructor.
  51.     *
  52.     * @param  PHPUnit2_Framework_Test $test 
  53.     * @access public
  54.     */
  55.     public function __construct(PHPUnit2_Framework_Test $test{
  56.         $this->test = $test;
  57.     }
  58.  
  59.     // }}}
  60.     // {{{ public function toString()
  61.  
  62.     /**
  63.     * Returns a string representation of the test.
  64.     *
  65.     * @return string 
  66.     * @access public
  67.     */
  68.     public function toString({
  69.         return $this->test->toString();
  70.     }
  71.  
  72.     // }}}
  73.     // {{{ public function basicRun(PHPUnit2_Framework_TestResult $result)
  74.  
  75.     /**
  76.     * Runs the test and collects the
  77.     * result in a TestResult.
  78.     *
  79.     * @param  PHPUnit2_Framework_TestResult $result 
  80.     * @access public
  81.     */
  82.     public function basicRun(PHPUnit2_Framework_TestResult $result{
  83.         $this->test->run($result);
  84.     }
  85.  
  86.     // }}}
  87.     // {{{ public function countTestCases()
  88.  
  89.     /**
  90.     * Counts the number of test cases that
  91.     * will be run by this test.
  92.     *
  93.     * @return integer 
  94.     * @access public
  95.     */
  96.     public function countTestCases({
  97.         return $this->test->countTestCases();
  98.     }
  99.  
  100.     // }}}
  101.     // {{{ protected function createResult()
  102.  
  103.     /**
  104.     * Creates a default TestResult object.
  105.     *
  106.     * @return PHPUnit2_Framework_TestResult 
  107.     * @access protected
  108.     */
  109.     protected function createResult({
  110.         return new PHPUnit2_Framework_TestResult;
  111.     }
  112.  
  113.     // }}}
  114.     // {{{ public function getTest()
  115.  
  116.     /**
  117.     * Returns the test to be run.
  118.     *
  119.     * @return PHPUnit2_Framework_Test 
  120.     * @access public
  121.     */
  122.     public function getTest({
  123.         return $this->test;
  124.     }
  125.  
  126.     // }}}
  127.     // {{{ public function run($result = null)
  128.  
  129.     /**
  130.     * Runs the decorated test and collects the
  131.     * result in a TestResult.
  132.     *
  133.     * @param  PHPUnit2_Framework_TestResult $result 
  134.     * @return PHPUnit2_Framework_TestResult 
  135.     * @access public
  136.     */
  137.     public function run($result = null{
  138.         if ($result === null{
  139.             $result $this->createResult();
  140.         }
  141.  
  142.         // XXX: Workaround for missing optional class type hints.
  143.         else if (!($result instanceof PHPUnit2_Framework_TestResult)) {
  144.             throw new Exception(
  145.               'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.'
  146.             );
  147.         }
  148.  
  149.         $this->basicRun($result);
  150.  
  151.         return $result;
  152.     }
  153.  
  154.     // }}}
  155. }
  156.  
  157. /*
  158.  * vim600:  et sw=2 ts=2 fdm=marker
  159.  * vim<600: et sw=2 ts=2
  160.  */
  161. ?>

Documentation generated on Mon, 11 Mar 2019 13:55:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.