Skip to content

Commit

Permalink
Merge pull request #53 from nlamirault/develop
Browse files Browse the repository at this point in the history
Release 0.16.0
  • Loading branch information
nlamirault committed Nov 27, 2017
2 parents 5ca5ee5 + 87f1dde commit a137067
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 25 deletions.
9 changes: 9 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# phpunit.el ChangeLog

## Version 0.16.0 (27/11/2017)

- [#52](https://github.com/nlamirault/phpunit.el/pull/52): windows system prohibits the use of stty (tszg)
- [#49](https://github.com/nlamirault/phpunit.el/pull/49): Add option to hide compilation buffer if all tests pass (thanks mallt)
- [#48](https://github.com/nlamirault/phpunit.el/pull/48): Support colorize output (thanks zonuexe)
- [#46](https://github.com/nlamirault/phpunit.el/pull/46): Add custom variables :tag (thanks zonuexe)
- [#45](https://github.com/nlamirault/phpunit.el/pull/45): Add path to current test file for phpunit-current-test (thanks landakram)
- [#44](https://github.com/nlamirault/phpunit.el/pull/44): Add ability to specify a bootstrap file (thanks landakram)

## Version 0.15.0 (02/11/2017)

- [#43](https://github.com/nlamirault/phpunit.el/pull/42): Rename test-helper to phpunit-test-helper (thanks zonuexe)
Expand Down
93 changes: 78 additions & 15 deletions phpunit.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
;; Eric Hansen <hansen.c.eric@gmail.com>
;;
;; URL: https://github.com/nlamirault/phpunit.el
;; Version: 0.15.0
;; Keywords: php, tests, phpunit
;; Version: 0.16.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"))

Expand Down Expand Up @@ -84,7 +84,25 @@

(defcustom phpunit-configuration-file nil
"The PHPUnit configuration file."
:type '(choice string nil))
:type '(choice (file :tag "Path to phpunit.xml[.dist]")
(const :tag "Automatically detect the path of phpunit.xml" nil)))

(defcustom phpunit-bootstrap-file nil
"The PHPUnit bootstrap file."
:type '(choice (file :tag "Path to PHPUnit bootstrap script")
(const :tag "Not specify boostrap script" nil)))

(defcustom phpunit-colorize nil
"Colorize PHPUnit compilation output buffer."
:type '(choice (const :tag "Do not specific --color argument" nil)
(const :tag "--color=auto" "auto")
(const :tag "--color=never" "never")
(const :tag "--color=always" "always")))

(defcustom phpunit-hide-compilation-buffer-if-all-tests-pass nil
"Hide the compilation buffer if all tests pass."
:type 'boolean
:group 'phpunit)

(defconst php-beginning-of-defun-regexp
(eval-when-compile
Expand Down Expand Up @@ -115,11 +133,8 @@
"[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]"
"Valid syntax for a character in a PHP label.")

;; Allow for error navigation after a failed test
(add-hook 'compilation-mode-hook
(lambda ()
(interactive)
(add-to-list 'compilation-error-regexp-alist '("^\\(.+\\.php\\):\\([0-9]+\\)$" 1 2))))
(when phpunit-hide-compilation-buffer-if-all-tests-pass
(add-hook 'compilation-finish-functions 'phpunit--hide-compilation-buffer-if-all-tests-pass))

(defvar phpunit-last-group-cache nil)

Expand Down Expand Up @@ -147,8 +162,13 @@
(s-concat " " (if (stringp phpunit-arg) phpunit-arg
(s-join " " (mapcar 'shell-quote-argument phpunit-arg)))))
(if phpunit-configuration-file
(s-concat " -c " (shell-quote-argument phpunit-configuration-file))
(s-concat " -c " (shell-quote-argument (expand-file-name phpunit-configuration-file)))
"")
(if phpunit-bootstrap-file
(s-concat " --bootstrap " (shell-quote-argument (expand-file-name phpunit-bootstrap-file)))
"")
(when phpunit-colorize
(format " --colors=%s" phpunit-colorize))
" "
args)))

Expand Down Expand Up @@ -224,10 +244,28 @@ https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.anno

(defun phpunit-get-compile-command (args)
"Return command string to execute PHPUnit from `ARGS'."
(let ((column-setting-command (format "stty cols %d" (frame-width)))
(command-separator "; ")
(phpunit-command (phpunit-get-program (phpunit-arguments args))))
(concat column-setting-command command-separator phpunit-command)))
(if (memq system-type '(windows-nt ms-dos))
(phpunit-get-program (phpunit-arguments args))
(let ((column-setting-command (format "stty cols %d" (frame-width)))
(command-separator "; ")
(phpunit-command (phpunit-get-program (phpunit-arguments args))))
(concat column-setting-command command-separator phpunit-command))))

(defun phpunit--colorize-compilation-buffer ()
"Colorize PHPUnit compilation buffer."
(let ((inhibit-read-only t))
(ansi-color-apply-on-region compilation-filter-start (point))))

(defun phpunit--setup-compilation-buffer ()
"Setup hooks for PHPUnit compilation buffer."
(add-hook 'compilation-finish-functions #'phpunit--finish-compilation-buffer)
(add-hook 'compilation-filter-hook #'phpunit--colorize-compilation-buffer))

(defun phpunit--finish-compilation-buffer (&optional cur-buffer msg)
"Setup hooks for PHPUnit compilation buffer.
`CUR-BUFFER' and `MSG' are ignore."
(remove-hook 'compilation-finish-functions #'phpunit--finish-compilation-buffer)
(remove-hook 'compilation-filter-hook #'phpunit--colorize-compilation-buffer))

(defun phpunit--execute (args)
"Execute phpunit command with `ARGS'."
Expand All @@ -236,9 +274,32 @@ https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.anno

(defun phpunit-run (args)
"Execute phpunit command with `ARGS'."
(let ((default-directory (phpunit-get-root-directory)))
(add-to-list 'compilation-error-regexp-alist '("^\\(.+\\.php\\):\\([0-9]+\\)$" 1 2))
(let ((default-directory (phpunit-get-root-directory))
(compilation-process-setup-function #'phpunit--setup-compilation-buffer))
(compile (phpunit-get-compile-command args))))

(defun phpunit--hide-compilation-buffer-if-all-tests-pass (buffer status)
"Hide the compilation BUFFER if all tests pass.
The STATUS describes how the compilation process finished."
(with-current-buffer buffer
(let* ((buffer-string (buffer-substring-no-properties
(point-min) (point-max)))
(buffer-lines (s-lines buffer-string))
(ok-msg (car (cl-remove-if-not
(lambda (x)
(and (s-contains? "OK" x)
(s-contains? "test" x)
(s-contains? "assertion" x)))
buffer-lines)))
(time-msg (car (cl-remove-if-not
(lambda (x)
(and (s-contains? "Time" x)
(s-contains? "Memory" x)))
buffer-lines))))
(when ok-msg
(delete-windows-on buffer)
(message "%s %s" ok-msg time-msg)))))

;; API
;; ----
Expand All @@ -250,7 +311,9 @@ https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.anno
(let ((args (s-concat " --filter '"
(phpunit-get-current-class)
"::"
(phpunit-get-current-test) "'")))
(phpunit-get-current-test) "'"
" "
(s-chop-prefix (phpunit-get-root-directory) buffer-file-name))))
(phpunit-run args)))


Expand Down
7 changes: 2 additions & 5 deletions test/phpunit-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
;;; Code:
(require 'ert)
(require 'f)
(when (boundp 'ert-runner-test-path)
(load (f-expand "phpunit-test-helper.el" ert-runner-test-path) nil :nomessage))

;; (defun phpunit-command (&rest arg)
;; (let ((composer-dir (s-concat (concat (getenv "HOME") "/") ".composer"))
Expand Down Expand Up @@ -118,7 +116,7 @@ class PhpUnitTest extends \\PHPUnit_Framework_TestCase {
:tags '(configuration-file)
(phpunit-test-helper-with-test-sandbox
(let ((phpunit-configuration-file "phpunit.xml"))
(should (s-contains? "-c phpunit.xml"
(should (s-contains? (s-concat "-c " (f-long phpunit-configuration-file))
(phpunit-get-program (phpunit-arguments "")))))))

(ert-deftest test-phpunit-without-configuration-file ()
Expand All @@ -136,10 +134,9 @@ class PhpUnitTest extends \\PHPUnit_Framework_TestCase {
(phpunit-get-program (phpunit-arguments ""))))))

(ert-deftest test-phpunit-add-stop-on-error-argument ()
:tags '(arguments current)
:tags '(arguments)
(phpunit-test-helper-with-test-sandbox
(let ((phpunit-stop-on-error t))
(message "==> %s " (phpunit-get-program (phpunit-arguments "")))
(should (s-suffix? "phpunit --stop-on-error"
(phpunit-get-program (phpunit-arguments "")))))))

Expand Down
4 changes: 1 addition & 3 deletions test/phpunit-version-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
;;; Code:
(require 'ert)
(require 'f)
(when (boundp 'ert-runner-test-path)
(load (f-expand "phpunit-test-helper.el" ert-runner-test-path) nil :nomessage))

(ert-deftest phpunit-mode-library-version ()
:expected-result (if (executable-find "cask") :passed :failed)
Expand All @@ -38,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.15.0" cask-version))))
(should (string= "0.16.0" cask-version))))

(provide 'phpunit-version-test)
;;; phpunit-version-test.el ends here
3 changes: 1 addition & 2 deletions test/phpunit-test-helper.el → test/test-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@
(phpunit-test-helper-load-library "/phpunit.el")
,@body))))

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

0 comments on commit a137067

Please sign in to comment.