Skip to content
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
13 changes: 13 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: PHP CodeSniffer

on:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
phpcs:
uses: wp-media/workflows/.github/workflows/phpcs.yml@main
13 changes: 13 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: PHPStan

on:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
phpstan:
uses: wp-media/workflows/.github/workflows/phpstan.yml@main
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/*
composer.lock
.phpunit.result.cache
phpcs-report.xml
15 changes: 15 additions & 0 deletions Integration/HttpRequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,22 @@ trait HttpRequestTrait {
*/
private $http_request_counts = [];

/**
* Starts mocking outbound HTTP requests for the current test.
*
* @return void
*/
public function setup_http() {
$this->reset_http();

add_filter( 'pre_http_request', [ $this, 'http_callback' ], 10, 3 );
}

/**
* Stops mocking outbound HTTP requests and fails the test if any request went unmocked.
*
* @return void
*/
public function tear_down_http() {
remove_filter( 'pre_http_request', [ $this, 'http_callback' ], 10 );

Expand Down Expand Up @@ -157,6 +167,11 @@ private function is_response_list( $mock ) {
return array_keys( $mock ) === range( 0, count( $mock ) - 1 );
}

/**
* Clears the state tracked between tests.
*
* @return void
*/
private function reset_http() {
$this->blocked_http_requests = [];
$this->http_request_counts = [];
Expand Down
22 changes: 20 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,23 @@
"vendor/antecedent/patchwork/Patchwork.php"
]
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1",
"php-stubs/wordpress-tests-stubs": "^6.8",
"phpcompatibility/phpcompatibility-wp": "^2.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-mockery": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"szepeviktor/phpstan-wordpress": "^2.0",
"wp-coding-standards/wpcs": "^3"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"scripts": {
"test-unit": "\"vendor/bin/phpunit\" --testsuite unit --colors=always --configuration Tests/Unit/phpunit.xml.dist",
Expand All @@ -40,6 +55,9 @@
"@test-unit",
"@test-integration",
"@test-integration-admin"
]
],
"phpcs": "vendor/bin/phpcs",
"phpcs:fix": "vendor/bin/phpcbf",
"phpstan": "vendor/bin/phpstan analyze --memory-limit=2G"
}
}
37 changes: 37 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WP Media" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>The custom ruleset for WP Media projects</description>
<arg name="basepath" value="."/>

<!--
Scope is intentionally limited to the file(s) already brought up to the WP Media standard
(see issue #39). A job that only `uses:` a reusable workflow cannot carry
`continue-on-error`, so the ruleset is scoped instead of failing CI on the ~20 pre-existing
files that have not been touched yet. Add files here as they are brought up to standard
opportunistically, and widen this to the full source tree (the six root files plus
Integration/, Unit/, Fixtures/, Tests/) once the codebase is fully compliant.
-->
<file>Integration/HttpRequestTrait.php</file>
<exclude-pattern>vendor/*</exclude-pattern>
<arg value="sp"/>
<arg name="colors"/>
<arg name="parallel" value="50"/>
<arg name="extensions" value="php"/>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="7.4-"/>
<config name="minimum_supported_wp_version" value="6.6"/>
<rule ref="WordPress">
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag" />
<exclude name="Squiz.Commenting.FileComment.Missing" />
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties><property name="prefixes" type="array"><element value="wpmedia" /></property></properties>
</rule>
<rule ref="WordPress.Files.FileName">
<properties><property name="strict_class_file_names" value="false" /></properties>
</rule>
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
</ruleset>
Loading
Loading