]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add some tests for subclasses
authorJoshua Spence <josh@joshuaspence.com>
Mon, 15 Jun 2015 10:00:54 +0000 (20:00 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Mon, 15 Jun 2015 10:01:30 +0000 (20:01 +1000)
Summary: Add some tests to ensure that `ArcanistXHPASTLinterRule` subclasses are properly implemented. This should catch issues such as two linter rules having the same `ID` value. See D13272 for a similar change.

Test Plan: `arc unit`

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

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

src/__phutil_library_map__.php
src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php
src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php [new file with mode: 0644]

index 6c4fe32ca3b587f79e2762ea58b2b0e27f16972a..e5e0583d70af5cd71d0602411dcaa3bc0216c4d6 100644 (file)
@@ -261,6 +261,7 @@ phutil_register_library_map(array(
     'ArcanistXHPASTLintSwitchHook' => 'lint/linter/xhpast/ArcanistXHPASTLintSwitchHook.php',
     'ArcanistXHPASTLinter' => 'lint/linter/ArcanistXHPASTLinter.php',
     'ArcanistXHPASTLinterRule' => 'lint/linter/xhpast/ArcanistXHPASTLinterRule.php',
+    'ArcanistXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php',
     'ArcanistXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php',
     'ArcanistXMLLinter' => 'lint/linter/ArcanistXMLLinter.php',
     'ArcanistXMLLinterTestCase' => 'lint/linter/__tests__/ArcanistXMLLinterTestCase.php',
@@ -533,6 +534,7 @@ phutil_register_library_map(array(
     'ArcanistXHPASTLintSwitchHook' => 'Phobject',
     'ArcanistXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
     'ArcanistXHPASTLinterRule' => 'Phobject',
+    'ArcanistXHPASTLinterRuleTestCase' => 'PhutilTestCase',
     'ArcanistXHPASTLinterTestCase' => 'ArcanistLinterTestCase',
     'ArcanistXMLLinter' => 'ArcanistLinter',
     'ArcanistXMLLinterTestCase' => 'ArcanistLinterTestCase',
index 0d1b593de5133e3388d495537c08ce119e1832db..668542f842e6f15d879807d5c0ac1d50b24104c6 100644 (file)
@@ -8,7 +8,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
   private $rules = array();
 
   public function __construct() {
-    $this->rules = $this->getLinterRules();
+    $this->rules = ArcanistXHPASTLinterRule::loadAllRules();
   }
 
   public function __clone() {
@@ -66,32 +66,6 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
     return count($this->rules);
   }
 
-  public function getLinterRules() {
-    $rules = array();
-
-    $symbols = id(new PhutilSymbolLoader())
-      ->setAncestorClass('ArcanistXHPASTLinterRule')
-      ->loadObjects();
-
-    foreach ($symbols as $class => $rule) {
-      $id = $rule->getLintID();
-
-      if (isset($rules[$id])) {
-        throw new Exception(
-          pht(
-            'Two linter rules (`%s`, `%s`) share the same lint ID (%d). '.
-            'Each linter rule must have a unique ID.',
-            $class,
-            get_class($rules[$id]),
-            $id));
-      }
-
-      $rules[$id] = $rule;
-    }
-
-    return $rules;
-  }
-
   protected function resolveFuture($path, Future $future) {
     $tree = $this->getXHPASTTreeForPath($path);
     if (!$tree) {
index 35bf55167f75b6f9f00fb7cf5a19d3200ec2c224..00c441947e640517d0939dff64f0abdb20719f6c 100644 (file)
@@ -4,6 +4,32 @@ abstract class ArcanistXHPASTLinterRule extends Phobject {
 
   private $linter = null;
 
+  final public static function loadAllRules() {
+    $rules = array();
+
+    $symbols = id(new PhutilSymbolLoader())
+      ->setAncestorClass(__CLASS__)
+      ->loadObjects();
+
+    foreach ($symbols as $class => $rule) {
+      $id = $rule->getLintID();
+
+      if (isset($rules[$id])) {
+        throw new Exception(
+          pht(
+            'Two linter rules (`%s`, `%s`) share the same lint ID (%d). '.
+            'Each linter rule must have a unique ID.',
+            $class,
+            get_class($rules[$id]),
+            $id));
+      }
+
+      $rules[$id] = $rule;
+    }
+
+    return $rules;
+  }
+
   final public function getLintID() {
     $class = new ReflectionClass($this);
 
diff --git a/src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php b/src/lint/linter/xhpast/__tests__/ArcanistXHPASTLinterRuleTestCase.php
new file mode 100644 (file)
index 0000000..fcb49f7
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+final class ArcanistXHPASTLinterRuleTestCase extends PhutilTestCase {
+
+  public function testLoadAllRules() {
+    ArcanistXHPASTLinterRule::loadAllRules();
+    $this->assertTrue(true);
+  }
+
+}