]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve getLink method for unit tests
authorJoshua Spence <josh@joshuaspence.com>
Tue, 19 May 2015 23:36:22 +0000 (09:36 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Tue, 19 May 2015 23:36:22 +0000 (09:36 +1000)
Summary:
Ref T7977. The `PhutilTestCase::getLink` method currently relies on arcanist projects instead of repositories. Instead, make this logic a bit smarter by looking up the base URI from `phabricator.uri` (currently it is hardcoded to `https://secure.phabricator.com`).

Ideally, we would pass `?repositories=$REPOSITORY_PHID` to `DiffusionSymbolController` as well, but I don't know if this is worth pursuing.

Test Plan: This diff.

Reviewers: avivey, #blessed_reviewers, epriestley

Reviewed By: avivey, #blessed_reviewers, epriestley

Subscribers: aurelijus, Korvin, epriestley

Maniphest Tasks: T7977

Differential Revision: https://secure.phabricator.com/D12664

src/infrastructure/testing/ArcanistTestCase.php
src/unit/engine/PhutilUnitTestEngine.php
src/unit/engine/XUnitTestEngine.php
src/unit/engine/__tests__/PhutilUnitTestEngineTestCase.php
src/unit/engine/phutil/ArcanistPhutilTestCase.php

index 41de1242de28b6ad78036bf2ee7ea15e3214bc5a..e56707a6ad982a1011a4eade93af2e5c24fb6d50 100644 (file)
@@ -1,13 +1,3 @@
 <?php
 
-abstract class ArcanistTestCase extends ArcanistPhutilTestCase {
-
-  protected function getLink($method) {
-    $arcanist_project = 'PHID-APRJ-703e0b140530f17ede30';
-    return
-      'https://secure.phabricator.com/diffusion/symbol/'.$method.
-      '/?lang=php&projects='.$arcanist_project.
-      '&jump=true&context='.get_class($this);
-  }
-
-}
+abstract class ArcanistTestCase extends ArcanistPhutilTestCase {}
index ae7906002609b34cd114777c86d26dd35d24433e..375890ba3e7c9e3db54c6c283c3fcb1255f41177 100644 (file)
@@ -42,7 +42,8 @@ final class PhutilUnitTestEngine extends ArcanistUnitTestEngine {
     foreach ($run_tests as $test_class) {
       $test_case = newv($test_class, array());
       $test_case->setEnableCoverage($enable_coverage);
-      $test_case->setProjectRoot($project_root);
+      $test_case->setWorkingCopy($this->getWorkingCopy());
+
       if ($this->getPaths()) {
         $test_case->setPaths($this->getPaths());
       }
index cec076c5a11dadb47230f4b77eae6cf414daffbf..d97c6f0ef70d9516713b7ce848fb954b989eb2c5 100644 (file)
@@ -101,7 +101,6 @@ class XUnitTestEngine extends ArcanistUnitTestEngine {
    * @return array   Array of test results.
    */
   public function run() {
-
     $this->loadEnvironment();
 
     if ($this->getRunAllTests()) {
index 561e108b16681eeca5eef1e6fc0aeca089608934..62b3af07ac1c89d4b697e7f98a76d99482be2b1c 100644 (file)
@@ -75,7 +75,10 @@ final class PhutilUnitTestEngineTestCase extends ArcanistTestCase {
   public function testFailSkip() {
     $failed = 0;
     $skipped = 0;
-    $test_case = new ArcanistPhutilTestCaseTestCase();
+
+    $test_case = id(new ArcanistPhutilTestCaseTestCase())
+      ->setWorkingCopy($this->getWorkingCopy());
+
     foreach ($test_case->run() as $result) {
       if ($result->getResult() == ArcanistUnitTestResult::RESULT_FAIL) {
         $failed++;
index 3e10052b1a0564d2bbfa18a27efa3a3c162ed133..54aa730697eca4212710072221479adf9fb29263 100644 (file)
@@ -16,7 +16,7 @@ abstract class ArcanistPhutilTestCase {
   private $results = array();
   private $enableCoverage;
   private $coverage = array();
-  private $projectRoot;
+  private $workingCopy;
   private $paths;
   private $renderer;
 
@@ -570,7 +570,9 @@ abstract class ArcanistPhutilTestCase {
     $coverage = array();
 
     foreach ($result as $file => $report) {
-      if (strncmp($file, $this->projectRoot, strlen($this->projectRoot))) {
+      $project_root = $this->getProjectRoot();
+
+      if (strncmp($file, $project_root, strlen($project_root))) {
         continue;
       }
 
@@ -593,7 +595,7 @@ abstract class ArcanistPhutilTestCase {
           $str .= 'N'; // Not executable.
         }
       }
-      $coverage[substr($file, strlen($this->projectRoot) + 1)] = $str;
+      $coverage[substr($file, strlen($project_root) + 1)] = $str;
     }
 
     // Only keep coverage information for files modified by the change. In
@@ -613,18 +615,44 @@ abstract class ArcanistPhutilTestCase {
     }
   }
 
-  final public function setProjectRoot($project_root) {
-    $this->projectRoot = $project_root;
+  final public function getWorkingCopy() {
+    return $this->workingCopy;
+  }
+
+  final public function setWorkingCopy(
+    ArcanistWorkingCopyIdentity $working_copy) {
+
+    $this->workingCopy = $working_copy;
     return $this;
   }
 
+  final public function getProjectRoot() {
+    $working_copy = $this->getWorkingCopy();
+
+    if (!$working_copy) {
+      throw new PhutilInvalidStateException('setWorkingCopy');
+    }
+
+    return $working_copy->getProjectRoot();
+  }
+
   final public function setPaths(array $paths) {
     $this->paths = $paths;
     return $this;
   }
 
-  protected function getLink($method) {
-    return null;
+  final protected function getLink($method) {
+    $base_uri = $this
+      ->getWorkingCopy()
+      ->getProjectConfig('phabricator.uri');
+
+    $uri = id(new PhutilURI($base_uri))
+      ->setPath("/diffusion/symbol/{$method}/")
+      ->setQueryParam('context', get_class($this))
+      ->setQueryParam('jump', 'true')
+      ->setQueryParam('lang', 'php');
+
+    return (string)$uri;
   }
 
   public function setRenderer(ArcanistUnitRenderer $renderer) {