diff --git a/src/TUnit/framework/Assert.php b/src/TUnit/framework/Assert.php index 2d94d9f..632c55b 100644 --- a/src/TUnit/framework/Assert.php +++ b/src/TUnit/framework/Assert.php @@ -1,63 +1,233 @@ evaluate()) { $constraint->fail($message); } } + /** + * Negates a constraint + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param Constraint $constraint + * @return NotConstraint + */ protected static function negate(Constraint $constraint) { return new NotConstraint($constraint); } + /** + * Asserts that two values are equal + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + */ public static function equal($expected, $actual, $message = '') { self::evaluate(new EqualConstraint($expected, $actual), $message); } + /** + * Asserts that two values are not equal + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + */ public static function notEqual($expected, $actual, $message = '') { self::evaluate(self::negate(new EqualConstraint($expected, $actual)), $message); } + /** + * Asserts that two values are identical + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + */ public static function identical($expected, $actual, $message = '') { self::evaluate(new IdenticalConstraint($expected, $actual), $message); } + /** + * Asserts that two values are not identical + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + */ public static function notIdentical($expected, $actual, $message = '') { self::evaluate(self::negate(new IdenticalConstraint($expected, $actual)), $message); } + /** + * Asserts that a value is true + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $value + * @param string $message + */ public static function isTrue($value, $message = '') { self::evaluate(new TrueConstraint($value), $message); } + /** + * Asserts that a value is false + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $value + * @param string $message + */ public static function isFalse($value, $message = '') { self::evaluate(new FalseConstraint($value), $message); } + /** + * Asserts that a value is set + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $value + * @param string $message + */ public static function set($value, $message = '') { self::evaluate(new IssetConstraint($value), $message); } + /** + * Asserts that a value is not set + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $value + * @param string $message + */ public static function notSet($value, $message = '') { self::evaluate(self::negate(new IssetConstraint($value)), $message); } + /** + * Asserts that a value is empty + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $value + * @param string $message + */ public static function isEmpty($value, $message = '') { self::evaluate(new EmptyConstraint($value), $message); } + /** + * Asserts that a value is not empty + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $value + * @param string $message + */ public static function isNotEmpty($value, $message = '') { self::evaluate(self::negate(new EmptyConstraint($value)), $message); } + /** + * Asserts that a value is null + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $value + * @param string $message + */ public static function isNull($value, $message = '') { self::evaluate(new NullConstraint($value), $message); } + /** + * Asserts that a value is not null + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param mixed $value + * @param string $message + */ public static function isNotNull($value, $message = '') { self::evaluate(self::negate(new NullConstraint($value)), $message); } diff --git a/src/TUnit/framework/BaseTestRunner.php b/src/TUnit/framework/BaseTestRunner.php index ccf0a94..0113874 100644 --- a/src/TUnit/framework/BaseTestRunner.php +++ b/src/TUnit/framework/BaseTestRunner.php @@ -1,14 +1,68 @@ tests = $tests; $this->listeners = $listeners; @@ -18,45 +72,135 @@ $this->endTime = -1; } + /** + * Gets the start time + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return float + */ public final function getStartTime() { return $this->startTime; } + /** + * Gets the end time + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return float + */ public final function getEndTime() { return $this->endTime; } + /** + * Gets the tests + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return array + */ public final function getTests() { return $this->tests; } + /** + * Sends a warning out to all listeners + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses TestListener::onFrameworkWarning() + * + * @param string $message + */ public final function warn($message) { foreach ($this->listeners as $listener) { $listener->onFrameworkWarning($message); } } + /** + * Sends an error message out to all listeners + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses TestListener::onFrameworkError() + * + * @param string $message + */ public final function error($message) { foreach ($this->listeners as $listener) { $listener->onFrameworkError($message); } } + /** + * Adds a test + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param Testable $test + * @return TestRunner + */ public final function addTest(Testable $test) { $this->tests[] = $test; return $this; } + /** + * Adds a listener + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param TestListener $listener + * @return TestRunner + */ public final function addListener(TestListener $listener) { $this->listeners[] = $listener; return $this; } + /** + * Sets the options + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses parseOptions() + * + * @param array $options + * @return TestRunner + */ public final function setOptions(array $options) { $this->options = $this->parseOptions($options); return $this; } + /** + * Parses options + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses getAllowableOptions() + * + * @param array $unparsed The unparsed options + * @throws {@link InvalidOptionException} + * @return array The parsed options + */ protected final function parseOptions(array $unparsed) { $allowedOptions = $this->getAllowableOptions(); $options = array_fill_keys(array_key($allowedOptions), null); @@ -74,6 +218,18 @@ return $options; } + /** + * Runs the tests and returns the results + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses warn() + * @uses error() + * @uses Testable::run() + * + * @return array Array of {@link TestResult}s + */ public function runTests() { $results = array(); foreach ($this->tests as $test) { @@ -91,12 +247,32 @@ return $results; } + /** + * Publishes test results + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses TestListener::publishTestResults() + * + * @param array $testResults Array of {@link TestResult}s + */ public function publishResults(array $testResults) { foreach ($this->listeners as $listener) { $listener->publishTestResults($testResults); } } + /** + * Runs all tests and publishes the results + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses TestListener::beforeTestRunner() + * @uses publishResults() + * @uses TestListener::afterTestRunner() + */ public final function run() { foreach ($this->listeners as $listener) { $listener->beforeTestRunner($this); @@ -111,14 +287,43 @@ } } + /** + * Gets the number of tests + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return int + * @ignore + */ public function count() { return count($this->tests); } + /** + * Gets a detailed count of all tests + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses Util::countTests() + * + * @return array The result of Util::countTests() + */ public function getTestCount() { return Util::countTests($this->tests); } + /** + * Gets all allowable options for this test runner + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return array + */ protected abstract function getAllowableOptions(); } diff --git a/src/TUnit/framework/TestRunners.php b/src/TUnit/framework/TestRunners.php index 2a972ec..64e329e 100644 --- a/src/TUnit/framework/TestRunners.php +++ b/src/TUnit/framework/TestRunners.php @@ -1,7 +1,37 @@ 'boolean',