Skip to content

Update rector config to actually fix issues in tests#2978

Merged
Crabcyborg merged 4 commits into
masterfrom
update_rector_to_actually_cover_tests
Feb 24, 2026
Merged

Update rector config to actually fix issues in tests#2978
Crabcyborg merged 4 commits into
masterfrom
update_rector_to_actually_cover_tests

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Looks like none of our Rector tests were working because it didn't identify our classes as PHPUnit class children.

Summary by CodeRabbit

Release Notes

  • Tests

    • Modernized unit test assertions with PHPUnit native methods for improved code clarity and type safety.
  • Chores

    • Updated test infrastructure with PHPUnit bootstrap configuration and Rector rules to enhance code quality standards.
    • Added test stub classes for better PHPUnit integration.
    • Simplified constant expression in anti-spam validation logic.

@coderabbitai

coderabbitai Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Crabcyborg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 22 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 155cf2d and ef327c9.

📒 Files selected for processing (16)
  • rector.php
  • tests/phpunit/database/test_FrmMigrate.php
  • tests/phpunit/emails/test_FrmEmailSummaryHelper.php
  • tests/phpunit/entries/test_FrmEntry.php
  • tests/phpunit/entries/test_FrmEntryValidate.php
  • tests/phpunit/fields/test_FrmField.php
  • tests/phpunit/fields/test_FrmFieldGridHelper.php.php
  • tests/phpunit/form-templates/test_FrmFormTemplatesController.php
  • tests/phpunit/forms/test_FrmFormsController.php
  • tests/phpunit/misc/test_FrmAddon.php
  • tests/phpunit/misc/test_FrmAntiSpam.php
  • tests/phpunit/misc/test_FrmAppHelper.php
  • tests/phpunit/misc/test_FrmMisc.php
  • tests/phpunit/styles/test_FrmStyleApi.php
  • tests/phpunit/styles/test_FrmStylesController.php
  • tests/phpunit/styles/test_FrmStylesHelper.php
📝 Walkthrough

Walkthrough

The PR refactors test assertions across the codebase to use PHPUnit-specific assertion methods (such as assertEmpty(), assertArrayHasKey(), assertInstanceOf()) instead of generic assertTrue() checks, adds test infrastructure via stub classes, configures Rector rules for automated code quality enforcement, and includes a minor constant expression simplification in production code.

Changes

Cohort / File(s) Summary
Production Code
classes/models/FrmAntiSpam.php
Simplified constant expression by replacing 1 * DAY_IN_SECONDS with DAY_IN_SECONDS.
Configuration & Infrastructure
rector.php, stubs.php
Added PHPUnit-related Rector rules (DeclareStrictTypesTestsRector, FinalizeTestCaseClassRector, PrivatizeFinalClassPropertyRector, StringClassNameToClassConstantRector) to configuration and introduced two base test case stub classes (WP_UnitTestCase_Base and WP_UnitTestCase) for test infrastructure.
Test Assertion Refactoring — Applications & Database
tests/phpunit/applications/test_FrmApplicationsController.php, tests/phpunit/database/test_FrmMigrate.php
Updated assertions to cast HTML/object outputs to string and replaced type checks with specialized PHPUnit methods (assertInstanceOf, assertArrayHasKey).
Test Assertion Refactoring — Emails
tests/phpunit/emails/test_FrmEmail.php, tests/phpunit/emails/test_FrmEmailSummaryHelper.php
Replaced isset/instanceof checks with assertArrayHasKey and assertInstanceOf; added string casting for header and message content validation.
Test Assertion Refactoring — Entries & Fields
tests/phpunit/entries/test_FrmEntry.php, tests/phpunit/entries/test_FrmEntryValidate.php, tests/phpunit/fields/test_FrmField.php, tests/phpunit/fields/test_FrmFieldFormHtml.php, tests/phpunit/fields/test_FrmFieldGridHelper.php.php, tests/phpunit/fields/test_FrmFieldName.php, tests/phpunit/fields/test_FrmFieldValidate.php
Replaced assertTrue(empty) with assertEmpty/assertNotEmpty; replaced isset/instanceof with assertArrayHasKey/assertInstanceOf; added string casting for HTML assertions.
Test Assertion Refactoring — Forms & Templates
tests/phpunit/form-templates/test_FrmFormTemplatesController.php, tests/phpunit/forms/test_FrmForm.php, tests/phpunit/forms/test_FrmFormsController.php, tests/phpunit/forms/test_FrmOnSubmitAction.php
Updated assertions to use assertArrayHasKey for key checks and cast outputs to string; replaced empty/instanceof checks with dedicated assertion methods.
Test Assertion Refactoring — Miscellaneous
tests/phpunit/misc/test_FrmAddon.php, tests/phpunit/misc/test_FrmAntiSpam.php, tests/phpunit/misc/test_FrmAppController.php, tests/phpunit/misc/test_FrmAppHelper.php, tests/phpunit/misc/test_FrmCSVExportHelper.php, tests/phpunit/misc/test_FrmHooksController.php, tests/phpunit/misc/test_FrmMisc.php, tests/phpunit/misc/test_FrmSimpleBlocksController.php, tests/phpunit/misc/test_FrmSpamCheckDenylist.php
Replaced assertTrue/assertFalse(empty/isset) with assertEmpty/assertNotEmpty/assertArrayHasKey; replaced boolean comparisons with assertGreaterThanOrEqual/assertLessThanOrEqual/assertNotSame; added string casting for content checks.
Test Assertion Refactoring — Styles & XML
tests/phpunit/styles/test_FrmStyleApi.php, tests/phpunit/styles/test_FrmStylesController.php, tests/phpunit/styles/test_FrmStylesHelper.php, tests/phpunit/xml/test_FrmXMLHelper.php
Updated assertions to use assertArrayHasKey and assertNotEmpty; added string casting for URL and content validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Poem

🐰 Assertions now hop with PHPUnit grace,
No more empty() checks in this test space!
From assertTrue to assertEmpty we bound,
Type-safe string casts all around,
Our tests now squeak with clarity bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.04% 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 clearly and accurately describes the main objective of the PR: updating the Rector configuration to fix issues in tests by ensuring Rector can identify PHPUnit classes.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update_rector_to_actually_cover_tests

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.

@deepsource-io

deepsource-io Bot commented Feb 24, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in ea804cb...ef327c9 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade  

Focus Area: Security
Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Feb 24, 2026 7:39p.m. Review ↗
JavaScript Feb 24, 2026 7:39p.m. Review ↗

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 8

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tests/phpunit/fields/test_FrmFieldValidate.php (1)

183-234: ⚠️ Potential issue | 🟡 Minor

Fix typo on line 198: "Email email" should be "Empty email".

The assertion on line 198 contains a typo in the failure message: 'Email email passed required validation' should be 'Empty email passed required validation' to accurately describe the test case checking that an empty value fails validation for a required email field.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/phpunit/fields/test_FrmFieldValidate.php` around lines 183 - 234, In
test_email_value(), fix the failure message for the required-email assertion by
replacing the typo "Email email passed required validation" with "Empty email
passed required validation" so the assertArrayHasKey call for
$this->check_single_value( array( $field->id => '' ) ) accurately describes the
test case in the method test_email_value.
tests/phpunit/misc/test_FrmAppHelper.php (1)

572-576: ⚠️ Potential issue | 🟠 Major

Fix PHPCS spacing in assertLessThanOrEqual.

Line 576 fails PHPCS because the function call is missing spaces after the opening parenthesis and before the closing parenthesis.

🔧 Suggested fix
-		$this->assertLessThanOrEqual(70, strlen( $unique_key ));
+		$this->assertLessThanOrEqual( 70, strlen( $unique_key ) );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/phpunit/misc/test_FrmAppHelper.php` around lines 572 - 576, The PHPCS
spacing error is caused by the assertLessThanOrEqual call missing spaces after
the opening parenthesis and before the closing parenthesis; update the test
assertion line that calls $this->assertLessThanOrEqual(70, strlen( $unique_key
)); (which follows the FrmAppHelper::get_unique_key call) so it uses proper
spacing inside the parentheses (space after '(' and before ')') to satisfy
PHPCS.
🧹 Nitpick comments (2)
tests/phpunit/forms/test_FrmOnSubmitAction.php (1)

46-47: assertNotEmpty is redundant; consider assertArrayHasKey instead.

assertNotEmpty($post_content['success_url']) adds no coverage beyond the assertSame on the next line — any empty or wrong value is already caught there. A more useful guard would be assertArrayHasKey, which both avoids a potential undefined-index notice and produces a clearer failure message for the distinct case where the key itself is absent.

♻️ Proposed refactor
-		$this->assertNotEmpty( $post_content['success_url'] );
+		$this->assertArrayHasKey( 'success_url', $post_content );
 		$this->assertSame( 'https://example.com/?param=[' . $field_id . ' sanitize_url=1]', $post_content['success_url'] );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/phpunit/forms/test_FrmOnSubmitAction.php` around lines 46 - 47, The
test uses assertNotEmpty($post_content['success_url']) which is redundant and
risky if the key is missing; replace that assertion with
assertArrayHasKey('success_url', $post_content) to explicitly verify the array
contains the key before the subsequent assertSame check (refer to $post_content,
'success_url', assertNotEmpty, assertArrayHasKey, and assertSame in
test_FrmOnSubmitAction.php).
tests/phpunit/forms/test_FrmForm.php (1)

63-66: Tighten the “deleted form” assertion.
assertNotInstanceOf(\stdClass::class, …) passes for any non‑stdClass value (arrays, WP_Error, etc.), which can allow false positives if FrmForm::getOne ever returns another non‑empty type. If the contract is falsy on missing, assert that explicitly (or use assertEmpty) to keep the deletion check strict.

Possible tightening (adjust to the actual contract)
-			$this->assertNotInstanceOf( \stdClass::class, $form_exists, 'Failed to delete form ' . $form->form_key );
+			$this->assertEmpty( $form_exists, 'Failed to delete form ' . $form->form_key );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/phpunit/forms/test_FrmForm.php` around lines 63 - 66, The test
currently uses assertNotInstanceOf(\stdClass::class, $form_exists) which is too
loose; change the assertion to explicitly check the expected "missing" contract
from FrmForm::getOne after calling FrmForm::destroy($form->id). Locate the
destroy/getOne sequence (FrmForm::destroy and FrmForm::getOne) and replace the
assertNotInstanceOf with a strict assertion matching the contract — for example
use $this->assertEmpty($form_exists, ...) or $this->assertFalse($form_exists,
...) (or assertNull if getOne returns null) to ensure the deleted form is
explicitly falsy.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/phpunit/emails/test_FrmEmailSummaryHelper.php`:
- Around line 16-18: The failing PHPCS spacing is due to missing spaces inside
function call parentheses for the assertion calls (e.g.,
assertArrayHasKey('last_monthly', $options)), so update each Rector-generated
call in test_FrmEmailSummaryHelper.php (and similar occurrences in
test_FrmAddon.php and test_FrmField.php) to include a space after the opening
parenthesis and before the closing parenthesis for the function names like
assertArrayHasKey, assertTrue, etc.; make the changes consistently across all
four lines shown and any other occurrences, and then run PHPCS to confirm the
PEAR.Functions.FunctionCallSignature rule is satisfied.

In `@tests/phpunit/entries/test_FrmEntryValidate.php`:
- Around line 276-279: PHPCS flagged missing spaces inside the PHPUnit
assertions; update the calls to assertArrayNotHasKey and assertArrayHasKey so
they have a single space after the opening parenthesis and before the closing
parenthesis (e.g. around the arguments referencing $fields[$key]->id and
$fields['radio_5']->id and the $values['item_meta'] array) to satisfy spacing
rules; modify the calls in the test_FrmEntryValidate.php block where
assertArrayNotHasKey($fields[ $key ]->id, $values['item_meta']) and
assertArrayHasKey($fields['radio_5']->id, $values['item_meta']) appear so
spacing conforms to PHPCS.

In `@tests/phpunit/fields/test_FrmFieldGridHelper.php.php`:
- Around line 111-112: Fix PHPCS spacing for the assertInstanceOf calls by
adding a space after the opening parenthesis and before the closing parenthesis
in the assertion invocation(s); update the calls to assertInstanceOf (and any
similar assertions like the one on lines referenced) so they use the form
assertInstanceOf( <Type>::class, $this->section_helper ); ensuring you adjust
both occurrences (the current assertInstanceOf and the similar assertion at the
other mentioned location).

In `@tests/phpunit/fields/test_FrmFieldValidate.php`:
- Line 198: Fix the typo in the assertion message for the validation test:
update the message passed to $this->assertArrayHasKey that currently reads
'Email email passed required validation ...' to instead read 'Empty email passed
required validation ...', keeping the rest of the message (including
concatenation with print_r($errors, 1)) and references to 'field' . $field->id
and $errors unchanged.

In `@tests/phpunit/misc/test_FrmAddon.php`:
- Line 32: PHPCS is flagging spacing on the test assertion; open the call to
assertArrayHasKey in the test_FrmAddon.php test and fix the spacing so it
matches coding standards (no extra spaces after the opening parenthesis and
exactly one space after the comma between 'signature' and $plugins) for the
method call $this->assertArrayHasKey('signature', $plugins); then run
phpcbf/phpcs to auto-fix or confirm the change.
- Around line 13-14: The test constructs a mock for FrmTestAddon using
getMockBuilder but includes a no-op call to setMethods() which is
deprecated/removed; remove the ->setMethods() call from the chain so the mock is
built as $this->getMockBuilder('FrmTestAddon')->getMock() (i.e., locate the
getMockBuilder('FrmTestAddon') call in tests/phpunit/misc/test_FrmAddon.php and
delete the setMethods() invocation).

In `@tests/phpunit/misc/test_FrmAntiSpam.php`:
- Line 22: Update the PHPCS spacing in the assertion calls so there is a space
after the opening parenthesis and before the closing parenthesis of the
assertion method; e.g. change the assertGreaterThanOrEqual call to use
$this->assertGreaterThanOrEqual( 32, strlen( $token_string ) ); and make the
same spacing adjustment for the other assertion occurrences on the same file
(the other two assertion calls referenced on lines 31 and 40).

In `@tests/phpunit/styles/test_FrmStylesHelper.php`:
- Around line 12-18: The PHPCS failure is caused by missing spaces inside the
assertArrayHasKey call; update the assertion to include a space after the
opening parenthesis and before the closing parenthesis so it reads
$this->assertArrayHasKey( 'baseurl', $base ); while leaving the surrounding test
logic (the FrmStylesHelper::get_upload_base() calls and subsequent assertions)
unchanged.

---

Outside diff comments:
In `@tests/phpunit/fields/test_FrmFieldValidate.php`:
- Around line 183-234: In test_email_value(), fix the failure message for the
required-email assertion by replacing the typo "Email email passed required
validation" with "Empty email passed required validation" so the
assertArrayHasKey call for $this->check_single_value( array( $field->id => '' )
) accurately describes the test case in the method test_email_value.

In `@tests/phpunit/misc/test_FrmAppHelper.php`:
- Around line 572-576: The PHPCS spacing error is caused by the
assertLessThanOrEqual call missing spaces after the opening parenthesis and
before the closing parenthesis; update the test assertion line that calls
$this->assertLessThanOrEqual(70, strlen( $unique_key )); (which follows the
FrmAppHelper::get_unique_key call) so it uses proper spacing inside the
parentheses (space after '(' and before ')') to satisfy PHPCS.

---

Nitpick comments:
In `@tests/phpunit/forms/test_FrmForm.php`:
- Around line 63-66: The test currently uses
assertNotInstanceOf(\stdClass::class, $form_exists) which is too loose; change
the assertion to explicitly check the expected "missing" contract from
FrmForm::getOne after calling FrmForm::destroy($form->id). Locate the
destroy/getOne sequence (FrmForm::destroy and FrmForm::getOne) and replace the
assertNotInstanceOf with a strict assertion matching the contract — for example
use $this->assertEmpty($form_exists, ...) or $this->assertFalse($form_exists,
...) (or assertNull if getOne returns null) to ensure the deleted form is
explicitly falsy.

In `@tests/phpunit/forms/test_FrmOnSubmitAction.php`:
- Around line 46-47: The test uses assertNotEmpty($post_content['success_url'])
which is redundant and risky if the key is missing; replace that assertion with
assertArrayHasKey('success_url', $post_content) to explicitly verify the array
contains the key before the subsequent assertSame check (refer to $post_content,
'success_url', assertNotEmpty, assertArrayHasKey, and assertSame in
test_FrmOnSubmitAction.php).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea804cb and 155cf2d.

📒 Files selected for processing (31)
  • classes/models/FrmAntiSpam.php
  • rector.php
  • stubs.php
  • tests/phpunit/applications/test_FrmApplicationsController.php
  • tests/phpunit/database/test_FrmMigrate.php
  • tests/phpunit/emails/test_FrmEmail.php
  • tests/phpunit/emails/test_FrmEmailSummaryHelper.php
  • tests/phpunit/entries/test_FrmEntry.php
  • tests/phpunit/entries/test_FrmEntryValidate.php
  • tests/phpunit/fields/test_FrmField.php
  • tests/phpunit/fields/test_FrmFieldFormHtml.php
  • tests/phpunit/fields/test_FrmFieldGridHelper.php.php
  • tests/phpunit/fields/test_FrmFieldName.php
  • tests/phpunit/fields/test_FrmFieldValidate.php
  • tests/phpunit/form-templates/test_FrmFormTemplatesController.php
  • tests/phpunit/forms/test_FrmForm.php
  • tests/phpunit/forms/test_FrmFormsController.php
  • tests/phpunit/forms/test_FrmOnSubmitAction.php
  • tests/phpunit/misc/test_FrmAddon.php
  • tests/phpunit/misc/test_FrmAntiSpam.php
  • tests/phpunit/misc/test_FrmAppController.php
  • tests/phpunit/misc/test_FrmAppHelper.php
  • tests/phpunit/misc/test_FrmCSVExportHelper.php
  • tests/phpunit/misc/test_FrmHooksController.php
  • tests/phpunit/misc/test_FrmMisc.php
  • tests/phpunit/misc/test_FrmSimpleBlocksController.php
  • tests/phpunit/misc/test_FrmSpamCheckDenylist.php
  • tests/phpunit/styles/test_FrmStyleApi.php
  • tests/phpunit/styles/test_FrmStylesController.php
  • tests/phpunit/styles/test_FrmStylesHelper.php
  • tests/phpunit/xml/test_FrmXMLHelper.php

Comment thread tests/phpunit/emails/test_FrmEmailSummaryHelper.php Outdated
Comment thread tests/phpunit/entries/test_FrmEntryValidate.php Outdated
Comment thread tests/phpunit/fields/test_FrmFieldGridHelper.php.php Outdated

$errors = $this->check_single_value( array( $field->id => '' ) );
$this->assertTrue( isset( $errors[ 'field' . $field->id ] ), 'Email email passed required validation ' . print_r( $errors, 1 ) );
$this->assertArrayHasKey( 'field' . $field->id, $errors, 'Email email passed required validation ' . print_r( $errors, 1 ) );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Typo in error message: "Email email" → "Empty email".

-		$this->assertArrayHasKey( 'field' . $field->id, $errors, 'Email email passed required validation ' . print_r( $errors, 1 ) );
+		$this->assertArrayHasKey( 'field' . $field->id, $errors, 'Empty email passed required validation ' . print_r( $errors, 1 ) );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$this->assertArrayHasKey( 'field' . $field->id, $errors, 'Email email passed required validation ' . print_r( $errors, 1 ) );
$this->assertArrayHasKey( 'field' . $field->id, $errors, 'Empty email passed required validation ' . print_r( $errors, 1 ) );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/phpunit/fields/test_FrmFieldValidate.php` at line 198, Fix the typo in
the assertion message for the validation test: update the message passed to
$this->assertArrayHasKey that currently reads 'Email email passed required
validation ...' to instead read 'Empty email passed required validation ...',
keeping the rest of the message (including concatenation with print_r($errors,
1)) and references to 'field' . $field->id and $errors unchanged.

Comment on lines +13 to 14
$this->addon = $this->getMockBuilder( 'FrmTestAddon' )->setMethods()
->getMock();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the required/installed PHPUnit version
rg -i 'phpunit' composer.json -A 2 -B 2

Repository: Strategy11/formidable-forms

Length of output: 234


🌐 Web query:

PHPUnit MockBuilder setMethods deprecated removed version timeline

💡 Result:

PHPUnit MockBuilder::setMethods() deprecation/removal timeline

  • Introduced replacements in PHPUnit 8 (2019): onlyMethods() (mock existing methods) and addMethods() (mock non-existing methods) were added as the intended split of setMethods() responsibilities (see PR #3687 referenced by multiple downstream projects). [2]
  • Deprecated in PHPUnit 8.3.0: MockBuilder::setMethods() was deprecated (but it notably did not always emit a deprecation warning at runtime, which caused confusion). [1]
  • Removed in PHPUnit 10.0: MockBuilder::setMethods() no longer exists; you must migrate to onlyMethods() and/or addMethods() (or drop the call if unnecessary). [1][2]

Migration mapping

  • setMethods(['a','b'])onlyMethods(['a','b']) (when methods exist) [3]
  • If you previously used setMethods() to “mock” methods that don’t exist on the class, use addMethods([...]) instead. [3]

Sources: Moodle upgrade notes [1], Drupal issue referencing PR #3687 and removal in PHPUnit 10 [2], PHPUnit manual (onlyMethods() / addMethods()) [3].


🏁 Script executed:

#!/bin/bash
# Get the full composer.json to find PHPUnit version
cat composer.json | jq '.require, .require-dev' 2>/dev/null || head -100 composer.json

Repository: Strategy11/formidable-forms

Length of output: 1408


🏁 Script executed:

#!/bin/bash
# Also check composer.lock for installed PHPUnit version
rg '"name": "phpunit' composer.lock -A 2 | head -20

Repository: Strategy11/formidable-forms

Length of output: 124


🏁 Script executed:

#!/bin/bash
# Find phpunit configuration
fd -name 'phpunit.xml*'

Repository: Strategy11/formidable-forms

Length of output: 301


🏁 Script executed:

#!/bin/bash
# Check the test file to understand what setMethods() is doing
cat -n tests/phpunit/misc/test_FrmAddon.php | head -40

Repository: Strategy11/formidable-forms

Length of output: 1335


🏁 Script executed:

#!/bin/bash
# Find phpunit configuration files
fd phpunit

Repository: Strategy11/formidable-forms

Length of output: 137


🏁 Script executed:

#!/bin/bash
# Check if there are any CI/workflow files that specify PHPUnit version
fd -e yml -e yaml | xargs grep -l phpunit 2>/dev/null | head -5

Repository: Strategy11/formidable-forms

Length of output: 53


🏁 Script executed:

#!/bin/bash
# Check the phpunit.xml file
cat phpunit.xml

Repository: Strategy11/formidable-forms

Length of output: 949


🏁 Script executed:

#!/bin/bash
# Check bootstrap file for PHPUnit version hints
cat tests/phpunit/bootstrap.php | head -50

Repository: Strategy11/formidable-forms

Length of output: 1028


🏁 Script executed:

#!/bin/bash
# Check GitHub workflows for PHPUnit version
fd -e yml -e yaml .github 2>/dev/null | xargs cat 2>/dev/null | grep -i phpunit -C 3 || echo "No workflows found"

Repository: Strategy11/formidable-forms

Length of output: 89


🏁 Script executed:

#!/bin/bash
# Check if there's a .github/workflows directory or CI config
find . -type d -name '.github' -o -name '.gitlab-ci*' -o -name '.travis*' 2>/dev/null | head -5

Repository: Strategy11/formidable-forms

Length of output: 80


🏁 Script executed:

#!/bin/bash
# Check README or documentation for PHPUnit version requirements
find . -maxdepth 2 -type f \( -name 'README*' -o -name 'CONTRIBUTE*' -o -name 'DEV*' \) -exec head -50 {} \; 2>/dev/null | grep -i phpunit -C 2 || echo "No PHPUnit version info in docs"

Repository: Strategy11/formidable-forms

Length of output: 102


🏁 Script executed:

#!/bin/bash
# List contents of .github directory
ls -la .github/

Repository: Strategy11/formidable-forms

Length of output: 311


🏁 Script executed:

#!/bin/bash
# Check all YAML files in .github for PHPUnit mentions
find .github -type f -name '*.yml' -o -name '*.yaml' | xargs cat 2>/dev/null

Repository: Strategy11/formidable-forms

Length of output: 13279


Remove the no-op setMethods() call.

MockBuilder::setMethods() was deprecated in PHPUnit 8.3 and removed in PHPUnit 10.0. The call on lines 13–14 with no arguments is a no-op (equivalent to setMethods(null)) and should be removed entirely. This ensures compatibility with both current and future PHPUnit versions.

Current code:
$this->addon = $this->getMockBuilder( 'FrmTestAddon' )->setMethods()
                            ->getMock();

Remove ->setMethods() from the chain.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/phpunit/misc/test_FrmAddon.php` around lines 13 - 14, The test
constructs a mock for FrmTestAddon using getMockBuilder but includes a no-op
call to setMethods() which is deprecated/removed; remove the ->setMethods() call
from the chain so the mock is built as
$this->getMockBuilder('FrmTestAddon')->getMock() (i.e., locate the
getMockBuilder('FrmTestAddon') call in tests/phpunit/misc/test_FrmAddon.php and
delete the setMethods() invocation).

Comment thread tests/phpunit/misc/test_FrmAddon.php Outdated
Comment thread tests/phpunit/misc/test_FrmAntiSpam.php Outdated
Comment thread tests/phpunit/styles/test_FrmStylesHelper.php Outdated
@Crabcyborg
Crabcyborg merged commit 7762044 into master Feb 24, 2026
19 of 21 checks passed
@Crabcyborg
Crabcyborg deleted the update_rector_to_actually_cover_tests branch February 24, 2026 19:40
stephywells pushed a commit that referenced this pull request Apr 4, 2026
…ver_tests

Update rector config to actually fix issues in tests
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