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/Extensions/SeleniumTestCase.php';
49
require_once 'PHPUnit/Extensions/Story/TestCase.php';
50
 
51
/**
52
 *
53
 *
54
 * @category   Testing
55
 * @package    PHPUnit
56
 * @author     Mattis Stordalen Flister <mattis@xait.no>
57
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
58
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
59
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
60
 * @version    Release: 3.4.15
61
 * @link       http://www.phpunit.de/
62
 * @since      Class available since Release 3.3.0
63
 */
64
abstract class PHPUnit_Extensions_Story_SeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
65
{
66
    protected $scenario;
67
    protected $world = array();
68
 
69
    public function __construct($name = NULL, array $data = array(), $dataName = '', array $browser = array())
70
    {
71
        parent::__construct($name, $data, $dataName, $browser);
72
        $this->scenario = new PHPUnit_Extensions_Story_Scenario($this);
73
    }
74
 
75
    /**
76
     * @method PHPUnit_Extensions_Story_Step and($contextOrOutcome)
77
     */
78
    public function __call($command, $arguments)
79
    {
80
        switch($command) {
81
            case 'and': {
82
                return $this->scenario->_and($arguments);
83
            }
84
            break;
85
 
86
            default: {
87
                return parent::__call($command, $arguments);
88
            }
89
        }
90
    }
91
 
92
    /**
93
     * Returns this test's scenario.
94
     *
95
     * @return PHPUnit_Extensions_Story_Scenario
96
     */
97
    public function getScenario()
98
    {
99
        return $this->scenario;
100
    }
101
 
102
    /**
103
     * This method is used by __call
104
     *
105
     */
106
    protected function notImplemented($action)
107
    {
108
        if (strstr($action, ' ')) {
109
            $this->markTestIncomplete("step: $action not implemented.");
110
        }
111
 
112
        throw new BadMethodCallException("Method $action not defined.");
113
    }
114
 
115
    /**
116
     * Adds a "Given" step to the scenario.
117
     *
118
     * @param  array $arguments
119
     * @return PHPUnit_Extensions_Story_TestCase
120
     */
121
    protected function given($context)
122
    {
123
        return $this->scenario->given(func_get_args());
124
    }
125
 
126
    /**
127
     * Adds a "When" step to the scenario.
128
     *
129
     * @param  array $arguments
130
     * @return PHPUnit_Extensions_Story_TestCase
131
     */
132
    protected function when($event)
133
    {
134
        return $this->scenario->when(func_get_args());
135
    }
136
 
137
    /**
138
     * Adds a "Then" step to the scenario.
139
     *
140
     * @param  array $arguments
141
     * @return PHPUnit_Extensions_Story_TestCase
142
     */
143
    protected function then($outcome)
144
    {
145
        return $this->scenario->then(func_get_args());
146
    }
147
 
148
    /**
149
     * Add another step of the same type as the step that was added before.
150
     *
151
     * @param  array $arguments
152
     * @return PHPUnit_Extensions_Story_TestCase
153
     */
154
    protected function _and($contextOrOutcome)
155
    {
156
        return $this->scenario->_and(func_get_args());
157
    }
158
 
159
    /**
160
     * Run this test's scenario.
161
     *
162
     * @return mixed
163
     * @throws RuntimeException
164
     */
165
    protected function runTest()
166
    {
167
        $autostop       = $this->autoStop;
168
        $this->autoStop = FALSE;
169
 
170
        try {
171
            $testResult = parent::runTest();
172
            $this->scenario->run($this->world);
173
            $this->autoStop = $autostop;
174
        }
175
 
176
        catch (Exception $e) {
177
            $this->autoStop = $autostop;
178
            throw $e;
179
        }
180
 
181
        return $testResult;
182
    }
183
 
184
    /**
185
     * Implementation for "Given" steps.
186
     *
187
     * @param  array  $world
188
     * @param  string $action
189
     * @param  array  $arguments
190
     */
191
    abstract protected function runGiven(&$world, $action, $arguments);
192
 
193
    /**
194
     * Implementation for "When" steps.
195
     *
196
     * @param  array  $world
197
     * @param  string $action
198
     * @param  array  $arguments
199
     */
200
    abstract protected function runWhen(&$world, $action, $arguments);
201
 
202
    /**
203
     * Implementation for "Then" steps.
204
     *
205
     * @param  array  $world
206
     * @param  string $action
207
     * @param  array  $arguments
208
     */
209
    abstract protected function runThen(&$world, $action, $arguments);
210
}