Skip to content

Commit

Permalink
Parse the phpcs standards output a little better
Browse files Browse the repository at this point in the history
Resolves #185
  • Loading branch information
benmatselby committed Oct 15, 2023
1 parent 439b36c commit 6b5315c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion phpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def get_standards_available(self):
args.append("-i")

output = self.shell_out(args)
standards = output[35:].replace("and", ",").strip().split(", ")
standards = output[35:].replace(" and ", ", ").strip().split(", ")
return standards


Expand Down
20 changes: 16 additions & 4 deletions tests/test_phpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import re
import sys
import sublime
from unittest import TestCase

from unittest import TestCase
from unittest.mock import patch

from Phpcs.phpcs import Sniffer


class TestDiffViewInternalFunctions(TestCase):
class TestSniffer(TestCase):
def test_we_can_build_up_the_correct_executable_string_when_we_prefix(self):
php_path = "/bin/php"
php_path = "/opt/homebrew/bin/php"
s = sublime.load_settings("phpcs.sublime-settings")

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

s.set("phpcs_php_prefix_path", "/bin/php")
s.set("phpcs_php_prefix_path", "/opt/homebrew/bin/php")
s.set("phpcs_commands_to_php_prefix", "")
s.set("phpcs_executable_path", "")

args = Sniffer().get_executable_args()
self.assertIn("phpcs", args)

@patch("Phpcs.phpcs.Sniffer.shell_out")
def test_we_can_parse_phpcs_standards_output(self, shell_mock):
shell_mock.return_value = (
"The installed coding standards are One, NeutronStandard, Two and Three"
)
standards = Sniffer().get_standards_available()

expected = ["One", "NeutronStandard", "Two", "Three"]

self.assertEqual(expected, standards)

0 comments on commit 6b5315c

Please sign in to comment.