1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4/**
5 * PHP Version 4
6 *
7 * Copyright (c) 2002-2005, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 *   * Redistributions of source code must retain the above copyright
15 *     notice, this list of conditions and the following disclaimer.
16 *
17 *   * Redistributions in binary form must reproduce the above copyright
18 *     notice, this list of conditions and the following disclaimer in
19 *     the documentation and/or other materials provided with the
20 *     distribution.
21 *
22 *   * Neither the name of Sebastian Bergmann nor the names of his
23 *     contributors may be used to endorse or promote products derived
24 *     from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 *
39 * @category   Testing
40 * @package    PHPUnit
41 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
42 * @copyright  2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
43 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
44 * @version    CVS: $Id: TestDecorator.php,v 1.17 2005/11/10 09:47:14 sebastian Exp $
45 * @link       http://pear.php.net/package/PHPUnit
46 * @since      File available since Release 1.0.0
47 */
48
49require_once 'PHPUnit/TestCase.php';
50require_once 'PHPUnit/TestSuite.php';
51
52if (!function_exists('is_a')) {
53    require_once 'PHP/Compat/Function/is_a.php';
54}
55
56/**
57 * A Decorator for Tests.
58 *
59 * Use TestDecorator as the base class for defining new
60 * test decorators. Test decorator subclasses can be introduced
61 * to add behaviour before or after a test is run.
62 *
63 * @category   Testing
64 * @package    PHPUnit
65 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
66 * @copyright  2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
67 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
68 * @version    Release: 1.3.2
69 * @link       http://pear.php.net/package/PHPUnit
70 * @since      Class available since Release 1.0.0
71 */
72class PHPUnit_TestDecorator {
73    /**
74     * The Test to be decorated.
75     *
76     * @var    object
77     * @access protected
78     */
79    var $_test = NULL;
80
81    /**
82     * Constructor.
83     *
84     * @param  object
85     * @access public
86     */
87    function PHPUnit_TestDecorator(&$test) {
88        if (is_object($test) &&
89            (is_a($test, 'PHPUnit_TestCase') ||
90             is_a($test, 'PHPUnit_TestSuite'))) {
91
92            $this->_test = &$test;
93        }
94    }
95
96    /**
97     * Runs the test and collects the
98     * result in a TestResult.
99     *
100     * @param  object
101     * @access public
102     */
103    function basicRun(&$result) {
104        $this->_test->run($result);
105    }
106
107    /**
108     * Counts the number of test cases that
109     * will be run by this test.
110     *
111     * @return integer
112     * @access public
113     */
114    function countTestCases() {
115        return $this->_test->countTestCases();
116    }
117
118    /**
119     * Returns the test to be run.
120     *
121     * @return object
122     * @access public
123     */
124    function &getTest() {
125        return $this->_test;
126    }
127
128    /**
129     * Runs the decorated test and collects the
130     * result in a TestResult.
131     *
132     * @param  object
133     * @access public
134     * @abstract
135     */
136    function run(&$result) { /* abstract */ }
137
138    /**
139     * Returns a string representation of the test.
140     *
141     * @return string
142     * @access public
143     */
144    function toString() {
145        return $this->_test->toString();
146    }
147}
148
149/*
150 * Local variables:
151 * tab-width: 4
152 * c-basic-offset: 4
153 * c-hanging-comment-ender-p: nil
154 * End:
155 */
156?>
157