package.xml0000644000175000017500000001063211631066263010773 0ustar sbsb PHPUnit_Story pear.phpunit.de Story extension for PHPUnit to facilitate Behaviour-Driven Development. Story extension for PHPUnit to facilitate Behaviour-Driven Development Sebastian Bergmann sb sb@sebastian-bergmann.de yes 2011-09-05 1.0.0 1.0.0 stable stable BSD License http://github.com/sebastianbergmann/phpunit-story/blob/master/ChangeLog.markdown 5.2.7 1.9.4 spl PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/ResultPrinter/Template/scenario_header.html.dist0000644000175000017500000000010711631066263030101 0ustar sbsb

{name}

PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/ResultPrinter/Template/scenario.html.dist0000644000175000017500000000043011631066263026570 0ustar sbsb

[+] {name}

{steps}
PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/ResultPrinter/Template/scenarios.html.dist0000644000175000017500000000344211631066263026761 0ustar sbsb {scenarios}

[+] Summary:

PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/ResultPrinter/Template/step.html.dist0000644000175000017500000000017311631066263025744 0ustar sbsb {text} {action}   PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/ResultPrinter/HTML.php0000644000175000017500000001421011631066263022640 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * Prints stories in HTML format. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ class PHPUnit_Extensions_Story_ResultPrinter_HTML extends PHPUnit_Extensions_Story_ResultPrinter { /** * @var boolean */ protected $printsHTML = TRUE; /** * @var integer */ protected $id = 0; /** * @var string */ protected $scenarios = ''; /** * @var string */ protected $templatePath; /** * Constructor. * * @param mixed $out * @throws InvalidArgumentException */ public function __construct($out = NULL) { parent::__construct($out); $this->templatePath = sprintf( '%s%sTemplate%s', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR ); } /** * Handler for 'start class' event. * * @param string $name */ protected function startClass($name) { $scenarioHeaderTemplate = new Text_Template( $this->templatePath . 'scenario_header.html' ); $scenarioHeaderTemplate->setVar( array( 'name' => $this->currentTestClassPrettified ) ); $this->scenarios .= $scenarioHeaderTemplate->render(); } /** * Handler for 'on test' event. * * @param string $name * @param boolean $success * @param array $steps */ protected function onTest($name, $success = TRUE, array $steps = array()) { if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) { $scenarioStatus = 'scenarioFailed'; } else if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) { $scenarioStatus = 'scenarioSkipped'; } else if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) { $scenarioStatus = 'scenarioIncomplete'; } else { $scenarioStatus = 'scenarioSuccess'; } $lastStepName = ''; $stepsBuffer = ''; foreach ($steps as $step) { $currentStepName = $step->getName(); if ($lastStepName == $currentStepName) { $stepText = 'and'; } else { $stepText = $currentStepName; } $lastStepName = $currentStepName; $stepTemplate = new Text_Template( $this->templatePath . 'step.html' ); $stepTemplate->setVar( array( 'text' => $stepText, 'action' => $step->getAction() . ' ' . $step->getArguments(TRUE), ) ); $stepsBuffer .= $stepTemplate->render(); } $scenarioTemplate = new Text_Template( $this->templatePath . 'scenario.html' ); $scenarioTemplate->setVar( array( 'id' => ++$this->id, 'name' => $name, 'scenarioStatus' => $scenarioStatus, 'steps' => $stepsBuffer, ) ); $this->scenarios .= $scenarioTemplate->render(); } /** * Handler for 'end run' event. * */ protected function endRun() { $scenariosTemplate = new Text_Template( $this->templatePath . 'scenarios.html' ); $scenariosTemplate->setVar( array( 'scenarios' => $this->scenarios, 'successfulScenarios' => $this->successful, 'failedScenarios' => $this->failed, 'skippedScenarios' => $this->skipped, 'incompleteScenarios' => $this->incomplete ) ); $this->write($scenariosTemplate->render()); } } PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/ResultPrinter/Text.php0000644000175000017500000001127111631066263023024 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * Prints stories in HTML format. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ class PHPUnit_Extensions_Story_ResultPrinter_Text extends PHPUnit_Extensions_Story_ResultPrinter { /** * Handler for 'start class' event. * * @param string $name */ protected function startClass($name) { $this->write($this->currentTestClassPrettified . "\n"); } /** * Handler for 'on test' event. * * @param string $name * @param boolean $success * @param array $steps */ protected function onTest($name, $success = TRUE, array $steps = array()) { if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) { $scenarioStatus = 'failed'; } else if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) { $scenarioStatus = 'skipped'; } else if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) { $scenarioStatus = 'incomplete'; } else { $scenarioStatus = 'successful'; } $this->write( sprintf( " [%s] %s\n\n", $scenarioStatus == 'successful' ? 'x' : ' ', $name ) ); $lastStepName = ''; $stepsBuffer = ''; foreach ($steps as $step) { $currentStepName = $step->getName(); if ($lastStepName == $currentStepName) { $stepText = 'and'; } else { $stepText = $currentStepName; } $lastStepName = $currentStepName; $this->write( sprintf( " %5s %s %s\n", $stepText, $step->getAction(), $step->getArguments(TRUE) ) ); } $this->write("\n"); } /** * Handler for 'end run' event. * */ protected function endRun() { $this->write( sprintf( "Scenarios: %d, Failed: %d, Skipped: %d, Incomplete: %d.\n", $this->successful + $this->failed + $this->skipped + $this->incomplete, $this->failed, $this->skipped, $this->incomplete ) ); } } PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/Autoload.php0000644000175000017500000000646211631066263021034 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Sebastian Bergmann * @copyright 2002-2010 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 1.0.0 */ function phpunit_story_autoload($class = NULL) { static $classes = NULL; static $path = NULL; if ($classes === NULL) { $classes = array( 'phpunit_extensions_story_given' => '/Extensions/Story/Given.php', 'phpunit_extensions_story_resultprinter' => '/Extensions/Story/ResultPrinter.php', 'phpunit_extensions_story_resultprinter_html' => '/Extensions/Story/ResultPrinter/HTML.php', 'phpunit_extensions_story_resultprinter_text' => '/Extensions/Story/ResultPrinter/Text.php', 'phpunit_extensions_story_scenario' => '/Extensions/Story/Scenario.php', 'phpunit_extensions_story_step' => '/Extensions/Story/Step.php', 'phpunit_extensions_story_testcase' => '/Extensions/Story/TestCase.php', 'phpunit_extensions_story_then' => '/Extensions/Story/Then.php', 'phpunit_extensions_story_when' => '/Extensions/Story/When.php' ); $path = dirname(dirname(dirname(__FILE__))); } if ($class === NULL) { $result = array(__FILE__); foreach ($classes as $file) { $result[] = $path . $file; } return $result; } $cn = strtolower($class); if (isset($classes[$cn])) { $file = $path . $classes[$cn]; require $file; } } spl_autoload_register('phpunit_story_autoload'); PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/Given.php0000644000175000017500000000530011631066263020322 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * A "Given" step. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ class PHPUnit_Extensions_Story_Given extends PHPUnit_Extensions_Story_Step { /** * Returns this step's name. * * @return string */ public function getName() { return 'Given'; } } PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/ResultPrinter.php0000644000175000017500000000704311631066263022102 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * Base for Story result printers. * * @package PHPUnit * @subpackage Extensions_Story * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ class PHPUnit_Extensions_Story_ResultPrinter extends PHPUnit_Util_TestDox_ResultPrinter { /** * A test ended. * * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest(PHPUnit_Framework_Test $test, $time) { if ($test instanceof PHPUnit_Extensions_Story_TestCase || $test instanceof PHPUnit_Extensions_Story_SeleniumTestCase) { if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) { $this->successful++; $success = TRUE; } else { $success = FALSE; } $this->onTest( $this->currentTestMethodPrettified, $success, $test->getScenario()->getSteps() ); } } /** */ protected function doEndClass() { $this->endClass($this->testClass); } /** * Handler for 'on test' event. * * @param string $name * @param boolean $success * @param array $steps */ protected function onTest($name, $success = TRUE, array $steps = array()) { } } PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/Scenario.php0000644000175000017500000001313011631066263021015 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * A scenario. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ class PHPUnit_Extensions_Story_Scenario { /** * @var PHPUnit_Extensions_Story_TestCase */ protected $test; /** * @var array */ protected $steps = array(); /** * @var string */ protected $lastCalledMethod; /** * Constructor. * * @param PHPUnit_Extensions_Story_TestCase $caller */ public function __construct($test) { if ($test instanceof PHPUnit_Extensions_Story_TestCase || $test instanceof PHPUnit_Extensions_Story_SeleniumTestCase) { $this->test = $test; } else { throw new Exception('$test must either be PHPUnit_Extensions_Story_TestCase or PHPUnit_Extensions_Story_SeleniumTestCase'); } } /** * Adds a "Given" step to the scenario. * * @param array $arguments * @return PHPUnit_Extensions_Story_TestCase */ public function given($arguments) { return $this->addStep(new PHPUnit_Extensions_Story_Given($arguments)); } /** * Adds a "When" step to the scenario. * * @param array $arguments * @return PHPUnit_Extensions_Story_TestCase */ public function when($arguments) { return $this->addStep(new PHPUnit_Extensions_Story_When($arguments)); } /** * Adds a "Then" step to the scenario. * * @param array $arguments * @return PHPUnit_Extensions_Story_TestCase */ public function then($arguments) { return $this->addStep(new PHPUnit_Extensions_Story_Then($arguments)); } /** * Add another step of the same type as the step that was added before. * * @param array $arguments * @return PHPUnit_Extensions_Story_TestCase */ public function _and($arguments) { $lastCalledStepClass = get_class($this->steps[count($this->steps)-1]); return $this->addStep(new $lastCalledStepClass($arguments)); } /** * Runs this scenario. * * @param array $world */ public function run(array &$world) { foreach ($this->steps as $step) { if ($step instanceof PHPUnit_Extensions_Story_Given) { $this->test->runGiven( $world, $step->getAction(), $step->getArguments() ); } else if ($step instanceof PHPUnit_Extensions_Story_When) { $this->test->runWhen( $world, $step->getAction(), $step->getArguments() ); } else { $this->test->runThen( $world, $step->getAction(), $step->getArguments() ); } } } /** * Adds a step to the scenario. * * @param PHPUnit_Extensions_Story_Step $step * @return PHPUnit_Extensions_Story_TestCase */ protected function addStep(PHPUnit_Extensions_Story_Step $step) { $this->steps[] = $step; return $this->test; } /** * Returns the steps of this scenario. * * @return array */ public function getSteps() { return $this->steps; } } PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/Step.php0000644000175000017500000000744111631066263020175 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * A step of a scenario. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ abstract class PHPUnit_Extensions_Story_Step { /** * @var string */ protected $action; /** * @var array */ protected $arguments; /** * Constructor. * * @param array $arguments */ public function __construct(array $arguments) { $this->action = array_shift($arguments); $this->arguments = $arguments; } /** * Returns this step's action. * * @return string */ public function getAction() { return $this->action; } /** * Returns this step's arguments. * * @param boolean $asString * @return array|string */ public function getArguments($asString = FALSE) { if (!$asString) { return $this->arguments; } else { switch (count($this->arguments)) { case 0: { return ''; } break; case 1: { return $this->arguments[0]; } break; default: { return var_export($this->arguments, TRUE); } } } } /** * Returns this step's name. * * @return string */ abstract public function getName(); } PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/TestCase.php0000644000175000017500000001372411631066263020776 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * A story test case. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ abstract class PHPUnit_Extensions_Story_TestCase extends PHPUnit_Framework_TestCase { /** * @var PHPUnit_Extensions_Story_Scenario */ protected $scenario; /** * @var array */ protected $world = array(); /** * Constructs a test case with the given name. * * @param string $name * @param array $data * @param string $dataName */ public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); $this->scenario = new PHPUnit_Extensions_Story_Scenario($this); } /** * @method PHPUnit_Extensions_Story_Step and($contextOrOutcome) */ public function __call($command, $arguments) { switch ($command) { case 'and': { return $this->scenario->_and($arguments); } break; default: { throw new BadMethodCallException( "Method $command not defined." ); } } } /** * Returns this test's scenario. * * @return PHPUnit_Extensions_Story_Scenario */ public function getScenario() { return $this->scenario; } /** * * */ protected function notImplemented($action) { if (strstr($action, ' ')) { $this->markTestIncomplete("step: $action not implemented."); } throw new BadMethodCallException("Method $action not defined."); } /** * Adds a "Given" step to the scenario. * * @param array $arguments * @return PHPUnit_Extensions_Story_TestCase */ protected function given($context) { return $this->scenario->given(func_get_args()); } /** * Adds a "When" step to the scenario. * * @param array $arguments * @return PHPUnit_Extensions_Story_TestCase */ protected function when($event) { return $this->scenario->when(func_get_args()); } /** * Adds a "Then" step to the scenario. * * @param array $arguments * @return PHPUnit_Extensions_Story_TestCase */ protected function then($outcome) { return $this->scenario->then(func_get_args()); } /** * Add another step of the same type as the step that was added before. * * @param array $arguments * @return PHPUnit_Extensions_Story_TestCase */ protected function _and($contextOrOutcome) { return $this->scenario->_and(func_get_args()); } /** * Run this test's scenario. * * @return mixed * @throws RuntimeException */ protected function runTest() { $testResult = parent::runTest(); $this->scenario->run($this->world); return $testResult; } /** * Implementation for "Given" steps. * * @param array $world * @param string $action * @param array $arguments */ abstract protected function runGiven(&$world, $action, $arguments); /** * Implementation for "When" steps. * * @param array $world * @param string $action * @param array $arguments */ abstract protected function runWhen(&$world, $action, $arguments); /** * Implementation for "Then" steps. * * @param array $world * @param string $action * @param array $arguments */ abstract protected function runThen(&$world, $action, $arguments); } PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/Then.php0000644000175000017500000000527511631066263020163 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * A "Then" step. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ class PHPUnit_Extensions_Story_Then extends PHPUnit_Extensions_Story_Step { /** * Returns this step's name. * * @return string */ public function getName() { return 'Then'; } } PHPUnit_Story-1.0.0/PHPUnit/Extensions/Story/When.php0000644000175000017500000000527511631066263020166 0ustar sbsb. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.3.0 */ /** * A "When" step. * * @package PHPUnit * @subpackage Extensions_Story * @author Mattis Stordalen Flister * @author Sebastian Bergmann * @copyright 2011-2011 Sebastian Bergmann * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.0 * @link http://www.phpunit.de/ * @since Class available since Release 3.3.0 */ class PHPUnit_Extensions_Story_When extends PHPUnit_Extensions_Story_Step { /** * Returns this step's name. * * @return string */ public function getName() { return 'When'; } } PHPUnit_Story-1.0.0/ChangeLog.markdown0000644000175000017500000000027611631066263015375 0ustar sbsbPHPUnit_Story 1.0 ================= This is the list of changes for the PHPUnit_Story 1.0 release series. PHPUnit_Story 1.0.0 ------------------- * Initial release as separate component. PHPUnit_Story-1.0.0/LICENSE0000644000175000017500000000301411631066263013000 0ustar sbsbPHPUnit_Story Copyright (c) 2002-2011, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package.sig0000644000175000017500000000030611631066271010751 0ustar sbsb-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEABECAAYFAk5kbLkACgkQaGfFFLhbXWl2CgCfSNWjMc+gI+G/0gtz5VTeNFDz UlcAn3q/13K21RZzgYztULpfMriunpM+ =hvpy -----END PGP SIGNATURE-----