/**
  * Handle intercepted calls made to the mock class instance.
  *
  * @param string                            $mockObjName
  * @param \Box\TestScribe\MethodInfo\Method $method
  * @param array                             $arguments
  *
  * @return void
  */
 public function showCallInfo($mockObjName, Method $method, array $arguments)
 {
     $methodName = $method->getName();
     $callerInfoString = $this->getCallerInfoString();
     $msg = "\n{$callerInfoString} Calling {$mockObjName}->{$methodName}( ";
     $this->output->write($msg);
     $msg = $this->methodCallInfo->getCallParamInfo($method, $arguments);
     $this->output->writeln($msg);
 }
예제 #2
0
 /**
  * Invoke a method on the target object regardless if the method is private, protected or public.
  *
  * @param object|null                         $targetObject null if the method is static
  * @param \Box\TestScribe\MethodInfo\Method    $method
  * @param \Box\TestScribe\ArgumentInfo\Arguments $arguments
  *
  * @return mixed
  */
 public function invokeMethodRegardlessOfProtectionLevel($targetObject, Method $method, Arguments $arguments)
 {
     $className = $method->getFullClassName();
     $argumentValues = $arguments->getValues();
     // @TODO (ryang 2/3/15) : warn against testing private methods directly.
     // @TODO (ryang 6/8/15) : only change accessibility when the method is not public
     $reflectionClass = new \ReflectionClass($className);
     $methodName = $method->getName();
     $reflectionMethod = $reflectionClass->getMethod($methodName);
     $reflectionMethod->setAccessible(true);
     $this->output->writeln("\nStart executing method ( {$methodName} ).\n");
     $executionResult = $reflectionMethod->invokeArgs($targetObject, $argumentValues);
     $this->output->writeln("\nFinish executing method ( {$methodName} ).\n");
     return $executionResult;
 }
 /**
  * Generate and return the statement for setting up one
  * mocked object method invocation expectation.
  *
  * @param Method     $methodObj
  * @param array      $arguments
  * @param InputValue $returnValue
  *
  * @return string
  */
 public function renderOneMethodExpectation(Method $methodObj, array $arguments, InputValue $returnValue)
 {
     $methodName = $methodObj->getName();
     $argString = $this->mockedMethodInvocationArgumentsRenderer->renderMockedMethodArguments($arguments);
     $expectationStatements = "\$shmock->{$methodName}({$argString});";
     // @TODO (ryang 9/12/14) : can we make this decision purely based on the $value?
     // If no return value still specify return null?
     // If the method has no return value
     // don't generate the return value mock statement.
     if (!$returnValue->isVoid()) {
         $returnValueAsString = $returnValue->getExpression();
         $returnValueCallStatement = "\$mock->return_value({$returnValueAsString});";
         $expectationStatements = "/** @var \$mock \\Shmock\\Spec */\n" . "\$mock = {$expectationStatements}\n" . "{$returnValueCallStatement}";
     }
     return $expectationStatements;
 }
 /**
  * Get the name of the method under test.
  *
  * @return string
  */
 public function getMethodName()
 {
     return $this->inMethod->getName();
 }