Skip to content

Commit a0ad141

Browse files
committed
Tests adjusted
1 parent 65e904a commit a0ad141

8 files changed

Lines changed: 61 additions & 25 deletions

File tree

.phpcs.xml.dist

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
<ruleset name="CS">
33
<description>PHPCS MslsMenu configuration</description>
44
<config name="testVersion" value="7.4-"/>
5+
6+
<file>MslsMenu.php</file>
7+
<file>tests/</file>
8+
59
<exclude-pattern>bin/*</exclude-pattern>
6-
<exclude-pattern>tests/*</exclude-pattern>
10+
<exclude-pattern>node_modules/*</exclude-pattern>
711
<exclude-pattern>vendor/*</exclude-pattern>
812

913
<arg value="ps"/>
@@ -13,14 +17,30 @@
1317
<arg name="cache" value=".phpcs.cache"/>
1418

1519
<rule ref="WordPress">
20+
<!-- PSR4 -->
1621
<exclude name="Generic.Commenting.DocComment.MissingShort" />
1722
<exclude name="Squiz.Commenting.FileComment.Missing" />
1823
<exclude name="Squiz.Commenting.ClassComment.Missing" />
1924
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
2025
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
2126
<exclude name="WordPress.Files.FileName" />
22-
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.Found" />
2327
</rule>
2428
<rule ref="WordPress-Extra"/>
2529
<rule ref="WordPress-Docs"/>
30+
<rule ref="PHPCompatibilityWP"/>
31+
32+
<!-- tests/Pest.php intentionally groups the WordPress test doubles in one file. -->
33+
<rule ref="Generic.Files.OneObjectStructurePerFile">
34+
<exclude-pattern>tests/Pest.php</exclude-pattern>
35+
</rule>
36+
37+
<!-- Test doubles mirror the signatures they stand in for, unused params included. -->
38+
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
39+
<exclude-pattern>tests/*</exclude-pattern>
40+
</rule>
41+
42+
<!-- Pest binds its closures to the test case, which this sniff cannot verify statically. -->
43+
<rule ref="PHPCompatibility.FunctionDeclarations.NewClosure.ThisFoundOutsideClass">
44+
<exclude-pattern>tests/*</exclude-pattern>
45+
</rule>
2646
</ruleset>

AGENTS.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
## Build, Test, and Development Commands
1111
- Run `composer install` after cloning to pull dev dependencies.
12-
- `composer test` executes the Pest suite with mocked WordPress APIs.
12+
- `composer qa` runs the full gate: `phpcs`, `phpstan`, then `pest`.
13+
- `composer pest` executes the Pest suite with mocked WordPress APIs.
14+
- `composer phpcs` checks the WordPress coding standards and PHP 7.4 compatibility via `.phpcs.xml.dist`; `composer phpcbf` fixes what can be fixed automatically.
1315
- `composer analyze` runs PHPStan (level 5) against `MslsMenu.php`; keep it passing before pushing.
14-
- `composer coverage` enables Xdebug coverage for pull request evidence.
16+
- `composer pest:coverage` enables Xdebug coverage for pull request evidence.
1517
- `composer build` triggers `bin/git-release.sh`, refreshing `mslsmenu/` and `mslsmenu.zip` for distribution.
1618

1719
## Coding Style & Naming Conventions
@@ -22,12 +24,13 @@
2224
## Testing Guidelines
2325
- Place new specs in `tests/YourFeatureTest.php`; keep case names descriptive (`it('renders menu item')`).
2426
- Stub external WP functions with Brain Monkey setup blocks to keep tests deterministic.
25-
- Run `composer coverage` for behavioral changes and share the summary when coverage changes noticeably.
27+
- Run `composer pest:coverage` for behavioral changes and share the summary when coverage changes noticeably.
28+
- `MslsMenu.php` guards against direct access with `ABSPATH`; `tests/bootstrap.php` defines that constant and then loads the plugin, so the suite must keep using it as its PHPUnit bootstrap.
2629

2730
## Commit & Pull Request Guidelines
2831
- Write short imperative subjects (≈50 chars) such as `Clean menu walker output`; batch related edits together.
2932
- Reference GitHub issues in the body (`Refs #123`) and list the commands you ran.
30-
- PRs should explain the problem, outline the fix, attach UI evidence when relevant, and confirm `composer test` plus `composer analyze`.
33+
- PRs should explain the problem, outline the fix, attach UI evidence when relevant, and confirm `composer qa` passes.
3134

3235
## Release Packaging Tips
3336
- Bump the plugin header version in `MslsMenu.php` and sync the same value into `readme.txt` before building.

MslsMenu.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434

3535
declare( strict_types=1 );
3636

37+
if ( ! defined( 'ABSPATH' ) ) {
38+
exit;
39+
}
40+
3741
/**
3842
* MslsMenu Class
3943
*
@@ -154,7 +158,7 @@ public function add_settings(): void {
154158
*
155159
* @param array $args
156160
*/
157-
public function theme_location( array $args ) {
161+
public function theme_location( array $args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Signature is dictated by add_settings_field().
158162
$menu_locations = get_nav_menu_locations();
159163
$theme_locations = $this->options->mslsmenu_theme_location ?? '';
160164
$options = array(

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ MslsMenu extends the Multisite Language Switcher by injecting a language picker
1515
- Configure Multisite Language Switcher as usual; MslsMenu reuses its site mappings automatically.
1616

1717
## Develop
18-
- `composer install` pulls dev tools (Pest, PHPStan, Brain Monkey).
19-
- `composer test` runs the Pest suite; `composer analyze` performs static analysis.
18+
- `composer install` pulls dev tools (Pest, PHPStan, PHP_CodeSniffer, Brain Monkey).
19+
- `composer qa` runs the full gate: coding standards, static analysis, then the Pest suite.
20+
- `composer pest`, `composer phpcs` and `composer phpstan` run the individual steps; `composer phpcbf` auto-fixes coding-standard violations.
2021

2122
## Contribute
2223
- Review `AGENTS.md` for project conventions and release steps.

composer.json

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@
1010
},
1111
"require-dev": {
1212
"pestphp/pest": "^1.22",
13-
"brain/monkey": "2.*",
14-
"phpstan/phpstan": "^1.8",
15-
"szepeviktor/phpstan-wordpress": "^1.1",
16-
"phpstan/extension-installer": "^1.1",
13+
"brain/monkey": "^2.7.0",
14+
"phpstan/phpstan": "^2.2.0",
15+
"phpstan/extension-installer": "^1.4",
16+
"szepeviktor/phpstan-wordpress": "^2.0.0",
17+
"squizlabs/php_codesniffer": "^3.9",
18+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
19+
"wp-coding-standards/wpcs": "^3.1",
20+
"phpcompatibility/phpcompatibility-wp": "^2.1",
1721
"lloc/composer-i18n-scripts": "^1.0"
1822
},
19-
"autoload-dev": {
20-
"files": [ "MslsMenu.php" ]
21-
},
2223
"scripts": {
23-
"test": "vendor/bin/pest",
24-
"coverage": "php -d xdebug.mode=coverage vendor/bin/pest --coverage",
24+
"phpcs": "phpcs",
25+
"phpcbf": "phpcbf",
26+
"phpstan": "vendor/bin/phpstan analyze --memory-limit=2G",
27+
"pest": "vendor/bin/pest",
28+
"qa": [
29+
"@phpcs",
30+
"@phpstan",
31+
"@pest"
32+
],
33+
"pest:coverage": "php -d xdebug.mode=coverage vendor/bin/pest --coverage",
2534
"analyze": "vendor/bin/phpstan analyze",
2635
"git-release": "bin/git-release.sh",
2736
"build": [
@@ -47,6 +56,7 @@
4756
"allow-plugins": {
4857
"composer/installers": true,
4958
"phpstan/extension-installer": true,
59+
"dealerdirect/phpcodesniffer-composer-installer": true,
5060
"pestphp/pest-plugin": true,
5161
"lloc/composer-i18n-scripts": true
5262
}

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
4+
bootstrap="tests/bootstrap.php"
55
colors="true"
66
>
77
<testsuites>

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: realloc
44
Donate link: http://www.greenpeace.org/international/
55
Tags: multilingual, multisite, language, switcher, menu
66
Requires at least: 5.3
7-
Tested up to: 6.9
7+
Tested up to: 7.0
88
Requires PHP: 7.4
99
Stable tag: 2.5.1
1010
License: GPLv2 or later

tests/Pest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class Options {
55
public static function instance() {
66
return new self();
77
}
8-
98
}
109

1110
class Admin {
@@ -17,10 +16,9 @@ public static function init() {
1716

1817
class Link {
1918

20-
public static function get_types_description() {
21-
return [];
19+
public static function get_types_description() {
20+
return array();
2221
}
23-
2422
}
2523

2624
class Output {
@@ -30,7 +28,7 @@ public static function init() {
3028
}
3129

3230
public function get( $display, $filter = false, $exists = false ) {
33-
return [ 'de', 'en' ];
31+
return array( 'de', 'en' );
3432
}
3533
}
3634

0 commit comments

Comments
 (0)