Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e08bcb9
Update: version and dependencies
nlamirault Nov 27, 2017
d130762
Add missing require
zonuexe Dec 5, 2017
45fcae5
Use forward-line instead of next-line
zonuexe Dec 5, 2017
94f7592
Merge pull request #54 from nlamirault/fix/warnings
nlamirault Dec 5, 2017
292e9cb
Add phpunit-executable variable as buffer-local
zonuexe Dec 5, 2017
070d289
Refactor phpunit-get-program function
zonuexe Dec 5, 2017
3a12ad4
Add phpunit-root-directory as buffer local
zonuexe Dec 5, 2017
278391f
Add option to ignore phpunit-root-directory
zonuexe Dec 5, 2017
eb59c99
Add phpunit-set-dir-local-variable command
zonuexe Dec 5, 2017
64b7a1e
Merge pull request #55 from nlamirault/feature/phpunit-executable-var…
nlamirault Dec 5, 2017
b8b377b
Add vendor to .gitignore
zonuexe Dec 5, 2017
f99e1d1
Touch phpunit if there is no phpunit command
zonuexe Dec 5, 2017
5514e34
Merge pull request #56 from nlamirault/fix/test-phpunit-executable
zonuexe Dec 5, 2017
846e5dc
Rename phpunit-program to phpunit-default-program
zonuexe Dec 5, 2017
eb77cae
Allow string/function for phpunit-executable
zonuexe Dec 5, 2017
8784049
Rename phpunit-args and make buffer-local
zonuexe Dec 5, 2017
a8da976
Add document to phpunit-root-directory
zonuexe Dec 5, 2017
f0e3b59
Use unix command instead php -r
zonuexe Dec 6, 2017
464fe66
Merge pull request #57 from nlamirault/rename-variable-names
nlamirault Dec 6, 2017
6762c1b
Fix comment style
zonuexe Dec 16, 2017
044b9ed
quote executable in case path to vendor dir includes spaces.
jflearn Aug 7, 2018
ff89430
Merge pull request #58 from logicbrush/feature/fix_for_spaces_in_proj…
zonuexe Aug 8, 2018
cbb5022
Update: changelog for 0.17.0
zonuexe Aug 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.cask/
/.cask
/vendor
*.elc
elpa
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# phpunit.el ChangeLog

## Version 0.17.0 (09/08/2018)

- [#54](https://github.com/nlamirault/phpunit.el/pull/54): Fix warnings
- [#55](https://github.com/nlamirault/phpunit.el/pull/55): Integrate .dir-locals.el
- [#56](https://github.com/nlamirault/phpunit.el/pull/56): Fix `Makefile` for test
- [#57](https://github.com/nlamirault/phpunit.el/pull/57): Rename variable names
- [#58](https://github.com/nlamirault/phpunit.el/pull/58): Fix for spaces in project path (thanks @jflearn)

## Version 0.16.0 (27/11/2017)

- [#52](https://github.com/nlamirault/phpunit.el/pull/52): windows system prohibits the use of stty (tszg)
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ elpa:
build : elpa $(OBJECTS)

.PHONY: test
test: build
test: build vendor/bin/phpunit
@echo -e "$(OK_COLOR)[$(APP)] Unit tests$(NO_COLOR)"
@$(CASK) exec ert-runner

Expand All @@ -77,7 +77,7 @@ virtual-clean:
.PHONY: clean
clean :
@echo -e "$(OK_COLOR)[$(APP)] Cleanup$(NO_COLOR)"
@rm -fr $(OBJECTS) elpa $(APP)-pkg.el $(APP)-pkg.elc $(ARCHIVE).gz
@rm -fr $(OBJECTS) elpa vendor $(APP)-pkg.el $(APP)-pkg.elc $(ARCHIVE).gz

reset : clean
@rm -rf .cask
Expand All @@ -94,6 +94,9 @@ package: clean pkg-el
gzip $(ARCHIVE)
rm -fr dist

vendor/bin/phpunit:
(test -d "vendor/bin" || mkdir -p "vendor/bin") && touch "vendor/bin/phpunit"

%.elc : %.el
@$(CASK) exec $(EMACS) --no-site-file --no-site-lisp --batch \
$(EMACSFLAGS) \
Expand Down
111 changes: 70 additions & 41 deletions phpunit.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
;; Eric Hansen <[email protected]>
;;
;; URL: https://github.com/nlamirault/phpunit.el
;; Version: 0.16.0
;; Version: 0.17.0
;; Keywords: tools, php, tests, phpunit

;; Package-Requires: ((s "1.9.0") (f "0.16.0") (pkg-info "0.5") (cl-lib "0.5") (emacs "24.3"))
;; Package-Requires: ((s "1.12.0") (f "0.19.0") (pkg-info "0.6") (cl-lib "0.5") (emacs "24.3"))

;;; License:

Expand Down Expand Up @@ -42,6 +42,8 @@
;;; Code:

(require 'cl-lib)
(require 'compile)
(require 'tramp)
(require 's)
(require 'f)
(eval-when-compile
Expand All @@ -54,17 +56,17 @@
:group 'tools
:group 'php)

(defcustom phpunit-program nil
"PHPUnit binary path."
(defcustom phpunit-default-program nil
"PHPUnit command or path to executable file or a function that returns these string."
:type '(choice (file :tag "Path to PHPUnit executable file.")
(function :tag "A function return PHPUnit executable file path.")
(string :tag "PHPUnit command name. (require command in PATH)")))

(defcustom phpunit-arg nil
"Argument to pass to phpunit."
:type '(choice string
(repeat string))
:group 'phpunit)
(defvar phpunit-program)
(make-obsolete-variable 'phpunit-program 'phpunit-default-program "0.18.0")

(defvar phpunit-arg)
(make-obsolete-variable 'phpunit-arg 'phpunit-args "0.18.0")

(defcustom phpunit-stop-on-error nil
"Stop execution upon first error."
Expand Down Expand Up @@ -133,6 +135,19 @@
"[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]"
"Valid syntax for a character in a PHP label.")

;;;###autoload
(progn
(defvar-local phpunit-root-directory nil
"Directory path to execute PHPUnit.")
(put 'phpunit-root-directory 'safe-local-variable #'stringp)
(defvar-local phpunit-args nil
"Argument to pass to phpunit command.")
(put 'phpunit-args 'safe-local-variable #'(lambda (v) (or (stringp v) (listp v))))
(defvar-local phpunit-executable nil
"PHPUnit command or path to executable file.")
(put 'phpunit-executable 'safe-local-variable
#'(lambda (v) (or (null v) (stringp v) (functionp v)))))

(when phpunit-hide-compilation-buffer-if-all-tests-pass
(add-hook 'compilation-finish-functions 'phpunit--hide-compilation-buffer-if-all-tests-pass))

Expand All @@ -141,26 +156,29 @@
;; Commands
;; -----------

(defun phpunit--find-executable (directory)
"Get PHPUnit executable command in `DIRECTORY'."
(let ((executable (or phpunit-executable phpunit-default-program)))
(cond ((stringp executable) executable)
((functionp executable) (funcall executable))
((and directory
(file-exists-p (concat directory "vendor/bin/phpunit")))
(concat directory "vendor/bin/phpunit"))
((executable-find "phpunit") "phpunit")
(t (error "PHPUnit command/package is not installed")))))

(defun phpunit-get-program (args)
"Return the command to launch unit test.
`ARGS' corresponds to phpunit command line arguments."
(let ((phpunit-executable nil)
(filename (or (buffer-file-name) ""))
(vendor-dir (locate-dominating-file "" "vendor")))
(setq phpunit-executable
(cond ((stringp phpunit-program) phpunit-program)
((functionp phpunit-program) (funcall phpunit-program))
((and vendor-dir (file-exists-p (concat vendor-dir "vendor/bin/phpunit")))
(concat vendor-dir "vendor/bin/phpunit"))))
(unless phpunit-executable
(setq phpunit-executable "phpunit"))
(when (file-remote-p phpunit-executable)
(setq phpunit-executable
(tramp-file-name-localname (tramp-dissect-file-name phpunit-executable))))
(s-concat phpunit-executable
(when phpunit-arg
(s-concat " " (if (stringp phpunit-arg) phpunit-arg
(s-join " " (mapcar 'shell-quote-argument phpunit-arg)))))
(let* ((vendor-dir (locate-dominating-file default-directory "vendor"))
(executable (phpunit--find-executable vendor-dir)))
(when (file-remote-p default-directory)
(setq executable
(tramp-file-name-localname (tramp-dissect-file-name executable))))
(s-concat (shell-quote-argument executable)
(when phpunit-args
(s-concat " " (if (stringp phpunit-args) phpunit-args
(s-join " " (mapcar 'shell-quote-argument phpunit-args)))))
(if phpunit-configuration-file
(s-concat " -c " (shell-quote-argument (expand-file-name phpunit-configuration-file)))
"")
Expand All @@ -172,23 +190,22 @@
" "
args)))

(defun phpunit-get-root-directory ()
(defun phpunit-get-root-directory (&optional force-real-path)
"Return the root directory to run tests."
;; The function doesn't detect the root directory when used with
;; tramp mode. In that case, the phpunit-root-directory variable can
;; be set which takes precedence
(if (boundp 'phpunit-root-directory)
phpunit-root-directory
(let ((filename (buffer-file-name)) path)
(cond
((null filename) default-directory)
(phpunit-configuration-file
(file-truename (locate-dominating-file filename phpunit-configuration-file)))
(:else
(cl-loop for file in '("phpunit.xml" "phpunit.xml.dist" ".git" "composer.json")
do (setq path (locate-dominating-file filename file))
if path return (file-truename path)
finally return (file-truename "./")))))))
(or (and (not force-real-path) phpunit-root-directory)
(let ((filename (buffer-file-name)) path)
(cond
((null filename) default-directory)
(phpunit-configuration-file
(file-truename (locate-dominating-file filename phpunit-configuration-file)))
(:else
(cl-loop for file in '("phpunit.xml" "phpunit.xml.dist" ".git" "composer.json")
do (setq path (locate-dominating-file filename file))
if path return (file-truename path)
finally return (file-truename "./")))))))

(defun phpunit-get-current-class ()
"Return the canonical unit test class name associated with the current class or buffer."
Expand All @@ -212,7 +229,7 @@ https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.anno
(goto-char (point-min))
(search-forward "Available test group")
(move-beginning-of-line 1)
(next-line)
(forward-line)
(cl-loop
for line in (s-split "\n" (buffer-substring-no-properties (point) (point-max)))
if (s-starts-with? " - " line)
Expand Down Expand Up @@ -304,6 +321,18 @@ The STATUS describes how the compilation process finished."
;; API
;; ----

;;;###autoload
(defun phpunit-set-dir-local-variable (variable)
"Create project file `.dir-locals.el' and set `VARIABLE' for `phpunit.el'."
(interactive
(list (intern (completing-read "Select variable name: "
'(phpunit-executable phpunit-directory)))))
(add-dir-local-variable nil variable
(read-string
(cl-case variable
('phpunit-executable "Input a command to run PHPUnit: ")
('phpunit-root-directory "Input a directory path to execute PHPUnit: ")))))

;;;###autoload
(defun phpunit-current-test ()
"Launch PHPUnit on curent test."
Expand All @@ -321,7 +350,7 @@ The STATUS describes how the compilation process finished."
(defun phpunit-current-class ()
"Launch PHPUnit on current class."
(interactive)
(phpunit-run (s-chop-prefix (phpunit-get-root-directory) buffer-file-name)))
(phpunit-run (s-chop-prefix (phpunit-get-root-directory t) buffer-file-name)))

;;;###autoload
(defun phpunit-current-project ()
Expand Down
4 changes: 2 additions & 2 deletions test/phpunit-version-test.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; phpunit-version-test.el --- Tests for version information

;; Copyright (C) 2014-2016 Nicolas Lamirault <[email protected]>
;; Copyright (C) 2014-2017 Nicolas Lamirault <[email protected]>

;;; Commentary:

Expand Down Expand Up @@ -36,7 +36,7 @@
;;(message "PHPUnit.el : %s" lib-version)
(message "PHPUnit.el Cask version: %s" cask-version)
;;(should (string= version (phpunit-mode-library-version)))))
(should (string= "0.16.0" cask-version))))
(should (string= "0.17.0" cask-version))))

(provide 'phpunit-version-test)
;;; phpunit-version-test.el ends here