Example #1
0
 /**
  * @param \Box\TestScribe\Config\ConfigParams $params
  *
  * @return \Box\TestScribe\MethodInfo\Method
  */
 public function getMethodObjFromParamObj(ConfigParams $params)
 {
     $inPhpClassName = $params->getPhpClassName();
     $inPhpClass = new PhpClass($inPhpClassName);
     $methodName = $params->getMethodName();
     $inMethodObj = $this->methodHelper->createFromMethodName($inPhpClass, $methodName);
     return $inMethodObj;
 }
 /**
  * Handle intercepted calls made to the mock class instance.
  *
  * @param \Box\TestScribe\Mock\MockClass $mockClass
  * @param string                              $methodName
  * @param array                               $arguments
  *
  * @return mixed|void
  * @throws \Box\TestScribe\Exception\TestScribeException
  * @throw \RuntimeException
  */
 public function invokeInterceptedCall(MockClass $mockClass, $methodName, $arguments)
 {
     $this->output->writeStartSeparator();
     $phpClassObj = $mockClass->getPhpClass();
     $methodObj = $this->methodHelper->createFromMethodName($phpClassObj, $methodName);
     $mockObjName = $mockClass->getMockObjectName();
     $this->mockClassServiceCallInfo->showCallInfo($mockObjName, $methodObj, $arguments);
     $returnValue = $this->mockClassServiceInfoSaver->gatherAndSaveCallInfo($mockClass, $methodName, $arguments);
     $this->output->writeEndSeparator();
     return $returnValue;
 }
 /**
  * Handle intercepted calls made to the mock class instance.
  *
  * @param \Box\TestScribe\Mock\MockClass $mockClass
  * @param string                              $methodName
  * @param array                               $arguments
  *
  * @return mixed|void
  * @throws \Box\TestScribe\Exception\TestScribeException
  * @throw \RuntimeException
  */
 public function gatherAndSaveCallInfo(MockClass $mockClass, $methodName, $arguments)
 {
     $phpClass = $mockClass->getPhpClass();
     $className = $mockClass->getClassNameBeingMocked();
     $methodObj = $this->methodHelper->createFromMethodName($phpClass, $methodName);
     $retPHPDocType = $methodObj->getReturnType();
     $value = $this->inputValueGetter->get($retPHPDocType, 'return value', $className, $methodName, '');
     $mockClass->saveInvocationInformation($methodObj, $arguments, $value);
     $returnValue = $value->getValue();
     return $returnValue;
 }
 /**
  * @covers Box\TestScribe\Utils\ReflectionUtil
  */
 public function test_execute_private_instance_method_in_a_mock()
 {
     $className = "\\Box\\TestScribe\\_fixture\\_input\\Calculator";
     $methodName = 'privateAddOne';
     $objectFactoryObj = new ObjectFactory();
     $mockClassLoaderObj = $objectFactoryObj->getMockClassLoader();
     $mockClass = $mockClassLoaderObj->createAndLoadMockClass($className, $methodName);
     $mockObjectFactoryObj = $objectFactoryObj->getMockObjectFactory();
     $mockObj = $mockObjectFactoryObj->createMockObjectFromMockClass($mockClass, [1]);
     $phpClass = new PhpClass(new PhpClassName($className));
     $methodHelper = new MethodHelper();
     $methodObj = $methodHelper->createFromMethodName($phpClass, $methodName);
     $converterObj = $objectFactoryObj->getStringToInputValueConverter();
     $inputValue = $converterObj->getValue('2');
     $args = new Arguments([$inputValue]);
     $objectUnderTest = $objectFactoryObj->getReflectionUtil();
     $executionResult = $objectUnderTest->invokeMethodRegardlessOfProtectionLevel($mockObj, $methodObj, $args);
     // Validate the execution result.
     $expected = 3;
     $this->assertSame($expected, $executionResult, 'Variable ( executionResult ) doesn\'t have the expected value.');
 }
Example #5
0
 /**
  * Return the constructor associated with the method.
  *
  * @return \Box\TestScribe\MethodInfo\Method|null
  */
 public function getConstructor()
 {
     $methodHelperObj = new MethodHelper();
     $constructorMethodObj = $methodHelperObj->createConstructor($this->inClass);
     return $constructorMethodObj;
 }