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

Add PHP_CodeSniffer for checking coding standards #45

Merged
merged 1 commit into from
Dec 3, 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
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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"phpcsstandards/php_codesniffer": "^3.7",
"squizlabs/php_codesniffer": "^3.7",

Thank you for your support and your enthousiasm embracing the take-over of the PHP_CodeSniffer package.

In contrast to earlier information, arrangements are now being made to allow the package to continue under its original name on Packagist. The commit (in the new repo) to rename the package has been reverted.

Sorry for the confusion and thank you for understanding. I hope you'll enjoy the 3.8.0 release, which I expect to release this Friday.

"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