Skip to content

Commit

Permalink
Add PHP_CodeSniffer for checking coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegrunwell committed Dec 3, 2023
1 parent 8feaae5 commit e7559b6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Coding Standards

on: [pull_request]

jobs:
phpcs:
name: PHP_CodeSniffer
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none

- name: Install Composer dependencies
uses: ramsey/composer-install@v2

- name: Run test suite
run: composer coding-standards
24 changes: 24 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruleset name="Custom ruleset">
<description>Coding standards for PHPUnit Markup Assertions</description>

<!-- Show progress and sniff codes in all reports -->
<arg value="ps"/>

<!-- Check all PHP files in directory tree by default. -->
<arg name="extensions" value="php"/>
<file>.</file>
<exclude-pattern>*/vendor/*</exclude-pattern>

<!-- Default to PSR-12 for coding standards-->
<rule ref="PSR12"/>

<!-- The tests/ directory may use snake_case for test methods -->
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Ensure we're compatible with PHP 5.6+ -->
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.6-"/>
</ruleset>
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"symfony/dom-crawler": "^3.4|^4.4|^5.4|^6.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpcompatibility/php-compatibility": "^9.3",
"phpcsstandards/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^5.2 || ^6.2"
},
"autoload": {
Expand All @@ -33,6 +36,9 @@
}
},
"scripts": {
"coding-standards": [
"phpcs"
],
"test": [
"simple-phpunit --testdox"
],
Expand All @@ -41,12 +47,16 @@
]
},
"scripts-descriptions": {
"coding-standards": "Check coding standards.",
"test": "Run all test suites.",
"test-coverage": "Generate code coverage reports in tests/coverage."
},
"config": {
"preferred-install": "dist",
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"archive": {
"exclude": [
Expand Down
1 change: 1 addition & 0 deletions src/MarkupAssertionsTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Markup assertions for PHPUnit.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/MarkupAssertionsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ public function flattenAttributeArray_should_throw_a_RiskyTestError_if_given_an_
* @testdox getInnerHtmlOfMatchedElements() should retrieve the inner HTML
* @dataProvider provideInnerHtml
*/
public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($markup, $selector, $expected) {
public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($markup, $selector, $expected)
{
$method = new \ReflectionMethod($this, 'getInnerHtmlOfMatchedElements');
$method->setAccessible(true);

Expand Down

0 comments on commit e7559b6

Please sign in to comment.