diff --git a/src/TUnit/util/Autoloader.php b/src/TUnit/util/Autoloader.php index a848118..3ca734e 100644 --- a/src/TUnit/util/Autoloader.php +++ b/src/TUnit/util/Autoloader.php @@ -3,19 +3,17 @@ /** * Autoloader * - * @package Library - * @subpackage Utilities - * @version 1.0 - * @since 1.0 + * @package TUnit + * @version 1.0 + * @since 1.0 */ /** * Bootstraps each NowhereConcave package via autoload * - * @package Library - * @subpackage Utilities - * @version 1.0 - * @since 1.0 + * @package TUnit + * @version 1.0 + * @since 1.0 */ final class Autoloader { diff --git a/src/TUnit/util/PhpFileIterator.php b/src/TUnit/util/PhpFileIterator.php index f777400..d9a7b4a 100644 --- a/src/TUnit/util/PhpFileIterator.php +++ b/src/TUnit/util/PhpFileIterator.php @@ -1,11 +1,46 @@ getInnerIterator()->isDot() && @@ -15,12 +50,38 @@ } + /** + * Iterates over PHP files + * + * @package TUnit + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ class PhpFileIterator extends FilterIterator { + /** + * Constructor + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param string $dir + */ public function __construct($dir) { parent::__construct(new DirectoryIterator($dir)); } + /** + * Defines acceptance criteria for iteration + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return bool + */ public function accept() { return !$this->getInnerIterator()->isDot() && diff --git a/src/TUnit/util/RecursiveTestIterator.php b/src/TUnit/util/RecursiveTestIterator.php index 5d5cce6..26a3814 100644 --- a/src/TUnit/util/RecursiveTestIterator.php +++ b/src/TUnit/util/RecursiveTestIterator.php @@ -1,11 +1,46 @@ current()->getTestResults()); } + /** + * Gets whether the current iterator has any children + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return mixed + */ public function hasChildren() { return $this->current() instanceof CombinedTestResult; } diff --git a/src/TUnit/util/TestAccumulator.php b/src/TUnit/util/TestAccumulator.php index fc478f5..2d91e93 100644 --- a/src/TUnit/util/TestAccumulator.php +++ b/src/TUnit/util/TestAccumulator.php @@ -1,7 +1,37 @@ getParameters() as $i => $param) { @@ -56,6 +101,17 @@ return rtrim($paramList, ', '); } + /** + * Repairs a parameter name from ReflectionParameter->getName() + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param string $name + * @param int $position + * @return string + */ private static function repairParameterName($name, $position) { if (empty($name)) { $name = 'param' . $position; @@ -64,6 +120,17 @@ return $name; } + /** + * Builds a parameter list suitable for eval() + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses repairParameterName() + * + * @param ReflectionMethod $method + * @return string + */ public static function buildParameterNameList(ReflectionMethod $method) { $list = ''; foreach ($method->getParameters() as $param) { @@ -73,6 +140,16 @@ return rtrim($list, ', '); } + /** + * Flattens a multi-dimensional array into one dimension + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $arr + * @return array + */ public static function arrayFlatten($arr) { $flattened = array(); if (is_array($arr)) { @@ -86,6 +163,17 @@ return $flattened; } + /** + * DGets the number of all test suites, cases and methods + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses mergeTestCount() + * + * @param array $tests + * @return array An array with keys "suite", "case" and "method" + */ public static function countTests(array $tests) { $counts = array( 'suite' => 0, @@ -108,6 +196,17 @@ return $counts; } + /** + * Used by countTests() + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param array $arr1 + * @param array $arr2 + * @return array + */ private static function mergeTestCount(array $arr1, array $arr2) { $arr1['suite'] += $arr2['suite']; $arr1['case'] += $arr2['case']; @@ -115,6 +214,19 @@ return $arr1; } + /** + * Gets a method closure + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @link http://php.net/manual/en/language.oop5.reflection.php#90964 + * + * @param object $object + * @param string $method + * @throws InvalidArgumentException + * @return lambda + */ public static function getClosure($object, $method) { if (!is_object($object)) { throw new InvalidArgumentException('1st argument must be an object'); diff --git a/src/TUnit/util/cli.php b/src/TUnit/util/cli.php index 73c9292..866f026 100644 --- a/src/TUnit/util/cli.php +++ b/src/TUnit/util/cli.php @@ -1,7 +1,31 @@ longName = $longName; - $this->shortName = $shortName; - $this->required = $required; - $this->value = $value; + $this->longName = $longName; + $this->shortName = $shortName; + $this->required = $required; + $this->value = $value; $this->description = $description; } } + /** + * Represents a collection of {@link CliSwitch}es + * + * @package TUnit + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ class CliSwitchCollection implements IteratorAggregate { + /** + * @var array + */ private $switches; + + /** + * @var CliSwitch + */ private $switchArg; + /** + * Constructor + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ public function __construct() { - $this->switches = array(); + $this->switches = array(); $this->switchArg = null; } + /** + * Adds a switch to the collection + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param CliSwitch $switch + * @return CliSwitchCollection + */ public function addSwitch(CliSwitch $switch) { if ($switch->longName === null) { $this->switchArg = $switch; @@ -79,6 +178,16 @@ return $this; } + /** + * Gets a switch by its short or long name + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param string $longOrShortName + * @return CliSwitch|null + */ public function getSwitch($longOrShortName) { foreach ($this->switches as $switch) { if ($switch->longName == $longOrShortName || $switch->shortName == $longOrShortName) { @@ -89,6 +198,15 @@ return null; } + /** + * Segregates the switches into required and optional + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return array Array with keys "required" and "optional" + */ public function segregateSwitches() { $switches = array( 'required' => array(), @@ -105,27 +223,102 @@ return $switches; } + /** + * Gets the switch representing the arguments + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return CliSwitch + */ public function getSwitchArg() { return $this->switchArg; } + /** + * Gets an iterator + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return ArrayIterator + */ public function getIterator() { return new ArrayIterator($this->switches); } } + /** + * Helpful class for printing usage + * + * @package TUnit + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ class Usage { + /** + * @var array + */ private $switches; + + /** + * Name of the program + * + * @var string + */ private $name; + + /** + * Name of the script + * + * @var string + */ private $script; + + /** + * Description of the program + * + * @var string + */ private $description; + + /** + * Copyright information + * + * @var string + */ private $copyright; + + /** + * @var int + */ private $maxSwitchLength; + /** + * Max line length + * + * @var int + */ const LINE_LENGTH = 80; + /** + * Constructor + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param string $name + * @param string $script + * @param string $description + * @param string $author + * @param string $date + */ public function __construct($name, $script, $description, $author = null, $date = null) { $this->switches = array(array(), array()); $this->maxSwitchLength = 0; @@ -138,6 +331,18 @@ : (($author !== null) ? "by $author" : ''); } + /** + * Magic function __get + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $key + * @throws InvalidArgumentException + * @return mixed + * @ignore + */ public function __get($key) { if ($key === 'switches') { return $this->switches; @@ -146,6 +351,16 @@ throw new InvalidArgumentException('Invalid property'); } + /** + * Sets the switch collection + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses CliSwitchCollection::getIterator() + * + * @param CliSwitchCollection $switches + */ public function setSwitches(CliSwitchCollection $switches) { $this->switches = $switches; @@ -165,6 +380,16 @@ } } + /** + * Gets a string representation of this object + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses CliSwitchCollection::segregateSwitches() + * + * @return string + */ public function __toString() { $this->maxSwitchLength += 2; $usage = $this->name . "\n"; diff --git a/src/TUnit/util/entry_console.php b/src/TUnit/util/entry_console.php index c1dcfcb..ad22fb5 100644 --- a/src/TUnit/util/entry_console.php +++ b/src/TUnit/util/entry_console.php @@ -1,8 +1,31 @@