File: test-php.el

package info (click to toggle)
flycheck 36.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,600 kB
  • sloc: lisp: 16,210; python: 718; makefile: 219; cpp: 24; ruby: 23; perl: 21; ada: 17; f90: 16; haskell: 15; javascript: 15; sh: 14; erlang: 14; xml: 14; ansic: 12; php: 9; tcl: 8; fortran: 3; vhdl: 2; awk: 1; sql: 1
file content (125 lines) | stat: -rw-r--r-- 6,205 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
;;; test-php.el --- Flycheck Specs: PHP      -*- lexical-binding: t; -*-

;; Copyright (C) 2016 Sebastian Wiesner and Flycheck contributors

;; This file is not part of GNU Emacs.

;; 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 3 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, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Specs for PHP support.

;;; Code:

(require 'flycheck-buttercup)
(require 'test-helpers)

(describe "Language PHP"
  (describe "The PHDMD error parser"
    (it "parses PHPMD XML output"

      (let ((phpmd-xml  "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<pmd version=\"1.5.0\" timestamp=\"2014-12-02T18:13:44+00:00\">
  <file name=\"foo.php\">
    <violation beginline=\"21\" endline=\"21\" rule=\"UnusedPrivateField\"
      ruleset=\"Unused Code Rules\"
      externalInfoUrl=\"http://phpmd.org/rules/unusedcode.html#unusedprivatefield\"
      priority=\"3\">
        Avoid unused private fields such as '$FOO'.
    </violation>
    <violation beginline=\"24\" endline=\"27\" rule=\"UnusedPrivateMethod\"
      ruleset=\"Unused Code Rules\" package=\"Flycheck\"
      externalInfoUrl=\"http://phpmd.org/rules/unusedcode.html#unusedprivatemethod\"
      class=\"A\" method=\"bar\" priority=\"3\">
        Avoid unused private methods such as 'bar'.
    </violation>
    <violation beginline=\"24\" endline=\"24\" rule=\"UnusedFormalParameter\"
      ruleset=\"Unused Code Rules\"
      externalInfoUrl=\"http://phpmd.org/rules/unusedcode.html#unusedformalparameter\"
      priority=\"3\">
        Avoid unused parameters such as '$baz'.
    </violation>
  </file>
</pmd>"))
        (expect (flycheck-parse-phpmd phpmd-xml 'checker 'buffer)
                :to-be-equal-flycheck-errors
                (list
                 (flycheck-error-new-at 21 nil 'warning
                                        "Avoid unused private fields such as '$FOO'."
                                        :id "UnusedPrivateField"
                                        :checker 'checker
                                        :buffer 'buffer
                                        :filename "foo.php")
                 (flycheck-error-new-at 24 nil 'warning
                                        "Avoid unused private methods such as 'bar'."
                                        :id "UnusedPrivateMethod"
                                        :checker 'checker
                                        :buffer 'buffer
                                        :filename "foo.php")
                 (flycheck-error-new-at 24 nil 'warning
                                        "Avoid unused parameters such as '$baz'."
                                        :id "UnusedFormalParameter"
                                        :checker 'checker
                                        :buffer 'buffer
                                        :filename "foo.php"))))))

  (describe "Checker tests"
    (flycheck-buttercup-def-checker-test php php syntax-error
      (when (version<= emacs-version "25")
        (buttercup-skip "PHP mode (via CC mode) seems broken on 24.5."))
      (flycheck-buttercup-should-syntax-check
       "language/php/syntax-error.php" 'php-mode
       '(8 nil error "Assignments can only happen to writable values" :checker php)))

    (flycheck-buttercup-def-checker-test (php php-phpcs php-phpmd) php nil
      (flycheck-buttercup-should-syntax-check
       "language/php/warnings.php" 'php-mode
       '(1 1 error "Missing file doc comment"
           :id "PEAR.Commenting.FileComment.Missing" :checker php-phpcs)
       '(21 nil warning "Avoid unused private fields such as '$FOO'."
            :id "UnusedPrivateField" :checker php-phpmd)
       '(21 20 error "Private member variable \"FOO\" must be prefixed with an underscore"
            :id "PEAR.NamingConventions.ValidVariableName.PrivateNoUnderscore"
            :checker php-phpcs)
       '(23 5 error "The open comment tag must be the only content on the line"
            :id "Generic.Commenting.DocComment.ContentAfterOpen"
            :checker php-phpcs)
       '(23 5 error "Doc comment for parameter \"$baz\" missing"
            :id "PEAR.Commenting.FunctionComment.MissingParamTag"
            :checker php-phpcs)
       '(23 9 error "Doc comment short description must be on the first line"
            :id "Generic.Commenting.DocComment.SpacingBeforeShort"
            :checker php-phpcs)
       '(23 29 error "The close comment tag must be the only content on the line"
            :id "Generic.Commenting.DocComment.ContentBeforeClose"
            :checker php-phpcs)
       '(23 29 error "Missing @return tag in function comment"
            :id "PEAR.Commenting.FunctionComment.MissingReturn"
            :checker php-phpcs)
       '(24 nil warning "Avoid unused private methods such as 'bar'."
            :id "UnusedPrivateMethod" :checker php-phpmd)
       '(24 nil warning "Avoid unused parameters such as '$baz'."
            :id "UnusedFormalParameter" :checker php-phpmd)
       '(24 13 error "Private method name \"A::bar\" must be prefixed with an underscore"
            :id "PEAR.NamingConventions.ValidFunctionName.PrivateNoUnderscore"
            :checker php-phpcs)
       '(26 nil warning "Avoid variables with short names like $i. Configured minimum length is 3."
            :id "ShortVariable" :checker php-phpmd)
       '(26 nil warning "Avoid unused local variables such as '$i'."
            :id "UnusedLocalVariable" :checker php-phpmd)
       '(26 12 error "TRUE, FALSE and NULL must be lowercase; expected \"false\" but found \"FALSE\""
            :id "Generic.PHP.LowerCaseConstant.Found" :checker php-phpcs)))))

;;; test-php.el ends here