Skip to content

Commit 3d17b2a

Browse files
Merge pull request #45 from stevegrunwell/feature/phpcs
Add PHP_CodeSniffer for checking coding standards
2 parents 8feaae5 + e7559b6 commit 3d17b2a

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Coding Standards
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
phpcs:
7+
name: PHP_CodeSniffer
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
13+
- name: Setup PHP
14+
uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: '8.2'
17+
coverage: none
18+
19+
- name: Install Composer dependencies
20+
uses: ramsey/composer-install@v2
21+
22+
- name: Run test suite
23+
run: composer coding-standards

.phpcs.xml.dist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Custom ruleset">
3+
<description>Coding standards for PHPUnit Markup Assertions</description>
4+
5+
<!-- Show progress and sniff codes in all reports -->
6+
<arg value="ps"/>
7+
8+
<!-- Check all PHP files in directory tree by default. -->
9+
<arg name="extensions" value="php"/>
10+
<file>.</file>
11+
<exclude-pattern>*/vendor/*</exclude-pattern>
12+
13+
<!-- Default to PSR-12 for coding standards-->
14+
<rule ref="PSR12"/>
15+
16+
<!-- The tests/ directory may use snake_case for test methods -->
17+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
18+
<exclude-pattern>tests/*</exclude-pattern>
19+
</rule>
20+
21+
<!-- Ensure we're compatible with PHP 5.6+ -->
22+
<rule ref="PHPCompatibility"/>
23+
<config name="testVersion" value="5.6-"/>
24+
</ruleset>

composer.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"symfony/dom-crawler": "^3.4|^4.4|^5.4|^6.0"
2121
},
2222
"require-dev": {
23+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
24+
"phpcompatibility/php-compatibility": "^9.3",
25+
"phpcsstandards/php_codesniffer": "^3.7",
2326
"symfony/phpunit-bridge": "^5.2 || ^6.2"
2427
},
2528
"autoload": {
@@ -33,6 +36,9 @@
3336
}
3437
},
3538
"scripts": {
39+
"coding-standards": [
40+
"phpcs"
41+
],
3642
"test": [
3743
"simple-phpunit --testdox"
3844
],
@@ -41,12 +47,16 @@
4147
]
4248
},
4349
"scripts-descriptions": {
50+
"coding-standards": "Check coding standards.",
4451
"test": "Run all test suites.",
4552
"test-coverage": "Generate code coverage reports in tests/coverage."
4653
},
4754
"config": {
4855
"preferred-install": "dist",
49-
"sort-packages": true
56+
"sort-packages": true,
57+
"allow-plugins": {
58+
"dealerdirect/phpcodesniffer-composer-installer": true
59+
}
5060
},
5161
"archive": {
5262
"exclude": [

src/MarkupAssertionsTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Markup assertions for PHPUnit.
45
*

tests/MarkupAssertionsTraitTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ public function flattenAttributeArray_should_throw_a_RiskyTestError_if_given_an_
268268
* @testdox getInnerHtmlOfMatchedElements() should retrieve the inner HTML
269269
* @dataProvider provideInnerHtml
270270
*/
271-
public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($markup, $selector, $expected) {
271+
public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML($markup, $selector, $expected)
272+
{
272273
$method = new \ReflectionMethod($this, 'getInnerHtmlOfMatchedElements');
273274
$method->setAccessible(true);
274275

0 commit comments

Comments
 (0)