diff --git a/ChangeLog.md b/ChangeLog.md index 328577a..67e53e1 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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) diff --git a/phpunit.el b/phpunit.el index d711837..4ba27e9 100644 --- a/phpunit.el +++ b/phpunit.el @@ -4,8 +4,8 @@ ;; Eric Hansen ;; ;; 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")) @@ -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 @@ -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) @@ -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))) @@ -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'." @@ -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 ;; ---- @@ -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))) diff --git a/test/phpunit-test.el b/test/phpunit-test.el index b7f3923..f42ca5f 100644 --- a/test/phpunit-test.el +++ b/test/phpunit-test.el @@ -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")) @@ -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 () @@ -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 ""))))))) diff --git a/test/phpunit-version-test.el b/test/phpunit-version-test.el index 2fb918c..cf61b86 100644 --- a/test/phpunit-version-test.el +++ b/test/phpunit-version-test.el @@ -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) @@ -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 diff --git a/test/phpunit-test-helper.el b/test/test-helper.el similarity index 97% rename from test/phpunit-test-helper.el rename to test/test-helper.el index 1b34dd9..c5ca852 100644 --- a/test/phpunit-test-helper.el +++ b/test/test-helper.el @@ -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