aboutsummaryrefslogtreecommitdiffstats
path: root/AssertionChecker
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-22 12:04:09 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-11-22 12:04:09 +0100
commitf82db700c76d47bd3e8582e1f74f8ebbc5d0cb60 (patch)
treea24ab0f829adeba7a93523556b7538121085a0f6 /AssertionChecker
parent6382c6b467614a2caa4a695f51d0b2bb659e5c95 (diff)
downloadPraspel-f82db700c76d47bd3e8582e1f74f8ebbc5d0cb60.zip
Praspel-f82db700c76d47bd3e8582e1f74f8ebbc5d0cb60.tar.gz
Praspel-f82db700c76d47bd3e8582e1f74f8ebbc5d0cb60.tar.bz2
Better constructor support.
When the callable is a constructor, we need a special process, based on `ReflectionClass::newInstanceArgs`.
Diffstat (limited to 'AssertionChecker')
-rw-r--r--AssertionChecker/Runtime.php55
1 files changed, 43 insertions, 12 deletions
diff --git a/AssertionChecker/Runtime.php b/AssertionChecker/Runtime.php
index 0dc12a7..99dd467 100644
--- a/AssertionChecker/Runtime.php
+++ b/AssertionChecker/Runtime.php
@@ -123,11 +123,15 @@ class Runtime extends AssertionChecker {
'The Runtime Assertion Checker has detected failures for %s.',
0, $callable
);
+ $isConstructor = false;
if($reflection instanceof \ReflectionMethod) {
$reflection->setAccessible(true);
+ if('__construct' === $reflection->getName())
+ $isConstructor = true;
+
if(false === $reflection->isStatic()) {
$_callback = $callable->getValidCallback();
@@ -155,9 +159,8 @@ class Runtime extends AssertionChecker {
);
// Check invariant.
- if( true === $specification->clauseExists('invariant')
- && !( $reflection instanceof \ReflectionMethod
- && '__construct' === $reflection->getName())) {
+ if( true === $specification->clauseExists('invariant')
+ && false === $isConstructor) {
$attributes = $this->getAttributeData($callable);
$invariant = $specification->getClause('invariant');
@@ -202,15 +205,11 @@ class Runtime extends AssertionChecker {
try {
// Invoke.
- if($reflection instanceof \ReflectionFunction)
- $return = $reflection->invokeArgs($arguments);
- else {
-
- $_callback = $callable->getValidCallback();
- $_object = $_callback[0];
- $return = $reflection->invokeArgs($_object, $arguments);
- }
-
+ $return = $this->invoke(
+ $reflection,
+ $arguments,
+ $isConstructor
+ );
$arguments['\result'] = $return;
$_exceptions = null;
@@ -377,6 +376,38 @@ class Runtime extends AssertionChecker {
}
/**
+ * Invoke.
+ *
+ * @acccess protected
+ * @param \ReflectionFunctionAbstract $reflection Reflection.
+ * @param array &$arguments Arguments.
+ * @param bool $isConstructor Whether it is a
+ * constructor.
+ * @return mixed
+ * @throw \Exception
+ */
+ protected function invoke ( \ReflectionFunctionAbstract $reflection,
+ Array &$arguments,
+ $isConstructor ) {
+
+ if($reflection instanceof \ReflectionFunction)
+ return $reflection->invokeArgs($arguments);
+
+ if(false === $isConstructor) {
+
+ $_callback = $callable->getValidCallback();
+ $_object = $_callback[0];
+
+ return $reflection->invokeArgs($_object, $arguments);
+ }
+
+ $class = $reflection->getDeclaringClass();
+ $class->newInstanceArgs($arguments);
+
+ return void;
+ }
+
+ /**
* Check behavior clauses.
*
* @access protected