Skip to content
Browse files

Moved object related code to object interceptor

  • Loading branch information...
1 parent b4fbfe0 commit 78ed711ee10f05694d166ecdb6da3f549829d4c9 Amjad Mohamed committed Sep 3, 2012
Showing with 44 additions and 42 deletions.
  1. +0 −30 src/PHPSpec/Specification/Interceptor.php
  2. +44 −12 src/PHPSpec/Specification/Interceptor/Object.php
View
30 src/PHPSpec/Specification/Interceptor.php
@@ -162,10 +162,6 @@ public function __call($method, $args)
}
- if ($this->interceptedHasAMagicCall()) {
- return $this->invokeInterceptedMagicCall($method, $args);
- }
-
if ($this->callingExpectationsAsMethods($method)) {
$this->throwErrorExpectationsAreProperties();
}
@@ -328,32 +324,6 @@ protected function performMatchingWithUserDefinedMatcher($matcher,
}
/**
- * Checks if intercepted has a magic __call
- *
- * @return boolean
- */
- protected function interceptedHasAMagicCall()
- {
- return !$this->_actualValue instanceof ExampleGroup &&
- method_exists($this->_actualValue, '__call');
- }
-
- /**
- * Invokes intercepted magic call
- *
- * @param string $method
- * @param array $args
- * @return mixed
- */
- protected function invokeInterceptedMagicCall($method, $args)
- {
- $intercepted = new \ReflectionMethod($this->_actualValue, '__call');
- return InterceptorFactory::create($intercepted->invokeArgs(
- $this->_actualValue, array($method, $args)
- ));
- }
-
- /**
* Checks if intercepted is an object
*
* @return boolean
View
56 src/PHPSpec/Specification/Interceptor/Object.php
@@ -22,6 +22,7 @@
namespace PHPSpec\Specification\Interceptor;
use PHPSpec\Specification\Interceptor;
+use PHPSpec\Specification\Interceptor\InterceptorFactory;
use PHPSpec\Matcher\InvalidMatcher;
/**
@@ -53,17 +54,6 @@ class Object extends Interceptor
*/
public function __call($method, $args)
{
- $dslResult = parent::__call($method, $args);
- if (!is_null($dslResult)) {
- return $dslResult;
- }
-
- if ($this->isPredicate('have', $method, $args) ||
- $this->isPredicate('be', $method, $args)) {
- $this->performPredicateMatching();
- return true;
- }
-
$object = $this->getActualValue();
if (method_exists($object, $method)) {
return InterceptorFactory::create(
@@ -76,6 +66,21 @@ public function __call($method, $args)
return $this->accessProperty($args[0]);
}
+ $dslResult = parent::__call($method, $args);
+ if (!is_null($dslResult)) {
+ return $dslResult;
+ }
+
+ if ($this->interceptedHasAMagicCall()) {
+ return $this->invokeInterceptedMagicCall($method, $args);
+ }
+
+ if ($this->isPredicate('have', $method, $args) ||
+ $this->isPredicate('be', $method, $args)) {
+ $this->performPredicateMatching();
+ return true;
+ }
+
$class = get_class($object);
throw new InvalidMatcher(
"Call to undefined method {$class}::{$method}"
@@ -219,7 +224,7 @@ private function accessProperty($property)
if (array_key_exists($protected, $objectAsArray)) {
return InterceptorFactory::create($objectAsArray[$protected]);
}
-
+
foreach ($classes as $class) {
$private = sprintf("\0%s\0%s", $class, $property);
@@ -248,4 +253,31 @@ private function getClassAndParents()
}
return $classes;
}
+
+ /**
+ * Checks if intercepted has a magic __call
+ *
+ * @return boolean
+ */
+ protected function interceptedHasAMagicCall()
+ {
+ return !$this->getActualValue() instanceof ExampleGroup &&
+ method_exists($this->getActualValue(), '__call');
+ }
+
+ /**
+ * Invokes intercepted magic call
+ *
+ * @param string $method
+ * @param array $args
+ * @return mixed
+ */
+ protected function invokeInterceptedMagicCall($method, $args)
+ {
+ $intercepted = new \ReflectionMethod($this->getActualValue(), '__call');
+ return InterceptorFactory::create($intercepted->invokeArgs(
+ $this->getActualValue(), array($method, $args)
+ ));
+ }
+
}

0 comments on commit 78ed711

Please sign in to comment.
Something went wrong with that request. Please try again.