aboutsummaryrefslogtreecommitdiffstats
path: root/AssertionChecker
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-10 15:26:09 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-10 15:26:09 +0100
commit31d2496e677ef15956093e87b05ac3e9401ac716 (patch)
tree8b55495b743b5a921a47901987d6c529322c39e0 /AssertionChecker
parent131da654c830efc6d8ed96ad116ad878937bc77e (diff)
downloadPraspel-31d2496e677ef15956093e87b05ac3e9401ac716.zip
Praspel-31d2496e677ef15956093e87b05ac3e9401ac716.tar.gz
Praspel-31d2496e677ef15956093e87b05ac3e9401ac716.tar.bz2
Split into getAttributeData() & getArgumentData().
Diffstat (limited to 'AssertionChecker')
-rw-r--r--AssertionChecker/Runtime.php115
1 files changed, 84 insertions, 31 deletions
diff --git a/AssertionChecker/Runtime.php b/AssertionChecker/Runtime.php
index 348aafd..b28ae2a 100644
--- a/AssertionChecker/Runtime.php
+++ b/AssertionChecker/Runtime.php
@@ -148,41 +148,20 @@ class Runtime extends AssertionChecker {
'No data were given. The System Under Test %s needs data ' .
'to be executed.', 1, $callable);
- $arguments = array();
- $numberOfRequiredArguments = 0;
-
- foreach($reflection->getParameters() as $parameter) {
-
- $name = $parameter->getName();
-
- if(true === array_key_exists($name, $data)) {
-
- $arguments[$name] = &$data[$name];
-
- if(false === $parameter->isOptional())
- ++$numberOfRequiredArguments;
-
- continue;
- }
-
- if(false === $parameter->isOptional()) {
-
- ++$numberOfRequiredArguments;
-
- // Let the error be caught by a @requires clause.
- continue;
- }
-
- $arguments[$name] = $parameter->getDefaultValue();
- }
+ $arguments = $this->getArgumentData(
+ $reflection,
+ $data,
+ $numberOfRequiredArguments
+ );
// Check invariant.
if(true === $specification->clauseExists('invariant')) {
+ $attributes = $this->getAttributeData($callable);
$invariant = $specification->getClause('invariant');
$verdict &= $this->checkClause(
$invariant,
- $arguments,
+ $attributes,
$exceptions,
'Hoa\Praspel\Exception\Failure\Invariant',
true,
@@ -304,10 +283,11 @@ class Runtime extends AssertionChecker {
// Check invariant.
if(true === $specification->clauseExists('invariant')) {
+ $attributes = $this->getAttributeData($callable);
$invariant = $specification->getClause('invariant');
$verdict &= $this->checkClause(
$invariant,
- $arguments,
+ $attributes,
$exceptions,
'Hoa\Praspel\Exception\Failure\Invariant',
true,
@@ -322,6 +302,79 @@ class Runtime extends AssertionChecker {
}
/**
+ * Get argument data.
+ *
+ * @access protected
+ * @param \ReflectionFunctionAbstract $reflection Reflection.
+ * @param array &$data Data.
+ * @param int $numberOfRequiredArguments Number of
+ * required
+ * arguments.
+ * @return array
+ */
+ protected function getArgumentData ( \ReflectionFunctionAbstract $reflection,
+ Array &$data,
+ &$numberOfRequiredArguments ) {
+
+ $arguments = array();
+ $numberOfRequiredArguments = 0;
+
+ foreach($reflection->getParameters() as $parameter) {
+
+ $name = $parameter->getName();
+
+ if(true === array_key_exists($name, $data)) {
+
+ $arguments[$name] = &$data[$name];
+
+ if(false === $parameter->isOptional())
+ ++$numberOfRequiredArguments;
+
+ continue;
+ }
+
+ if(false === $parameter->isOptional()) {
+
+ ++$numberOfRequiredArguments;
+
+ // Let the error be caught by a @requires clause.
+ continue;
+ }
+
+ $arguments[$name] = $parameter->getDefaultValue();
+ }
+
+ return $arguments;
+ }
+
+ /**
+ * Get attribute data.
+ *
+ * @access protected
+ * @param \Hoa\Core\Consistency\Xcallable $callable Callable.
+ * @return array
+ */
+ protected function getAttributeData ( \Hoa\Core\Consistency\Xcallable $callable ) {
+
+ $callback = $callable->getValidCallback();
+ $object = $callback[0];
+
+ if(!is_object($object))
+ return array();
+
+ $reflectionObject = new \ReflectionObject($object);
+ $attributes = array();
+
+ foreach($reflectionObject->getProperties() as $property) {
+
+ $property->setAccessible(true);
+ $attributes[$property->getName()] = $property->getValue($object);
+ }
+
+ return $attributes;
+ }
+
+ /**
* Check behavior clauses.
*
* @access protected
@@ -462,7 +515,7 @@ class Runtime extends AssertionChecker {
if(false === array_key_exists($_name, $data)) {
$exceptions[] = new $exception(
- 'Variable %s is required and has no value.', 5, $name);
+ 'Variable %s is required and has no value.', 7, $name);
continue;
}
@@ -496,7 +549,7 @@ class Runtime extends AssertionChecker {
$exceptions[] = new $exception(
'Variable %s does not verify the constraint @%s %s.',
- 6,
+ 8,
array(
$name,
$clause->getName(),