diff --git a/phpcs.py b/phpcs.py index 2307a79..0a3aa32 100644 --- a/phpcs.py +++ b/phpcs.py @@ -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 diff --git a/tests/test_phpcs.py b/tests/test_phpcs.py index de7cadf..edef91e 100644 --- a/tests/test_phpcs.py +++ b/tests/test_phpcs.py @@ -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) @@ -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)