Author: Sebastian Bergmann (sebastian@phpunit.de)
コード例 #1
0
ファイル: ResultPrinter.php プロジェクト: qcodo/qcodo-website
 /**
  * A test started.
  *
  * @param  PHPUnit_Framework_Test $test
  */
 public function startTest(PHPUnit_Framework_Test $test)
 {
     if ($test instanceof $this->testTypeOfInterest) {
         $class = get_class($test);
         if ($this->testClass != $class) {
             if ($this->testClass != '') {
                 $this->doEndClass();
             }
             $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
             $this->startClass($class);
             $this->testClass = $class;
             $this->tests = array();
         }
         $prettified = FALSE;
         if ($test instanceof PHPUnit_Framework_TestCase && !$test instanceof PHPUnit_Framework_Warning) {
             $annotations = $test->getAnnotations();
             if (isset($annotations['method']['testdox'][0])) {
                 $this->currentTestMethodPrettified = $annotations['method']['testdox'][0];
                 $prettified = TRUE;
             }
         }
         if (!$prettified) {
             $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(FALSE));
         }
         $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
     }
 }
コード例 #2
0
ファイル: ResultPrinter.php プロジェクト: luchaninov/phpunit
 /**
  * A test started.
  *
  * @param PHPUnit_Framework_Test $test
  */
 public function startTest(PHPUnit_Framework_Test $test)
 {
     if (!$this->isOfInterest($test)) {
         return;
     }
     $class = get_class($test);
     if ($this->testClass != $class) {
         if ($this->testClass != '') {
             $this->doEndClass();
         }
         $classAnnotations = PHPUnit_Util_Test::parseTestMethodAnnotations($class);
         if (isset($classAnnotations['class']['testdox'][0])) {
             $this->currentTestClassPrettified = $classAnnotations['class']['testdox'][0];
         } else {
             $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
         }
         $this->startClass($class);
         $this->testClass = $class;
         $this->tests = [];
     }
     $annotations = $test->getAnnotations();
     if (isset($annotations['method']['testdox'][0])) {
         $this->currentTestMethodPrettified = $annotations['method']['testdox'][0];
     } else {
         $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(false));
     }
     $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
 }
コード例 #3
0
ファイル: ResultPrinter.php プロジェクト: dalinhuang/shopexts
 /**
  * @access private
  * @since  Method available since Release 2.3.0
  */
 private function doEndClass()
 {
     foreach ($this->tests as $name => $data) {
         if ($data['failure'] == 0) {
             $this->onTest($name);
         }
     }
     $this->endClass($this->prettifier->prettifyTestClass($this->testClass));
 }
コード例 #4
0
ファイル: XML.php プロジェクト: thanghexp/project
 /**
  * A test ended.
  *
  * @param PHPUnit_Framework_Test $test
  * @param float                  $time
  */
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     if (!$test instanceof PHPUnit_Framework_TestCase) {
         return;
     }
     /* @var PHPUnit_Framework_TestCase $test */
     $groups = array_filter($test->getGroups(), function ($group) {
         if ($group == 'small' || $group == 'medium' || $group == 'large') {
             return false;
         }
         return true;
     });
     $node = $this->document->createElement('test');
     $node->setAttribute('className', get_class($test));
     $node->setAttribute('methodName', $test->getName());
     $node->setAttribute('prettifiedClassName', $this->prettifier->prettifyTestClass(get_class($test)));
     $node->setAttribute('prettifiedMethodName', $this->prettifier->prettifyTestMethod($test->getName()));
     $node->setAttribute('status', $test->getStatus());
     $node->setAttribute('time', $time);
     $node->setAttribute('size', $test->getSize());
     $node->setAttribute('groups', implode(',', $groups));
     $inlineAnnotations = PHPUnit_Util_Test::getInlineAnnotations(get_class($test), $test->getName());
     if (isset($inlineAnnotations['given']) && isset($inlineAnnotations['when']) && isset($inlineAnnotations['then'])) {
         $node->setAttribute('given', $inlineAnnotations['given']['value']);
         $node->setAttribute('givenStartLine', $inlineAnnotations['given']['line']);
         $node->setAttribute('when', $inlineAnnotations['when']['value']);
         $node->setAttribute('whenStartLine', $inlineAnnotations['when']['line']);
         $node->setAttribute('then', $inlineAnnotations['then']['value']);
         $node->setAttribute('thenStartLine', $inlineAnnotations['then']['line']);
     }
     if ($this->exception !== null) {
         if ($this->exception instanceof PHPUnit_Framework_Exception) {
             $steps = $this->exception->getSerializableTrace();
         } else {
             $steps = $this->exception->getTrace();
         }
         $class = new ReflectionClass($test);
         $file = $class->getFileName();
         foreach ($steps as $step) {
             if (isset($step['file']) && $step['file'] == $file) {
                 $node->setAttribute('exceptionLine', $step['line']);
                 break;
             }
         }
         $node->setAttribute('exceptionMessage', $this->exception->getMessage());
     }
     $this->root->appendChild($node);
 }
コード例 #5
0
ファイル: ResultPrinter.php プロジェクト: cjmi/miniblog
 /**
  * A test started.
  *
  * @param  PHPUnit_Framework_Test $test
  */
 public function startTest(PHPUnit_Framework_Test $test)
 {
     if ($test instanceof $this->testTypeOfInterest) {
         $class = get_class($test);
         if ($this->testClass != $class) {
             if ($this->testClass != '') {
                 $this->doEndClass();
             }
             $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
             $this->startClass($class);
             $this->testClass = $class;
             $this->tests = array();
         }
         $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName());
         $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
     }
 }
コード例 #6
0
ファイル: TestListener.php プロジェクト: TrueType/phpunit
 /**
  * Prettifies the name of a test class.
  *
  * This method will return $testClass unchanged if human-readable names
  * are disabled.
  *
  * @param string $testClassName a camel-case test class name, must not be empty
  *
  * @return string the prettified test class name, will not be empty
  */
 protected function prettifyTestClass($testClassName)
 {
     if (!$this->useHumanReadableTextFormat) {
         return $testClassName;
     }
     $testClassNameWithoutPrefixOrSuffix = preg_replace('/(tx_|Tx_)?(.+)(Test|_testcase)$/', '\\2', $testClassName);
     $testClassNameWithoutUnderScores = str_replace('_', ' ', $testClassNameWithoutPrefixOrSuffix);
     $this->namePrettifier->setPrefix(null);
     $this->namePrettifier->setSuffix(null);
     return $this->namePrettifier->prettifyTestClass($testClassNameWithoutUnderScores);
 }
コード例 #7
0
ファイル: Module.php プロジェクト: TrueType/phpunit
 /**
  * Renders a drop-down for running single tests for the given extension.
  *
  * @param string $extensionKey
  *        keys of the extension for which to render the drop-down
  *
  * @return string
  *         HTML code with the drop-down and a surrounding form
  */
 protected function createTestSelector($extensionKey)
 {
     if (!$this->testFinder->existsTestableForKey($extensionKey)) {
         return '';
     }
     $testSuite = new PHPUnit_Framework_TestSuite('tx_phpunit_basetestsuite');
     $testsPathOfExtension = $this->testFinder->getTestableForKey($extensionKey)->getTestsPath();
     $testSuites = $this->testCaseService->findTestCaseFilesInDirectory($testsPathOfExtension);
     foreach ($testSuites as $fileName) {
         require_once $testsPathOfExtension . $fileName;
     }
     foreach (get_declared_classes() as $className) {
         if ($this->testCaseService->isValidTestCaseClassName($className)) {
             $testSuite->addTestSuite($className);
         }
     }
     // single test case
     $testsOptionsArr = array();
     $testCaseFile = $this->request->getAsString(Tx_Phpunit_Interface_Request::PARAMETER_KEY_TESTCASE);
     $useHumanReadableOptionLabels = $this->userSettingsService->getAsBoolean('testdox');
     /** @var PHPUnit_Framework_TestSuite $testCase */
     foreach ($testSuite->tests() as $testCase) {
         if ($testCaseFile !== null && $testCase->getName() !== $testCaseFile) {
             continue;
         }
         /** @var PHPUnit_Framework_TestCase $test */
         foreach ($testCase->tests() as $test) {
             if ($test instanceof PHPUnit_Framework_TestSuite) {
                 list($testSuiteName, $testName) = explode('::', $test->getName());
                 $testIdentifier = $testName . '(' . $testSuiteName . ')';
             } else {
                 $testName = $test->getName();
                 $testIdentifier = $test->toString();
                 $testSuiteName = strstr($testIdentifier, '(');
                 $testSuiteName = trim($testSuiteName, '()');
             }
             $selected = $testIdentifier === $this->request->getAsString(Tx_Phpunit_Interface_Request::PARAMETER_KEY_TEST) ? ' selected="selected"' : '';
             $testCaption = $useHumanReadableOptionLabels ? $this->namePrettifier->prettifyTestMethod($testName) : $testName;
             $testsOptionsArr[$testSuiteName][] .= '<option value="' . $testIdentifier . '"' . $selected . '>' . htmlspecialchars($testCaption) . '</option>';
         }
     }
     if (count($testsOptionsArr) === 0) {
         return '';
     }
     // builds options for select (including option groups for test suites)
     $testOptionsHtml = '';
     foreach ($testsOptionsArr as $suiteName => $testArr) {
         $testOptionsHtml .= '<optgroup label="' . $suiteName . '">';
         foreach ($testArr as $testHtml) {
             $testOptionsHtml .= $testHtml;
         }
         $testOptionsHtml .= '</optgroup>';
     }
     $currentStyle = $this->createIconStyle($extensionKey);
     return '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tools_txphpunitbeM1')) . '" method="post">
         <p>
         <select style="' . $currentStyle . '" name="' . Tx_Phpunit_Interface_Request::PARAMETER_NAMESPACE . '[' . Tx_Phpunit_Interface_Request::PARAMETER_KEY_TEST . ']">
         <option value="">' . $this->translate('select_tests') . '</option>' . $testOptionsHtml . '</select>
         <button type="submit" name="' . Tx_Phpunit_Interface_Request::PARAMETER_NAMESPACE . '[' . Tx_Phpunit_Interface_Request::PARAMETER_KEY_EXECUTE . ']" value="run" accesskey="s">' . $this->translate('run_single_test') . '</button>
         <input type="hidden" name="' . Tx_Phpunit_Interface_Request::PARAMETER_NAMESPACE . '[' . Tx_Phpunit_Interface_Request::PARAMETER_KEY_COMMAND . ']" value="runsingletest" />
         <input type="hidden" name="' . Tx_Phpunit_Interface_Request::PARAMETER_NAMESPACE . '[' . Tx_Phpunit_Interface_Request::PARAMETER_KEY_TESTCASE . ']" value="' . $testCaseFile . '" />
         </p>
         </form>';
 }