Exemplo n.º 1
0
 /**
  * @param \Box\TestScribe\Execution\ExecutionResult $executionResult
  *
  * @return void
  */
 public function genSpec(ExecutionResult $executionResult)
 {
     // This method assumes that the saved specs have been loaded.
     $specsPerClass = $this->savedSpecs->getSpecPerClass();
     $oneSpec = $this->specDetailRenderer->genSpecDetail($executionResult);
     $methodName = $this->globalComputedConfig->getMethodName();
     $newSpecsPerClass = $this->specsPerClassService->addOneSpec($specsPerClass, $methodName, $oneSpec);
     $this->savedSpecs->saveNewSpec($newSpecsPerClass);
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * @param \Box\TestScribe\Config\Options $options
  * @param \Box\TestScribe\Config\ConfigParams $inputParams
  *
  * @return \Box\TestScribe\Config\ConfigParams
  */
 public function getOutputParams(Options $options, ConfigParams $inputParams)
 {
     $inFullClassName = $inputParams->getFullClassName();
     $outFullClassName = $inFullClassName . 'GenTest';
     $outPhpClassName = new PhpClassName($outFullClassName);
     $outSimpleClassName = $outPhpClassName->getClassName();
     $outSourceFileDir = $options->getOutSourceFileDir();
     $outSourceFilePath = $outSourceFileDir . DIRECTORY_SEPARATOR . $outSimpleClassName . '.php';
     $overwriteExistingDestinationFile = $options->isOverwriteExistingDestinationFile();
     $methodName = $inputParams->getMethodName();
     $specPerClass = $this->savedSpecs->loadExistingSpecs($inputParams, $outSourceFileDir);
     $outTestMethodName = $this->outputTestNameGetter->getTestName($methodName, $overwriteExistingDestinationFile, $specPerClass);
     $outputParams = new ConfigParams($outSourceFilePath, $outPhpClassName, $outTestMethodName);
     return $outputParams;
 }