Skip to content

Commit 30f29bd

Browse files
committed
Parse the phpcs standards output a little better
Resolves #185
1 parent 439b36c commit 30f29bd

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

phpcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def get_standards_available(self):
272272
args.append("-i")
273273

274274
output = self.shell_out(args)
275-
standards = output[35:].replace("and", ",").strip().split(", ")
275+
standards = output[35:].replace(" and ", ", ").strip().split(", ")
276276
return standards
277277

278278

tests/test_phpcs.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import re
33
import sys
44
import sublime
5-
from unittest import TestCase
65

6+
from unittest import TestCase
7+
from unittest.mock import patch
78

89
from Phpcs.phpcs import Sniffer
910

1011

11-
class TestDiffViewInternalFunctions(TestCase):
12+
class TestSniffer(TestCase):
1213
def test_we_can_build_up_the_correct_executable_string_when_we_prefix(self):
13-
php_path = "/bin/php"
14+
php_path = "/opt/homebrew/bin/php"
1415
s = sublime.load_settings("phpcs.sublime-settings")
1516

1617
s.set("phpcs_php_prefix_path", php_path)
@@ -22,9 +23,20 @@ def test_we_can_build_up_the_correct_executable_string_when_we_prefix(self):
2223
def test_we_can_build_up_the_correct_executable_string_when_we_dont_prefix(self):
2324
s = sublime.load_settings("phpcs.sublime-settings")
2425

25-
s.set("phpcs_php_prefix_path", "/bin/php")
26+
s.set("phpcs_php_prefix_path", "/opt/homebrew/bin/php")
2627
s.set("phpcs_commands_to_php_prefix", "")
2728
s.set("phpcs_executable_path", "")
2829

2930
args = Sniffer().get_executable_args()
3031
self.assertIn("phpcs", args)
32+
33+
@patch("Phpcs.phpcs.Sniffer.shell_out")
34+
def test_we_can_parse_phpcs_standards_output(self, shell_mock):
35+
shell_mock.return_value = (
36+
"The installed coding standards are One, NeutronStandard, Two and Three"
37+
)
38+
standards = Sniffer().get_standards_available()
39+
40+
expected = ["One", "NeutronStandard", "Two", "Three"]
41+
42+
self.assertEqual(expected, standards)

0 commit comments

Comments
 (0)