diff --git a/Test/Unit/Visitor/Asserter.php b/Test/Unit/Visitor/Asserter.php new file mode 100644 index 0000000..3feed20 --- /dev/null +++ b/Test/Unit/Visitor/Asserter.php @@ -0,0 +1,85 @@ + + * @copyright Copyright © 2007-2015 Alexis von Glasow. + * @license New BSD License + */ + +class Asserter extends Test\Unit\Suite { + + public function case_keep_errors ( ) { + $this + ->given( + $ruler = new LUT(), + $fExecuted = false, + $asserter = $ruler->getDefaultAsserter(), + $asserter->setOperator( + 'f', + function ( $a = false ) use ( &$fExecuted ) { + + $fExecuted = true; + + return $a; + } + ), + $rule = 'f(false)' + ) + ->when($result = $ruler->assert($rule, new LUT\Context())) + ->then + ->boolean($result) + ->isFalse() + ->boolean($fExecuted) + ->isTrue() + ->boolean($asserter->hasError()) + ->isTrue() + ->array($asserter->getErrors()) + ->isNotEmpty() + ->hasKey('f') + ; + } +} + diff --git a/Visitor/Asserter.php b/Visitor/Asserter.php index 66991a1..3db8da8 100644 --- a/Visitor/Asserter.php +++ b/Visitor/Asserter.php @@ -67,6 +67,13 @@ class Asserter implements Visitor\Visit { */ protected $_operators = []; + /** + * List of errors. + * + * @var \Hoa\Ruler\Visitor\Asserter array + */ + protected $errors = []; + /** @@ -159,6 +166,10 @@ protected function visitOperator ( Ruler\Model\Operator $element, &$handle = nul $value = $argument->accept($this, $handle, $eldnah); $arguments[] = $value; + // Add operators name and their values in errors lists + if (false === $value) + $this->errors[$element->getName()] = $element->getArguments(); + if($element::LAZY_BREAK === $element->shouldBreakLazyEvaluation($value)) break; } @@ -487,4 +498,37 @@ public function getOperators ( ) { return $this->_operators; } + + /** + * Get all errors. + * + * @access public + * @return array + */ + public function getErrors ( ) { + + return $this->errors; + } + + /** + * The evaluation of operators has it raised errors. + * + * @access public + * @return boolean + */ + public function hasError ( ) { + + return !empty($this->errors); + } + + /** + * Reset all errors raised + * + * @access public + * @return void + */ + public function resetErrors ( ) { + + $this->errors = []; + } }