Skip to content

Add more phpunit sniffs#2854

Merged
Crabcyborg merged 5 commits into
masterfrom
add_more_phpunit_sniffs
Jan 21, 2026
Merged

Add more phpunit sniffs#2854
Crabcyborg merged 5 commits into
masterfrom
add_more_phpunit_sniffs

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 21, 2026

Summary by CodeRabbit

  • New Features

    • Added new code quality checks for PHPUnit test assertions to promote clearer, more explicit test methods.
  • Chores

    • Upgraded PHP support to version 8.4 for test infrastructure.
    • Updated testing library dependencies to latest major versions.
  • Tests

    • Refactored test assertions to use more explicit PHPUnit assertion methods for improved clarity and consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 21, 2026

📝 Walkthrough

Walkthrough

This PR updates PHP tooling versions, introduces two new PHP_CodeSniffer sniffs for PHPUnit assertion modernization (PreferAssertContains and PreferAssertFileExists), enhances an existing sniff to handle negation, updates the ruleset configuration, and refactors multiple test files to use standardized PHPUnit assertion APIs.

Changes

Cohort / File(s) Summary
Dependency and Workflow Updates
.github/workflows/phpunit.yml, composer.json
Updated PHP matrix from 8.0 to 8.4; bumped phpunit-polyfills dev dependency from ^1.0 to ^2.0.
New CodeSniffer PHPUnit Sniffs
phpcs-sniffs/Formidable/Sniffs/PHPUnit/PreferAssertContainsSniff.php, phpcs-sniffs/Formidable/Sniffs/PHPUnit/PreferAssertFileExistsSniff.php
Added two new sniff implementations that automatically refactor assertTrue/assertFalse patterns: PreferAssertContains transforms in_array checks to assertContains/assertNotContains; PreferAssertFileExists transforms file_exists checks to assertFileExists/assertFileDoesNotExist. Both include token parsing, validation, and fix application logic.
Enhanced CodeSniffer Sniff
phpcs-sniffs/Formidable/Sniffs/PHPUnit/PreferAssertStringContainsSniff.php
Extended to handle negation (! str_contains) and optional message arguments; updated applyFix method signature to accept messageArg parameter and logic to flip assertion when negation is detected.
CodeSniffer Configuration
phpcs-sniffs/Formidable/ruleset.xml
Reorganized Code Analysis rules section; added PreferAssertContains and PreferAssertFileExists PHPUnit rules.
Email Tests
tests/phpunit/emails/test_FrmEmail.php
Refactored assertions from strpos-based checks to assertStringContainsString/assertStringNotContainsString for header validation.
Entry Shortcode Tests
tests/phpunit/entries/test_FrmShowEntryShortcode.php
Moved style initialization from constructor to setUp() method for proper per-test lifecycle management.
Field AJAX Tests
tests/phpunit/fields/test_FrmFieldsAjax.php
Updated assertion from strpos-based to assertNotFalse for substring validation.
Form Controller Tests
tests/phpunit/forms/test_FrmFormActionsController.php
Replaced assertTrue(in_array(...)) with assertContains for post type validation.
App Controller/Helper Tests
tests/phpunit/misc/test_FrmAppController.php, tests/phpunit/misc/test_FrmAppHelper.php
Refactored assertions from str_contains/strpos/file_exists boolean checks to assertStringContainsString/assertStringNotContainsString/assertFileExists equivalents.
Styles Controller Tests
tests/phpunit/styles/test_FrmStylesController.php
Replaced strpos checks with assertStringContainsString/assertStringNotContainsString for CSS/HTML content validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 From PHP 8.0 to 8.4 we leap,
New sniffs in place, our code to keep,
Assert Contains, FileExists now shine,
Negations handled, assertions align,
Tests modernized, a pattern so fine!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding new PHP_CodeSniffer sniffs for PHPUnit assertions (PreferAssertContains, PreferAssertFileExists, and updates to PreferAssertStringContains), which is the primary focus of this changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Crabcyborg Crabcyborg merged commit b10a825 into master Jan 21, 2026
16 checks passed
@Crabcyborg Crabcyborg deleted the add_more_phpunit_sniffs branch January 21, 2026 14:42
stephywells pushed a commit that referenced this pull request Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant