/**
  * @param string $className
  * @param bool   $isStatic
  * @param string $nameOfTheMethodToPassThrough
  *   If not empty string, it tells this instance to pass calls to
  *   this method to the real object of the class being mocked
  *   and continue to mock other methods.
  *   If it is empty, it tells this instance to mock all methods.
  *
  * @return \Box\TestScribe\Mock\MockClass
  * @throws \DI\NotFoundException
  */
 public function create($className, $isStatic, $nameOfTheMethodToPassThrough)
 {
     $phpClassName = new PhpClassName($className);
     $simpleClassName = $phpClassName->getClassName();
     $mockObjectName = $this->mockObjectNameMgr->getMockObjectName($simpleClassName);
     $phpClass = new PhpClass($phpClassName);
     $mock = new MockClass($this->mockClassService, $phpClass, $isStatic, $nameOfTheMethodToPassThrough, $mockObjectName);
     $this->mockMgr->addMock($mock);
     return $mock;
 }
Esempio n. 2
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;
 }
    /**
     * @param PhpClassName $outPhpClassName
     *
     * @return string
     */
    public function renderClassHeader(PhpClassName $outPhpClassName)
    {
        $classNamespace = $outPhpClassName->getNameSpace();
        if ($classNamespace != '') {
            $namespaceStatement = "namespace {$classNamespace};";
        } else {
            $namespaceStatement = '';
        }
        $testClassName = $outPhpClassName->getClassName();
        $testBaseClassName = $this->globalComputedConfig->getTestBaseClassName();
        $headerStatements = <<<TAG
<?php
{$namespaceStatement}

/**
 * Generated by TestScribe.
 */
class {$testClassName} extends {$testBaseClassName}

TAG;
        return $headerStatements;
    }
 /**
  * @param \Box\TestScribe\ClassInfo\PhpClassName $inPhpClassName
  * @param string $outSourcePath
  *
  * @return string
  */
 public static function computeSpecFilePath(PhpClassName $inPhpClassName, $outSourcePath)
 {
     $inClassName = $inPhpClassName->getClassName();
     $specFilePath = $outSourcePath . DIRECTORY_SEPARATOR . $inClassName . '_ts.yaml';
     return $specFilePath;
 }
Esempio n. 5
0
 /**
  * (PHP 5 &gt;= 5.4.0)<br/>
  * Specify data which should be serialized to JSON
  * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  * @return mixed data which can be serialized by <b>json_encode</b>,
  * which is a value of any type other than a resource.
  */
 function jsonSerialize()
 {
     $data = ['file path' => $this->sourceFile, 'class name' => $this->phpClassName->getFullyQualifiedClassName(), 'method name' => $this->methodName];
     return $data;
 }
 /**
  * @return bool
  */
 public function isTheTestRunAgainstTheToolItself()
 {
     $fullClassName = $this->inPhpClassName->getFullyQualifiedClassName();
     $isTheTestRunAgainstTheToolItself = StringUtil::isStringStartWith($fullClassName, '\\Box\\TestScribe');
     return $isTheTestRunAgainstTheToolItself;
 }