Example #1
0
 /**
  * @param string $path
  *
  * @return mixed
  */
 public function loadYamlFile($path)
 {
     $yamlString = $this->fileFunctionWrapper->file_get_all_contents($path);
     $parser = new Parser();
     $data = $parser->parse($yamlString);
     return $data;
 }
 /**
  * @param string $specFilePath
  *
  * @param string $fullClassName
  *
  * @return \Box\TestScribe\Spec\SpecsPerClass
  */
 public function loadSpec($specFilePath, $fullClassName)
 {
     if ($this->fileFunctionWrapper->file_exists($specFilePath)) {
         $data = $this->yamlUtil->loadYamlFile($specFilePath);
         $specsPerClass = $this->specsPerClassPersistence->loadSpecsPerClass($data);
     } else {
         $specsPerClass = new SpecsPerClass($fullClassName, []);
     }
     return $specsPerClass;
 }
Example #3
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  *
  * @return \Box\TestScribe\Config\ConfigParams
  * @throws \Box\TestScribe\Exception\TestScribeException
  */
 public function getInputParams(InputInterface $input)
 {
     $originalInSourceFile = (string) $input->getArgument(CmdOption::SOURCE_FILE_NAME_KEY);
     // Always use the absolute path. This is needed when checking
     // if a call is from the class under test.
     $inSourceFile = $this->fileFunctionWrapper->realpath($originalInSourceFile);
     $inClassName = $this->classExtractor->getClassName($inSourceFile);
     $inPhpClassName = new PhpClassName($inClassName);
     $methodName = $this->methodNameGetter->getTestMethodName($input, $inClassName);
     $msg = "Testing the method ( {$methodName} ) of the class ( {$inClassName} ).";
     $this->output->writeln($msg);
     $inputParams = new ConfigParams($inSourceFile, $inPhpClassName, $methodName);
     return $inputParams;
 }
 /**
  * @param InputInterface $input
  * @return string
  */
 public function getConfigFilePath(InputInterface $input)
 {
     $configFilePath = $input->getOption(CmdOption::CONFIG_FILE_PATH);
     if (!$configFilePath) {
         // If the option is not given in the command line,
         // null will be returned from the getOption call.
         $configFilePath = '';
         $pathPrefixToSearch = ['tests/', 'test/', ''];
         foreach ($pathPrefixToSearch as $prefix) {
             $pathCandidate = $prefix . self::DEFAULT_CONFIG_FILE_NAME;
             if ($this->fileFunctionWrapper->file_exists($pathCandidate)) {
                 $configFilePath = $pathCandidate;
                 break;
             }
         }
     }
     return $configFilePath;
 }
Example #5
0
 /**
  * Write the data string to the file.
  * Create the directory in the path recursively if it doesn't exist.
  *
  * @param string $filename
  * @param string $data
  *
  * @return void
  * @exception TestScribeException
  */
 public function putContent($filename, $data)
 {
     $this->createDirectoriesWhenNeededForFile($filename);
     $this->fileFunctionWrapper->file_put_contents($filename, $data);
 }