emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phpinspect 83b55ce1ee 1/3: Add test for behaviour of `p


From: ELPA Syncer
Subject: [elpa] externals/phpinspect 83b55ce1ee 1/3: Add test for behaviour of `phpinspect-imports-remove-unused' variable + fix bug
Date: Mon, 2 Sep 2024 15:58:53 -0400 (EDT)

branch: externals/phpinspect
commit 83b55ce1eeed4223f1e787a0315b0c9ade6ab6f7
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>

    Add test for behaviour of `phpinspect-imports-remove-unused' variable + fix 
bug
---
 phpinspect-imports.el | 10 +++++-----
 test/test-imports.el  | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/phpinspect-imports.el b/phpinspect-imports.el
index 2537067af7..25c8c949d7 100644
--- a/phpinspect-imports.el
+++ b/phpinspect-imports.el
@@ -386,12 +386,12 @@ that there are import (\"use\") statements for them."
             (unless token-meta
               (error "Unable to find token for namespace %s" namespace-name))
 
-           (when phpinspect-imports-remove-unused
-              (phpinspect-add-use-statements-for-missing-types
-               used-types buffer (append imports namespace-imports) project 
token-meta))
+            (phpinspect-add-use-statements-for-missing-types
+             used-types buffer (append imports namespace-imports) project 
token-meta)
 
-            ;; (phpinspect-remove-unneeded-use-statements
-            ;;  used-types buffer (append imports namespace-imports) 
token-meta)
+           (when phpinspect-imports-remove-unused
+              (phpinspect-remove-unneeded-use-statements
+               used-types buffer (append imports namespace-imports) 
token-meta))
 
             (let ((parent (phpinspect-meta-find-parent-matching-token
                            token-meta #'phpinspect-namespace-or-root-p)))
diff --git a/test/test-imports.el b/test/test-imports.el
index 3fa4cff74c..d0c9c9be90 100644
--- a/test/test-imports.el
+++ b/test/test-imports.el
@@ -63,6 +63,43 @@ class Baz {
 }"
                          (buffer-string)))))))
 
+(ert-deftest phpinspect-fix-imports-no-remove-unused ()
+  (dlet ((phpinspect-imports-remove-unused nil))
+    (let ((project (phpinspect--make-dummy-composer-project)))
+      (with-temp-buffer
+       (let* ((buffer (phpinspect-make-buffer :buffer (current-buffer)
+                                               :-project project)))
+
+          (insert "<?php
+
+namespace Not\\App;
+
+use Not\\Needed;
+
+class Baz {
+    private Foo $foo;
+    public Bar $bar;
+}")
+          ;; Ensure buffer is made aware of changes
+          (setq phpinspect-current-buffer buffer)
+          (add-hook 'after-change-functions #'phpinspect-after-change-function)
+
+          (phpinspect-fix-imports)
+          (should (string= "<?php
+
+namespace Not\\App;
+
+use App\\Bar;
+use App\\Foo;
+use Not\\Needed;
+
+class Baz {
+    private Foo $foo;
+    public Bar $bar;
+}"
+                           (buffer-string))))))))
+
+
 (ert-deftest phpinspect-fix-imports-multiple-namespaced-classes ()
   (let ((project (phpinspect--make-dummy-composer-project)))
     (with-temp-buffer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]