|
122 | 122 | (phpstan-replace-path-prefix nil)) |
123 | 123 | (should (equal src (phpstan-normalize-path src)))))))) |
124 | 124 |
|
| 125 | +(ert-deftest phpstan-test-normalize-path-nil () |
| 126 | + "A nil path yields nil rather than erroring, even under a container. |
| 127 | +`phpstan-get-config-file' returns nil when a project has no configuration, |
| 128 | +and a containerized run would otherwise pass that nil to |
| 129 | +`replace-regexp-in-string'." |
| 130 | + (cl-letf (((symbol-function 'php-project-get-root-dir) (lambda () "/proj/"))) |
| 131 | + (let ((phpstan-replace-path-prefix nil)) |
| 132 | + (dolist (exe '(docker container ("docker" "run" "img") nil "/bin/phpstan")) |
| 133 | + (let ((phpstan-executable exe)) |
| 134 | + (should-not (phpstan-normalize-path nil)))) |
| 135 | + ;; The optional SOURCE fallback still applies when it is given. |
| 136 | + (let ((phpstan-executable 'docker)) |
| 137 | + (should (equal "fallback" (phpstan-normalize-path nil "fallback"))))))) |
| 138 | + |
125 | 139 | ;;; Command line construction |
126 | 140 |
|
127 | 141 | (defmacro phpstan-test--with-stubbed-project (&rest body) |
@@ -184,5 +198,16 @@ survive `expand-file-name' on every platform." |
184 | 198 | (should (member (expand-file-name "phpstan.neon" "/app") args)) |
185 | 199 | (should-not (member (phpstan-get-config-file) args)))))) |
186 | 200 |
|
| 201 | +(ert-deftest phpstan-test-command-args-without-config-under-container () |
| 202 | + "A container run with no configuration file must not error. |
| 203 | +`phpstan-get-config-file' returns nil then, and normalizing it used to |
| 204 | +error; the command line should simply omit the `-c' flag." |
| 205 | + (phpstan-test--with-stubbed-project |
| 206 | + (cl-letf (((symbol-function 'phpstan-get-config-file) (lambda () nil))) |
| 207 | + (let ((phpstan-executable 'docker)) |
| 208 | + (let ((args (phpstan-get-command-args :include-executable t))) |
| 209 | + (should-not (member "-c" args)) |
| 210 | + (should (member "analyze" args))))))) |
| 211 | + |
187 | 212 | (provide 'phpstan-test) |
188 | 213 | ;;; phpstan-test.el ends here |
0 commit comments