Skip to content

Commit

Permalink
Merge pull request #20 from nlamirault/develop
Browse files Browse the repository at this point in the history
Release 0.9.0
  • Loading branch information
nlamirault committed May 31, 2016
2 parents 443981b + ee18e98 commit 7b2a811
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 34 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# phpunit.el ChangeLog

## Version 0.9.0 (05/31/2016)

- #PR19: Some problem fixes (Tramp, phpunit-get-root-directory,
Use phpunit -c option when set configuration file, ...) (thanks zonuexe)
- Remove keybinding from phpunit-helm

## Version 0.8.0 (05/12/2016)

- #PR16: Create a minor mode (thanks eric-hansen)
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ These functions are available :
You can create some key bindings with these commands:

```lisp
(define-key web-mode-map (kbd "C-x t") 'phpunit-current-test)
(define-key web-mode-map (kbd "C-x c") 'phpunit-current-class)
(define-key web-mode-map (kbd "C-x p") 'phpunit-current-project)
(define-key web-mode-map (kbd "C-t t") 'phpunit-current-test)
(define-key web-mode-map (kbd "C-t c") 'phpunit-current-class)
(define-key web-mode-map (kbd "C-t p") 'phpunit-current-project)
```

or use the minor mode :

```lisp
(add-to-list 'auto-mode-alist '("\\.php$'" . phpunit-mode))
```



### Configuration

The following configuration variables are available:
Expand Down
22 changes: 20 additions & 2 deletions phpunit-mode.el
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
;;; phpunit-mode.el --- Minor mode for PHPUnit

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 2
;; of the License, or (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301, USA.

;;; Commentary:

;;; Code:

(require 'phpunit)

(defvar phpunit-mode-map
(let ((map (make-keymap)))
(define-key map (kbd "C-t f") 'phpunit-helm-function-tests)
(define-key map (kbd "C-t t") 'phpunit-current-test)
(define-key map (kbd "C-t c") 'phpunit-current-class)
(define-key map (kbd "C-t p") 'phpunit-current-project)
map)
"Keymap for PHPUnit minor mode")
"Keymap for PHPUnit minor mode.")

(define-minor-mode phpunit-mode
"PHPUnit minor mode"
Expand Down
47 changes: 27 additions & 20 deletions phpunit.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
;; Eric Hansen <hansen.c.eric@gmail.com>
;;
;; URL: https://github.com/nlamirault/phpunit.el
;; Version: 0.8.0
;; Version: 0.9.0
;; Keywords: php, tests, phpunit

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

;;; License:

;; Copyright (C) 2014, 2015 Nicolas Lamirault <nicolas.lamirault@gmail.com>
;; Copyright (C) 2014, 2015, 2016 Nicolas Lamirault <nicolas.lamirault@gmail.com>

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -41,6 +41,7 @@

;;; Code:

(require 'cl-lib)
(require 's)
(require 'f)

Expand Down Expand Up @@ -78,9 +79,9 @@
:type 'boolean
:group 'phpunit)

(defcustom phpunit-configuration-file "phpunit.xml"
(defcustom phpunit-configuration-file nil
"The PHPUnit configuration file."
:type 'string
:type '(choice string nil)
:group 'phpunit)

(defconst php-beginning-of-defun-regexp
Expand Down Expand Up @@ -118,26 +119,30 @@
;; "vendor/bin/phpunit"))
(unless phpunit-executable
(setq phpunit-executable phpunit-program))
(s-concat phpunit-executable " -c "
(phpunit-get-root-directory)
phpunit-configuration-file
args)
)
)

(defun phpunit-get-root-directory()
(s-concat phpunit-executable
(if phpunit-configuration-file
(s-concat " -c " phpunit-configuration-file)
"")
" "
args)))

(defun phpunit-get-root-directory ()
"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)))
(when filename
(file-truename (or (locate-dominating-file filename phpunit-configuration-file)
"./"))))))


(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 (&optional class-or-path)
"Return the canonical unit test class name associated with the current class or buffer."
Expand Down Expand Up @@ -178,7 +183,9 @@
(concat column-setting-command command-separator phpunit-command)))

(defun phpunit-run (args)
(compile (phpunit-get-compile-command args)))
"Execute phpunit command with `ARGS'."
(let ((default-directory (phpunit-get-root-directory)))
(compile (phpunit-get-compile-command args))))


;; API
Expand Down
28 changes: 22 additions & 6 deletions test/phpunit-test.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; phpunit-test.el --- Tests for phpunit.el

;; Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
;; Copyright (C) 2014, 2015, 2016 Nicolas Lamirault <nicolas.lamirault@gmail.com>

;;; Commentary:

Expand Down Expand Up @@ -31,11 +31,13 @@


(defun phpunit-command (&rest arg)
;;(apply 's-concat "phpunit -c " "phpunit.xml" arg))
(let ((composer-dir (s-concat (concat (getenv "HOME") "/") ".composer")))
(let ((composer-dir (s-concat (concat (getenv "HOME") "/") ".composer"))
(conf (if phpunit-configuration-file
(s-concat "-c " phpunit-configuration-file " ")
"")))
(if (f-dir? composer-dir)
(apply 's-concat composer-dir "/vendor/bin/phpunit -c " "phpunit.xml" arg)
(apply 's-concat "./vendor/bin/phpunit -c " "phpunit.xml" arg))))
(apply 's-concat composer-dir "/vendor/bin/phpunit " conf arg)
(apply 's-concat "./vendor/bin/phpunit " conf arg))))


(ert-deftest test-phpunit-get-class-from-file-path()
Expand All @@ -54,11 +56,25 @@
(phpunit-get-current-class "PhpUnitTest"))))


;; Using configuration file

(ert-deftest test-phpunit-with-configuration-file ()
:tags '(configuration-file)
(with-test-sandbox
(let ((phpunit-configuration-file "phpunit.xml"))
(should (s-contains? "-c phpunit.xml"
(phpunit-get-program (phpunit-arguments "")))))))

(ert-deftest test-phpunit-without-configuration-file ()
:tags '(configuration-file)
(with-test-sandbox
(should-not (s-contains? "-c phpunit.xml"
(phpunit-get-program (phpunit-arguments ""))))))

;; Arguments

(ert-deftest test-phpunit-get-program-without-args ()
:tags '(current arguments)
:tags '(arguments)
(with-test-sandbox
(should (string= (phpunit-command)
(phpunit-get-program (phpunit-arguments ""))))))
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) Nicolas Lamirault <nicolas.lamirault@gmail.com>
;; Copyright (C) 2014, 2015, 2016 Nicolas Lamirault <nicolas.lamirault@gmail.com>

;;; Commentary:

Expand Down Expand Up @@ -37,7 +37,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.8.0" cask-version))))
(should (string= "0.9.0" cask-version))))



Expand Down
2 changes: 1 addition & 1 deletion test/test-helper.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;; test-helper.el --- Test helpers for Phpunit.el

;; Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
;; Copyright (C) 2014, 2015, 2016 Nicolas Lamirault <nicolas.lamirault@gmail.com>

;; Author: Nicolas Lamirault <nicolas.lamirault@chmouel.com>
;; Homepage: https://github.com/nlamirault/phpunit.el
Expand Down

0 comments on commit 7b2a811

Please sign in to comment.