diff --git a/src/TUnit/framework/constraints/Constraint.php b/src/TUnit/framework/constraints/Constraint.php index 9d8da08..b727e4a 100644 --- a/src/TUnit/framework/constraints/Constraint.php +++ b/src/TUnit/framework/constraints/Constraint.php @@ -1,19 +1,75 @@ toString($message)); } + /** + * Gets a string representation of the constraint + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses getFailureMessage() + * + * @param string $message + * @return string + */ public function toString($message) { $message = !empty($message) ? $message . "\n" : ''; $message .= 'Failed asserting that ' . $this->getFailureMessage(); return $message; } + /** + * Evaluates the constraint + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return bool + */ public abstract function evaluate(); + /** + * Gets the failure message + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ protected abstract function getFailureMessage(); } diff --git a/src/TUnit/framework/constraints/DefaultConstraint.php b/src/TUnit/framework/constraints/DefaultConstraint.php index 795c519..1455e95 100644 --- a/src/TUnit/framework/constraints/DefaultConstraint.php +++ b/src/TUnit/framework/constraints/DefaultConstraint.php @@ -1,10 +1,48 @@ expected = $expected; $this->actual = $actual; diff --git a/src/TUnit/framework/constraints/EqualConstraint.php b/src/TUnit/framework/constraints/EqualConstraint.php index 46b6139..5e37e01 100644 --- a/src/TUnit/framework/constraints/EqualConstraint.php +++ b/src/TUnit/framework/constraints/EqualConstraint.php @@ -1,11 +1,46 @@ expected == $this->actual; } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ protected function getFailureMessage() { return Util::export($this->actual) . ' is equal to ' . Util::export($this->expected); } diff --git a/src/TUnit/framework/constraints/IdenticalConstraint.php b/src/TUnit/framework/constraints/IdenticalConstraint.php index 396e21d..f55f28d 100644 --- a/src/TUnit/framework/constraints/IdenticalConstraint.php +++ b/src/TUnit/framework/constraints/IdenticalConstraint.php @@ -1,11 +1,46 @@ expected === $this->actual; } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ protected function getFailureMessage() { return Util::export($this->actual) . ' is identical to ' . Util::export($this->expected); } diff --git a/src/TUnit/framework/constraints/NotConstraint.php b/src/TUnit/framework/constraints/NotConstraint.php index 6f6d870..0c9c77d 100644 --- a/src/TUnit/framework/constraints/NotConstraint.php +++ b/src/TUnit/framework/constraints/NotConstraint.php @@ -1,29 +1,110 @@ constraint = $constraint; } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param string $message + * @throws {@link FailedTest} + */ public function fail($message = '') { throw new FailedTest($this->toString($message)); } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return bool + */ public function evaluate() { return !$this->constraint->evaluate(); } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * @uses negateString() + * @uses Constraint::toString() + * + * @param string $message + * @return string + */ public function toString($message) { return $this->negateString($this->constraint->toString($message)); } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @throws BadMethodCallException + */ protected function getFailureMessage() { throw new BadMethodCallException(); } + /** + * Negates a string + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @param string $string + * @return string + */ protected function negateString($string) { return str_replace( array( diff --git a/src/TUnit/framework/constraints/SimpleConstraints.php b/src/TUnit/framework/constraints/SimpleConstraints.php index fcb6741..21688d3 100644 --- a/src/TUnit/framework/constraints/SimpleConstraints.php +++ b/src/TUnit/framework/constraints/SimpleConstraints.php @@ -1,69 +1,230 @@ value = $value; } } + /** + * Constraint for asserting that a value is set + * + * @package TUnit + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ class IssetConstraint extends SimpleConstraint { + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return bool + */ public function evaluate() { return isset($this->value); } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ protected function getFailureMessage() { return Util::export($this->value) . ' is set'; } } + /** + * Constraint for asserting that a value is empty + * + * @package TUnit + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ class EmptyConstraint extends SimpleConstraint { + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return bool + */ public function evaluate() { return empty($this->value); } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ protected function getFailureMessage() { return Util::export($this->value) . ' is empty'; } } + /** + * Constraint for asserting that a value is null + * + * @package TUnit + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ class NullConstraint extends SimpleConstraint { + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return bool + */ public function evaluate() { return $this->value === null; } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ protected function getFailureMessage() { return Util::export($this->value) . ' is null'; } } + /** + * Constraint for asserting that a value is true + * + * @package TUnit + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ class TrueConstraint extends SimpleConstraint { + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return bool + */ public function evaluate() { return $this->value === true; } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ protected function getFailureMessage() { return Util::export($this->value) . ' is true'; } } + /** + * Constraint for asserting that a value is true + * + * @package TUnit + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + */ class FalseConstraint extends SimpleConstraint { + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return bool + */ public function evaluate() { return $this->value === false; } + /** + * {@inheritdoc} + * + * @author Tommy Montgomery + * @version 1.0 + * @since 1.0 + * + * @return string + */ protected function getFailureMessage() { return Util::export($this->value) . ' is false'; }