Permalink
Browse files

Last bunch of API and code standard commit

  • Loading branch information...
1 parent 9798326 commit c1759f31710c8b624e63e0a52d07c1dac908de36 @MarcelloDuarte MarcelloDuarte committed Apr 25, 2011
@@ -37,7 +37,7 @@
class Match implements Matcher
{
- /**
+ /**
* The expected value.
*
* @var unused
@@ -80,7 +80,9 @@ public function matches($actual)
*/
public function getFailureMessage()
{
- return 'expected match for ' . var_export($this->_expected, true) . ' PCRE regular expression, got ' . var_export($this->_actual, true) . ' (using match())';
+ return 'expected match for ' . var_export($this->_expected, true) .
+ ' PCRE regular expression, got ' .
+ var_export($this->_actual, true) . ' (using match())';
}
/**
@@ -90,7 +92,9 @@ public function getFailureMessage()
*/
public function getNegativeFailureMessage()
{
- return 'expected no match for ' . var_export($this->_expected, true) . ' PCRE regular expression, got ' . var_export($this->_actual, true) . ' (using match())';
+ return 'expected no match for ' . var_export($this->_expected, true) .
+ ' PCRE regular expression, got ' .
+ var_export($this->_actual, true) . ' (using match())';
}
/**
@@ -100,6 +104,7 @@ public function getNegativeFailureMessage()
*/
public function getDescription()
{
- return 'match ' . var_export($this->_expected, true) . ' PCRE regular expression';
+ return 'match ' . var_export($this->_expected, true) .
+ ' PCRE regular expression';
}
}
View
@@ -44,24 +44,30 @@ public function run($options)
// check for straight class to execute
if (isset($options->specFile)) {
- $pathToFile = getcwd();
- if (false !== strpos($options->specFile, '/')) {
- $pathToFile = str_replace("/" . basename($options->specFile), '', $options->specFile);
- $options->specFile = basename($options->specFile);
- }
- if (is_dir(realpath($pathToFile . "/$options->specFile"))) {
- $loader = new Runner\Loader\DirectoryRecursive;
- $runnable += $loader->load(realpath($pathToFile . "/$options->specFile"));
- } else {
- $loader = new Runner\Loader\Classname;
- $runnable += $loader->load($options->specFile, $pathToFile);
- }
+ $pathToFile = getcwd();
+ if (false !== strpos($options->specFile, '/')) {
+ $pathToFile = str_replace(
+ "/" . basename($options->specFile), '', $options->specFile
+ );
+ $options->specFile = basename($options->specFile);
+ }
+ if (is_dir(realpath($pathToFile . "/$options->specFile"))) {
+ $loader = new Runner\Loader\DirectoryRecursive;
+ $runnable += $loader->load(
+ realpath($pathToFile . "/$options->specFile")
+ );
+ } else {
+ $loader = new Runner\Loader\Classname;
+ $runnable += $loader->load($options->specFile, $pathToFile);
+ }
}
// should only recurse if not running a single spec
- if ((isset($options->r) || isset($options->recursive)) && !isset($options->specFile)) {
+ if ((isset($options->r) ||
+ isset($options->recursive)) &&
+ !isset($options->specFile)) {
$loader = new Runner\Loader\DirectoryRecursive;
- $runnable += $loader->load( getcwd() );
+ $runnable += $loader->load(getcwd());
}
if (isset($options->s) || isset($options->specdoc)) {
@@ -77,14 +83,15 @@ public function run($options)
$result->setRuntimeStart(microtime(true));
if (isset($options->reporter)) {
- $reporterClass = "\\PHPSpec\\Runner\\Reporter\\" . ucfirst($options->reporter);
+ $reporterClass = "\\PHPSpec\\Runner\\Reporter\\" .
+ ucfirst($options->reporter);
} else {
- $reporterClass = "\\PHPSpec\\Runner\\Reporter\\Text";
+ $reporterClass = "\\PHPSpec\\Runner\\Reporter\\Text";
}
$reporter = new $reporterClass($result);
if ($options->c || $options->color || $options->colour) {
- $reporter->showColors(true);
- }
+ $reporter->showColors(true);
+ }
$result->setReporter($reporter);
@@ -10,32 +10,60 @@
* http://www.gnu.org/licenses/lgpl-3.0.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
- * to license@phpspec.org so we can send you a copy immediately.
+ * to license@phpspec.net so we can send you a copy immediately.
*
- * @category PHPSpec
- * @package PHPSpec
- * @copyright Copyright (c) 2007 P�draic Brady, Travis Swicegood
- * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ * @category PHPSpec
+ * @package PHPSpec
+ * @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
+ * @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
+ * Marcello Duarte
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
namespace PHPSpec\Runner;
+
/**
* @category PHPSpec
* @package PHPSpec
- * @copyright Copyright (c) 2007 P�draic Brady, Travis Swicegood
+ * @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
+ * @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
+ * Marcello Duarte
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
class Base implements \Countable
{
+ /**
+ * Collection of examples to run
+ *
+ * @var \PHPSpec\Runner\Collection
+ */
protected $_collection = null;
+
+ /**
+ * @var \PHPSpec\Runner\Result
+ */
protected $_result = null;
+ /**
+ * Base Runner is constructed with a collection of examples
+ *
+ * @param \PHPSpec\Runner\Collection $collection
+ */
public function __construct(Collection $collection)
{
$this->_collection = $collection;
}
- public static function execute(Collection $collection, Result $result = null)
+ /**
+ * Executes all examples and sets the result in the result object in the
+ * runner if any is given
+ *
+ * @param Collection $collection
+ * @param Result $result
+ * @return \PHPSpec\Runner\Base
+ */
+ public static function execute(Collection $collection,
+ Result $result = null)
{
$exampleRunner = new self($collection);
if (!is_null($result)) {
@@ -45,30 +73,54 @@ public static function execute(Collection $collection, Result $result = null)
return $exampleRunner;
}
+ /**
+ * Executes all examples in the internal collection object
+ */
public function executeExamples()
{
$result = $this->getResult();
$this->_collection->execute($result);
}
+ /**
+ * Sets the result object
+ *
+ * @param \PHPSpec\Runner\Result $result
+ */
public function setResult(Result $result)
{
$this->_result = $result;
}
+ /**
+ * Returns the collection
+ *
+ * @return \PHPSpec\Runner\Collection
+ */
public function getCollection()
{
return $this->_collection;
}
+ /**
+ * Returns the result object
+ *
+ * @return \PHPSpec\Runner\Result
+ */
public function getResult()
{
if (is_null($this->_result)) {
- $this->setResult( new Result() );
+ $this->setResult(new Result());
}
return $this->_result;
}
+ /**
+ * Returns the number of collection in the runner
+ * @see Countable::count()
+ *
+ * @return integer
+ */
public function count()
{
return count($this->_collection);
@@ -10,29 +10,60 @@
* http://www.gnu.org/licenses/lgpl-3.0.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
- * to license@phpspec.org so we can send you a copy immediately.
+ * to license@phpspec.net so we can send you a copy immediately.
*
- * @category PHPSpec
- * @package PHPSpec
- * @copyright Copyright (c) 2007 P�draic Brady, Travis Swicegood
- * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ * @category PHPSpec
+ * @package PHPSpec
+ * @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
+ * @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
+ * Marcello Duarte
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
namespace PHPSpec\Runner;
/**
* @category PHPSpec
* @package PHPSpec
- * @copyright Copyright (c) 2007 P�draic Brady, Travis Swicegood
+ * @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
+ * @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
+ * Marcello Duarte
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
class Collection implements \Countable
{
+ /**
+ * Context of the examples
+ *
+ * @var \PHPSpec\Context
+ */
protected $_context = null;
+
+ /**
+ * Examples in the collection
+ *
+ * @var array
+ */
protected $_examples = array();
+
+ /**
+ * @var string
+ */
protected $_description = null;
+
+ /**
+ * The example class used for each example
+ *
+ * @var string
+ */
protected $_exampleClass = "\\PHPSpec\\Runner\\Example";
+ /**
+ * Constructs the collection with the context object
+ *
+ * @param \PHPSpec\Context $context
+ * @param string $exampleClass
+ */
public function __construct(\PHPSpec\Context $context, $exampleClass = null)
{
$this->_context = $context;
@@ -44,21 +75,42 @@ public function __construct(\PHPSpec\Context $context, $exampleClass = null)
$this->_description = $context->getDescription();
}
+ /**
+ * Returns the collection's examples
+ *
+ * @return array
+ */
public function getExamples()
{
return $this->_examples;
}
+ /**
+ * Returns the description
+ *
+ * @return strings
+ */
public function getDescription()
{
return $this->_description;
}
+ /**
+ * Returns the number of examples in the collection
+ * @see Countable::count()
+ *
+ * @return interger
+ */
public function count()
{
return count($this->_examples);
}
+ /**
+ * Executes the collection
+ *
+ * @param Result $result
+ */
public function execute(Result $result)
{
set_error_handler("PHPSpec_ErrorHandler");
@@ -99,24 +151,45 @@ public function execute(Result $result)
restore_error_handler();
}
+ /**
+ * Initiates the example structure by extracting the examples from the
+ * current context
+ */
protected function _buildExamples()
{
$methods = $this->_context->getSpecMethods();
foreach ($methods as $methodName) {
- $this->_addExample( new $this->_exampleClass($this->_context, $methodName) );
+ $this->_addExample(
+ new $this->_exampleClass($this->_context, $methodName)
+ );
}
}
+ /**
+ * Adds an example to the {@link self::$examples} property
+ *
+ * @param \PHPSpec\Runner\Example $example
+ */
protected function _addExample(Example $example)
{
$this->_examples[] = $example;
}
+ /**
+ * Validates that a given example class extends \PHPSpec\Runner\Example
+ *
+ * @param string $exampleClass
+ * @throws \PHPSpec\Exception
+ */
protected function _verifyExampleClass($exampleClass)
{
$class = new \ReflectionClass($exampleClass);
- if (!$class->isSubclassOf(new \ReflectionClass('\PHPSpec\Runner\Example'))) {
- throw new \PHPSpec\Exception('not a valid \PHPSpec\Runner\Example subclass');
+ if (!$class->isSubclassOf(
+ new \ReflectionClass('\PHPSpec\Runner\Example')
+ )) {
+ throw new \PHPSpec\Exception(
+ 'not a valid \PHPSpec\Runner\Example subclass'
+ );
}
}
}
Oops, something went wrong.

0 comments on commit c1759f3

Please sign in to comment.