Example #1
0
 /**
  * Construct a new wrapped method.
  *
  * @param ReflectionMethod $method The method.
  * @param Handle           $handle The handle.
  */
 public function __construct(ReflectionMethod $method, Handle $handle)
 {
     $this->method = $method;
     $this->handle = $handle;
     $this->name = $method->getName();
     if ($handle instanceof StaticHandle) {
         $this->mock = null;
         $callback = array($method->getDeclaringClass()->getName(), $this->name);
     } else {
         $this->mock = $handle->get();
         $callback = array($this->mock, $this->name);
     }
     parent::__construct($callback, null);
 }
Example #2
0
 /**
  * Construct a new wrapped magic method.
  *
  * @param string           $name            The name.
  * @param ReflectionMethod $callMagicMethod The _callMagic() method.
  * @param bool             $isUncallable    True if the underlying magic method is uncallable.
  * @param Handle           $handle          The handle.
  */
 public function __construct($name, ReflectionMethod $callMagicMethod, $isUncallable, Handle $handle)
 {
     $this->name = $name;
     $this->callMagicMethod = $callMagicMethod;
     $this->isUncallable = $isUncallable;
     $this->handle = $handle;
     if ($callMagicMethod->isStatic()) {
         $this->mock = null;
         $callback = array($callMagicMethod->getDeclaringClass()->getName(), '__callStatic');
     } else {
         $this->mock = $handle->get();
         $callback = array($this->mock, '__call');
     }
     parent::__construct($callback, null);
 }
Example #3
0
 /**
  * Render a failed noInteraction() verification.
  *
  * @param Handle      $handle The handle.
  * @param array<Call> $calls  The calls.
  *
  * @return string The rendered failure message.
  */
 public function renderNoInteraction(Handle $handle, array $calls)
 {
     $class = $handle->clazz();
     if ($parentClass = $class->getParentClass()) {
         $class = $parentClass;
     }
     $atoms = explode('\\', $class->getName());
     $renderedHandle = array_pop($atoms);
     if ($handle instanceof InstanceHandle) {
         $label = $handle->label();
         if (null !== $label) {
             $renderedHandle .= '[' . $label . ']';
         }
     } else {
         $renderedHandle .= '[static]';
     }
     usort($calls, 'Eloquent\\Phony\\Call\\CallData::compareSequential');
     $renderedCalls = array();
     foreach ($calls as $index => $call) {
         $renderedArguments = array();
         foreach ($call->arguments()->all() as $argument) {
             $renderedArguments[] = $this->exporter->export($argument);
         }
         $renderedCalls[] = '    ' . $this->fail . ' ' . $this->exporter->exportCallable($call->callback()) . '(' . implode(', ', $renderedArguments) . ')';
     }
     return $this->reset . 'Expected no interaction with ' . $this->bold . $renderedHandle . $this->reset . '. Calls:' . PHP_EOL . implode(PHP_EOL, $renderedCalls);
 }