Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse the phpcs standards output a little better #212

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading