aboutsummaryrefslogtreecommitdiffstats
path: root/AssertionChecker
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2014-05-21 08:50:28 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2014-05-21 08:50:28 +0200
commitb5fcc37c476df179f020ea6686f7ecfe4d3dc739 (patch)
tree4d08aef8e5427e4542334fe8ad7baad2e8fb0cce /AssertionChecker
parentd4db95e53942b208235293fea6773e93947f725c (diff)
downloadPraspel-b5fcc37c476df179f020ea6686f7ecfe4d3dc739.zip
Praspel-b5fcc37c476df179f020ea6686f7ecfe4d3dc739.tar.gz
Praspel-b5fcc37c476df179f020ea6686f7ecfe4d3dc739.tar.bz2
Auto-collecting invariants.
Diffstat (limited to 'AssertionChecker')
-rw-r--r--AssertionChecker/Runtime.php54
1 files changed, 34 insertions, 20 deletions
diff --git a/AssertionChecker/Runtime.php b/AssertionChecker/Runtime.php
index abffc07..cd70227 100644
--- a/AssertionChecker/Runtime.php
+++ b/AssertionChecker/Runtime.php
@@ -115,6 +115,7 @@ class Runtime extends AssertionChecker {
public function evaluate ( &$trace = false ) {
// Start.
+ $registry = \Hoa\Praspel::getRegistry();
$verdict = true;
$callable = $this->getCallable();
$reflection = $callable->getReflection();
@@ -123,6 +124,7 @@ class Runtime extends AssertionChecker {
'The Runtime Assertion Checker has detected failures for %s.',
0, $callable
);
+ $classname = null;
$isConstructor = false;
if($reflection instanceof \ReflectionMethod) {
@@ -138,6 +140,8 @@ class Runtime extends AssertionChecker {
$_object = $_callback[0];
$specification->getImplicitVariable('this')->bindTo($_object);
}
+
+ $classname = $reflection->getDeclaringClass()->getName();
}
if(false !== $trace && !($trace instanceof Trace))
@@ -162,12 +166,26 @@ class Runtime extends AssertionChecker {
);
// Check invariant.
- if( true === $specification->clauseExists('invariant')
- && false === $isConstructor) {
+ $invariant = $specification->getClause('invariant');
+ $attributes = $this->getAttributeData($callable);
+
+ foreach($attributes as $name => $_) {
+
+ $entryName = $classname . '::$' . $name;
+
+ if(!isset($registry[$entryName]))
+ continue;
+
+ $entry = $registry[$entryName];
+
+ if(true === $entry->clauseExists('invariant'))
+ foreach($entry->getClause('invariant') as $variable)
+ $invariant->addVariable($variable->getName(), $variable);
+ }
+
+ if(false === $isConstructor) {
- $attributes = $this->getAttributeData($callable);
- $invariant = $specification->getClause('invariant');
- $verdict &= $this->checkClause(
+ $verdict &= $this->checkClause(
$invariant,
$attributes,
$exceptions,
@@ -296,22 +314,18 @@ class Runtime extends AssertionChecker {
throw $exceptions;
// Check invariant.
- if(true === $specification->clauseExists('invariant')) {
-
- $attributes = $this->getAttributeData($callable);
- $invariant = $specification->getClause('invariant');
- $verdict &= $this->checkClause(
- $invariant,
- $attributes,
- $exceptions,
- 'Hoa\Praspel\Exception\Failure\Invariant',
- true,
- $trace
- );
+ $attributes = $this->getAttributeData($callable);
+ $verdict &= $this->checkClause(
+ $invariant,
+ $attributes,
+ $exceptions,
+ 'Hoa\Praspel\Exception\Failure\Invariant',
+ true,
+ $trace
+ );
- if(0 < count($exceptions))
- throw $exceptions;
- }
+ if(0 < count($exceptions))
+ throw $exceptions;
return (bool) $verdict;
}