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/Framework.php';
50 require_once 'PHPUnit/Util/Filter.php';
52 PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
59 * @author Mattis Stordalen Flister <mattis@xait.no>
60 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
61 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
62 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
63 * @version Release: 3.3.17
64 * @link http://www.phpunit.de/
65 * @since Class available since Release 3.3.0
68 abstract class PHPUnit_Extensions_Story_TestCase extends PHPUnit_Framework_TestCase
71 * @var PHPUnit_Extensions_Story_Scenario
78 protected $world = array();
81 * Constructs a test case with the given name.
85 * @param string $dataName
87 public function __construct($name = NULL, array $data = array(), $dataName = '')
89 parent::__construct($name, $data, $dataName);
90 $this->scenario = new PHPUnit_Extensions_Story_Scenario($this);
94 * @method PHPUnit_Extensions_Story_Step and($contextOrOutcome)
96 public function __call($command, $arguments)
100 return $this->scenario->_and($arguments);
105 throw new BadMethodCallException(
106 "Method $command not defined."
113 * Returns this test's scenario.
115 * @return PHPUnit_Extensions_Story_Scenario
117 public function getScenario()
119 return $this->scenario;
126 protected function notImplemented($action)
128 if (strstr($action, ' ')) {
129 $this->markTestIncomplete("step: $action not implemented.");
132 throw new BadMethodCallException("Method $action not defined.");
136 * Adds a "Given" step to the scenario.
138 * @param array $arguments
139 * @return PHPUnit_Extensions_Story_TestCase
141 protected function given($context)
143 return $this->scenario->given(func_get_args());
147 * Adds a "When" step to the scenario.
149 * @param array $arguments
150 * @return PHPUnit_Extensions_Story_TestCase
152 protected function when($event)
154 return $this->scenario->when(func_get_args());
158 * Adds a "Then" step to the scenario.
160 * @param array $arguments
161 * @return PHPUnit_Extensions_Story_TestCase
163 protected function then($outcome)
165 return $this->scenario->then(func_get_args());
169 * Add another step of the same type as the step that was added before.
171 * @param array $arguments
172 * @return PHPUnit_Extensions_Story_TestCase
174 protected function _and($contextOrOutcome)
176 return $this->scenario->_and(func_get_args());
180 * Run this test's scenario.
182 * @throws RuntimeException
184 protected function runTest()
187 $this->scenario->run($this->world);
191 * Implementation for "Given" steps.
193 * @param array $world
194 * @param string $action
195 * @param array $arguments
197 abstract protected function runGiven(&$world, $action, $arguments);
200 * Implementation for "When" steps.
202 * @param array $world
203 * @param string $action
204 * @param array $arguments
206 abstract protected function runWhen(&$world, $action, $arguments);
209 * Implementation for "Then" steps.
211 * @param array $world
212 * @param string $action
213 * @param array $arguments
215 abstract protected function runThen(&$world, $action, $arguments);