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

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

[elpa] externals/phpinspect be2f8dada5 1/4: Add test for phpinspect-fix-


From: ELPA Syncer
Subject: [elpa] externals/phpinspect be2f8dada5 1/4: Add test for phpinspect-fix-imports
Date: Sat, 17 Aug 2024 06:58:47 -0400 (EDT)

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

    Add test for phpinspect-fix-imports
---
 phpinspect-imports.el       |  4 +--
 test/phpinspect-test-env.el | 22 ++++++++++-----
 test/phpinspect-test.el     |  1 +
 test/test-imports.el        | 65 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/phpinspect-imports.el b/phpinspect-imports.el
index 81ba8ba540..83b658c617 100644
--- a/phpinspect-imports.el
+++ b/phpinspect-imports.el
@@ -199,9 +199,7 @@ that there are import (\"use\") statements for them."
                      tree nil (phpinspect-buffer-location-resolver buffer)))
              (classes (alist-get 'classes index))
              (imports (alist-get 'imports index))
-             (project (phpinspect--cache-get-project-create
-                       (phpinspect--get-or-create-global-cache)
-                       (phpinspect-current-project-root)))
+             (project (phpinspect-buffer-project buffer))
              (used-types (alist-get 'used-types index)))
 
         (phpinspect-add-use-statements-for-missing-types
diff --git a/test/phpinspect-test-env.el b/test/phpinspect-test-env.el
index becfc1df82..393d0a9fb8 100644
--- a/test/phpinspect-test-env.el
+++ b/test/phpinspect-test-env.el
@@ -10,16 +10,26 @@
 (phpinspect-ensure-worker)
 (phpinspect-purge-cache)
 
-(defun phpinspect--make-dummy-project ()
-  (phpinspect--make-project
-   :fs (phpinspect-make-virtual-fs)
-   :autoload (phpinspect-make-autoloader)
-   :worker 'nil-worker))
-
 (defvar phpinspect-test-directory
   (file-name-directory (macroexp-file-name))
   "Directory that phpinspect tests reside in.")
 
+(defun phpinspect--make-dummy-project (&optional fs project-root)
+  (setq fs (or fs (phpinspect-make-virtual-fs))
+        project-root (or project-root "could never be a real project root"))
+
+  (let ((project (phpinspect--make-project
+                  :root project-root
+                  :fs fs
+                  :autoload (phpinspect-make-autoloader
+                             :fs fs
+                             :project-root-resolver (lambda () project-root))
+                  :worker 'nil-worker)))
+    (setf (phpinspect-autoloader-file-indexer (phpinspect-project-autoload 
project))
+          (phpinspect-project-make-file-indexer project))
+
+    project))
+
 
 (defvar phpinspect-test-php-file-directory
   (expand-file-name "fixtures" phpinspect-test-directory)
diff --git a/test/phpinspect-test.el b/test/phpinspect-test.el
index 3a6c275003..4e8c42cf4b 100644
--- a/test/phpinspect-test.el
+++ b/test/phpinspect-test.el
@@ -398,6 +398,7 @@ class Thing
 (load-file (concat phpinspect-test-directory "/test-toc.el"))
 (load-file (concat phpinspect-test-directory "/test-meta.el"))
 (load-file (concat phpinspect-test-directory "/test-resolve.el"))
+(load-file (concat phpinspect-test-directory "/test-imports.el"))
 
 
 (provide 'phpinspect-test)
diff --git a/test/test-imports.el b/test/test-imports.el
new file mode 100644
index 0000000000..8e0e364f8c
--- /dev/null
+++ b/test/test-imports.el
@@ -0,0 +1,65 @@
+; test-autoload.el --- Unit tests for phpinspect.el  -*- lexical-binding: t; 
-*-
+
+(require 'ert)
+(require 'phpinspect-pipeline)
+(require 'phpinspect-resolve)
+(require 'phpinspect-imports)
+(require 'phpinspect)
+(require 'phpinspect-test-env
+         (expand-file-name "phpinspect-test-env.el"
+                           (file-name-directory (macroexp-file-name))))
+
+(defun phpinspect--make-dummy-composer-project ()
+  (let ((fs (phpinspect-make-virtual-fs)))
+    (phpinspect-virtual-fs-set-file
+      fs
+      "/project/root/composer.json"
+      "{ \"autoload\": { \"psr-4\": {\"App\\\\\": [\"src/\", \"lib\"]}}}")
+
+    (phpinspect-virtual-fs-set-file fs "/project/root/src/Foo.php" "")
+    (phpinspect-virtual-fs-set-file fs "/project/root/src/Bar.php" "")
+
+    (let* ((project (phpinspect--make-dummy-project fs "/project/root"))
+           (autoload (phpinspect-project-autoload project))
+           result error)
+
+      (phpinspect-autoloader-refresh autoload (lambda (res err)
+                                                (setq result res error err)))
+
+      (while (not (or result error))
+        (thread-yield))
+
+      project)))
+
+(ert-deftest phpinspect-fix-imports-single-namespaced-class ()
+  (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;
+
+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;
+
+
+class Baz {
+    private Foo $foo;
+    public Bar $bar;
+}"
+                         (buffer-string)))))))



reply via email to

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