/** * Generate an OneSpec instance from the execution result. * * @param \Box\TestScribe\Execution\ExecutionResult $executionResult * * @return \Box\TestScribe\Spec\OneSpec */ public function genSpecDetail(ExecutionResult $executionResult) { $testName = $this->globalComputedConfig->getTestMethodName(); $result = $executionResult->getResultValue(); $methodArguments = $executionResult->getMethodArguments(); $methodParameters = $methodArguments->getValues(); $constructorArguments = $executionResult->getConstructorArguments(); $constructorParameters = $constructorArguments->getValues(); $mockSpecs = $this->allMockSpecs->getAllMockSpecs(); $oneSpec = new OneSpec($testName, $result, $constructorParameters, $methodParameters, $mockSpecs); return $oneSpec; }
/** * Collect values of the arguments to the given method. * * @param \Box\TestScribe\MethodInfo\Method $method * * @return \Box\TestScribe\ArgumentInfo\Arguments */ public function collect(Method $method) { $reflectionMethod = $method->getReflectionMethod(); $args = $reflectionMethod->getParameters(); $argumentsCount = count($args); if (!$argumentsCount) { return new Arguments([]); } $methodName = $reflectionMethod->getName(); $className = $reflectionMethod->getDeclaringClass()->getName(); $message = "\nPrepare to get arguments to the method ( {$methodName} ) of the class ( {$className} ).\n"; $this->output->writeln($message); $methodParams = null; $testName = $this->globalComputedConfig->getTestMethodName(); $savedSpec = $this->savedSpecs->getSpecForTest($testName); if ($savedSpec) { if ($method->isConstructor()) { $methodParams = $savedSpec->getConstructorParameters(); } else { $methodParams = $savedSpec->getMethodParameters(); } } $argsArray = []; $index = 0; foreach ($args as $arg) { $argumentName = $arg->getName(); $argPromptSubject = "parameter ( {$argumentName} )"; $isOptional = $arg->isOptional(); if ($isOptional) { $argPromptSubject = "optional {$argPromptSubject}"; } if ($methodParams) { // @TODO (Ray Yang 9/30/15) : error checking $value = $methodParams[$index]; $this->output->writeln("Get ( {$value} ) from the saved test for {$argPromptSubject}"); $inputValue = $this->inputValueFactory->createPrimitiveValue($value); } else { $typeInfo = $method->getParamTypeString($argumentName); $inputValue = $this->inputValueGetter->get($typeInfo, $argPromptSubject, '', $methodName, $argumentName); } if ($inputValue->isVoid()) { // @TODO (ryang 1/9/15) : double check if the parameter is optional. // Assume the parameters after this one will all have to be void. break; } $argsArray[] = $inputValue; $index++; } // Add an empty line for improved readability. $this->output->writeln(''); $args = new Arguments($argsArray); return $args; }