Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * PHPUnit
4
 *
5
 * Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 *   * Redistributions of source code must retain the above copyright
13
 *     notice, this list of conditions and the following disclaimer.
14
 *
15
 *   * Redistributions in binary form must reproduce the above copyright
16
 *     notice, this list of conditions and the following disclaimer in
17
 *     the documentation and/or other materials provided with the
18
 *     distribution.
19
 *
20
 *   * Neither the name of Sebastian Bergmann nor the names of his
21
 *     contributors may be used to endorse or promote products derived
22
 *     from this software without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
 * POSSIBILITY OF SUCH DAMAGE.
36
 *
37
 * @category   Testing
38
 * @package    PHPUnit
39
 * @author     Mattis Stordalen Flister <mattis@xait.no>
40
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
41
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
42
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
43
 * @link       http://www.phpunit.de/
44
 * @since      File available since Release 3.3.0
45
 */
46
 
47
require_once 'PHPUnit/Extensions/Story/Scenario.php';
48
require_once 'PHPUnit/Framework.php';
49
require_once 'PHPUnit/Util/Filter.php';
50
 
51
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
52
 
53
/**
54
 * A story test case.
55
 *
56
 * @category   Testing
57
 * @package    PHPUnit
58
 * @author     Mattis Stordalen Flister <mattis@xait.no>
59
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
60
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
61
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
62
 * @version    Release: 3.4.15
63
 * @link       http://www.phpunit.de/
64
 * @since      Class available since Release 3.3.0
65
 */
66
abstract class PHPUnit_Extensions_Story_TestCase extends PHPUnit_Framework_TestCase
67
{
68
    /**
69
     * @var    PHPUnit_Extensions_Story_Scenario
70
     */
71
    protected $scenario;
72
 
73
    /**
74
     * @var    array
75
     */
76
    protected $world = array();
77
 
78
    /**
79
     * Constructs a test case with the given name.
80
     *
81
     * @param  string $name
82
     * @param  array  $data
83
     * @param  string $dataName
84
     */
85
    public function __construct($name = NULL, array $data = array(), $dataName = '')
86
    {
87
        parent::__construct($name, $data, $dataName);
88
        $this->scenario = new PHPUnit_Extensions_Story_Scenario($this);
89
    }
90
 
91
    /**
92
     * @method PHPUnit_Extensions_Story_Step and($contextOrOutcome)
93
     */
94
    public function __call($command, $arguments)
95
    {
96
        switch ($command) {
97
            case 'and': {
98
                return $this->scenario->_and($arguments);
99
            }
100
            break;
101
 
102
            default: {
103
                throw new BadMethodCallException(
104
                  "Method $command not defined."
105
                );
106
            }
107
        }
108
    }
109
 
110
    /**
111
     * Returns this test's scenario.
112
     *
113
     * @return PHPUnit_Extensions_Story_Scenario
114
     */
115
    public function getScenario()
116
    {
117
        return $this->scenario;
118
    }
119
 
120
    /**
121
     *
122
     *
123
     */
124
    protected function notImplemented($action)
125
    {
126
        if (strstr($action, ' ')) {
127
            $this->markTestIncomplete("step: $action not implemented.");
128
        }
129
 
130
        throw new BadMethodCallException("Method $action not defined.");
131
    }
132
 
133
    /**
134
     * Adds a "Given" step to the scenario.
135
     *
136
     * @param  array $arguments
137
     * @return PHPUnit_Extensions_Story_TestCase
138
     */
139
    protected function given($context)
140
    {
141
        return $this->scenario->given(func_get_args());
142
    }
143
 
144
    /**
145
     * Adds a "When" step to the scenario.
146
     *
147
     * @param  array $arguments
148
     * @return PHPUnit_Extensions_Story_TestCase
149
     */
150
    protected function when($event)
151
    {
152
        return $this->scenario->when(func_get_args());
153
    }
154
 
155
    /**
156
     * Adds a "Then" step to the scenario.
157
     *
158
     * @param  array $arguments
159
     * @return PHPUnit_Extensions_Story_TestCase
160
     */
161
    protected function then($outcome)
162
    {
163
        return $this->scenario->then(func_get_args());
164
    }
165
 
166
    /**
167
     * Add another step of the same type as the step that was added before.
168
     *
169
     * @param  array $arguments
170
     * @return PHPUnit_Extensions_Story_TestCase
171
     */
172
    protected function _and($contextOrOutcome)
173
    {
174
        return $this->scenario->_and(func_get_args());
175
    }
176
 
177
    /**
178
     * Run this test's scenario.
179
     *
180
     * @return mixed
181
     * @throws RuntimeException
182
     */
183
    protected function runTest()
184
    {
185
        $testResult = parent::runTest();
186
        $this->scenario->run($this->world);
187
        return $testResult;
188
    }
189
 
190
    /**
191
     * Implementation for "Given" steps.
192
     *
193
     * @param  array  $world
194
     * @param  string $action
195
     * @param  array  $arguments
196
     */
197
    abstract protected function runGiven(&$world, $action, $arguments);
198
 
199
    /**
200
     * Implementation for "When" steps.
201
     *
202
     * @param  array  $world
203
     * @param  string $action
204
     * @param  array  $arguments
205
     */
206
    abstract protected function runWhen(&$world, $action, $arguments);
207
 
208
    /**
209
     * Implementation for "Then" steps.
210
     *
211
     * @param  array  $world
212
     * @param  string $action
213
     * @param  array  $arguments
214
     */
215
    abstract protected function runThen(&$world, $action, $arguments);
216
}
217
?>