5 * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
39 * @author Mattis Stordalen Flister <mattis@xait.no>
40 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
44 * @link http://www.phpunit.de/
45 * @since File available since Release 3.3.0
48 require_once 'PHPUnit/Extensions/Story/Scenario.php';
49 require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
50 require_once 'PHPUnit/Extensions/Story/TestCase.php';
57 * @author Mattis Stordalen Flister <mattis@xait.no>
58 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
59 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
60 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 * @version Release: 3.3.17
62 * @link http://www.phpunit.de/
63 * @since Class available since Release 3.3.0
66 abstract class PHPUnit_Extensions_Story_SeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
69 protected $world = array();
71 public function __construct($name = NULL, array $data = array(), $dataName = '', array $browser = array())
73 parent::__construct($name, $data, $dataName, $browser);
74 $this->scenario = new PHPUnit_Extensions_Story_Scenario($this);
78 * @method PHPUnit_Extensions_Story_Step and($contextOrOutcome)
80 public function __call($command, $arguments)
84 return $this->scenario->_and($arguments);
89 return parent::__call($command, $arguments);
95 * Returns this test's scenario.
97 * @return PHPUnit_Extensions_Story_Scenario
99 public function getScenario()
101 return $this->scenario;
105 * This method is used by __call
108 protected function notImplemented($action)
110 if (strstr($action, ' ')) {
111 $this->markTestIncomplete("step: $action not implemented.");
114 throw new BadMethodCallException("Method $action not defined.");
118 * Adds a "Given" step to the scenario.
120 * @param array $arguments
121 * @return PHPUnit_Extensions_Story_TestCase
123 protected function given($context)
125 return $this->scenario->given(func_get_args());
129 * Adds a "When" step to the scenario.
131 * @param array $arguments
132 * @return PHPUnit_Extensions_Story_TestCase
134 protected function when($event)
136 return $this->scenario->when(func_get_args());
140 * Adds a "Then" step to the scenario.
142 * @param array $arguments
143 * @return PHPUnit_Extensions_Story_TestCase
145 protected function then($outcome)
147 return $this->scenario->then(func_get_args());
151 * Add another step of the same type as the step that was added before.
153 * @param array $arguments
154 * @return PHPUnit_Extensions_Story_TestCase
156 protected function _and($contextOrOutcome)
158 return $this->scenario->_and(func_get_args());
162 * Run this test's scenario.
164 * @throws RuntimeException
166 protected function runTest()
168 $autostop = $this->autoStop;
169 $this->autoStop = FALSE;
173 $this->scenario->run($this->world);
174 $this->autoStop = $autostop;
177 catch (Exception $e) {
178 $this->autoStop = $autostop;
184 * Implementation for "Given" steps.
186 * @param array $world
187 * @param string $action
188 * @param array $arguments
190 abstract protected function runGiven(&$world, $action, $arguments);
193 * Implementation for "When" steps.
195 * @param array $world
196 * @param string $action
197 * @param array $arguments
199 abstract protected function runWhen(&$world, $action, $arguments);
202 * Implementation for "Then" steps.
204 * @param array $world
205 * @param string $action
206 * @param array $arguments
208 abstract protected function runThen(&$world, $action, $arguments);