Пример #1
0
 /**
  * Return the specsPerMethod for the given method.
  *
  * If the method key doesn't exist, an empty spec set
  * will be returned.
  *
  * @param $methodName
  *
  * @return \Box\TestScribe\Spec\SpecsPerMethod
  */
 public function getSpecsPerMethodByName($methodName)
 {
     $default = new SpecsPerMethod($methodName, []);
     /** @var SpecsPerMethod $specsPerMethod */
     $specsPerMethod = ArrayUtil::lookupValueByKey($methodName, $this->specs, $default);
     return $specsPerMethod;
 }
Пример #2
0
 /**
  * Return the last used raw input string for the item.
  * 
  * @param string $sectionName 
  *  either method name of the class under test
  *  or dependent class name
  * 
  * @param string $itemName
  *   either parameter name
  *   or dependent class's method name
  *
  * @return string
  */
 public function getInputStringFromHistory($sectionName, $itemName)
 {
     $inputString = '';
     $sectionArray = ArrayUtil::lookupValueByKey($sectionName, $this->data, null);
     if ($sectionArray !== null) {
         $inputString = ArrayUtil::lookupValueByKey($itemName, $sectionArray, '');
     }
     return $inputString;
 }
 /**
  * @param array $data
  *
  * @return \Box\TestScribe\Spec\OneSpec
  */
 public function loadOneSpec($data)
 {
     $testName = $data[self::TEST_NAME];
     $methodParameters = $data[self::METHOD_PARAM];
     $result = $data[self::RESULT_KEY];
     $mocksData = ArrayUtil::lookupValueByKey(self::MOCK, $data, []);
     $mockSpecs = [];
     foreach ($mocksData as $oneMockData) {
         $oneMockSpec = $this->mockSpecPersistence->loadMockSpec($oneMockData);
         $mockSpecs[] = $oneMockSpec;
     }
     $constructorParameters = ArrayUtil::lookupValueByKey(self::CONSTRUCTOR_PARAM, $data, []);
     $oneSpec = new OneSpec($testName, $result, $constructorParameters, $methodParameters, $mockSpecs);
     return $oneSpec;
 }
 /**
  * @param int $distanceFromThisCall
  *   e.g.
  *   bar calls foo, foo calls this method
  *   To get information about foo, specify 1.
  *   To get information about bar, specify 2. 
  *
  * @return \Box\TestScribe\Utils\CallInfo
  * @throws \Box\TestScribe\Exception\TestScribeException
  */
 public function getCallerInfoAt($distanceFromThisCall)
 {
     // This call frame and
     // $this->stackTraceFunctionWrapper->debugBacktrace()
     // add two frames on top.
     // Note that the frameIndex is 0 based.
     // And the file and line information refer to the caller
     // of the method in the frame.
     // Thus they offset each other.
     $frameIndex = $distanceFromThisCall;
     $stackFrames = $this->stackTraceFunctionWrapper->debugBacktrace();
     $totalFrames = count($stackFrames);
     if ($totalFrames <= $frameIndex) {
         $exceptionMsg = "Requested frame ( {$frameIndex} ) is out of range." . " Total frames ( {$totalFrames} )";
         throw new TestScribeException($exceptionMsg);
     }
     $targetFrame = $stackFrames[$frameIndex];
     $fileName = ArrayUtil::lookupValueByKey('file', $targetFrame, 'unknown');
     $lineNumberString = ArrayUtil::lookupValueByKey('line', $targetFrame, 'unknown');
     $callerInfo = new CallInfo($fileName, $lineNumberString);
     return $callerInfo;
 }
Пример #5
0
 /**
  * @param $testName
  *
  * @return OneSpec|null
  */
 public function getSpecForTest($testName)
 {
     /** @var OneSpec $spec */
     $spec = ArrayUtil::lookupValueByKey($testName, $this->specs, null);
     return $spec;
 }