Skip to content

Try using strict comparison in unit tests (prefer assertSame over assertEquals)#2905

Merged
Crabcyborg merged 4 commits into
masterfrom
try_using_strict_comparison_in_unit_tests
Jan 29, 2026
Merged

Try using strict comparison in unit tests (prefer assertSame over assertEquals)#2905
Crabcyborg merged 4 commits into
masterfrom
try_using_strict_comparison_in_unit_tests

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 29, 2026

Summary by CodeRabbit

  • Tests

    • Many PHPUnit assertions updated to strict type-and-value checks for tighter test validation across the suite.
  • Chores

    • Linter configuration extended to include WordPress and PHPUnit integrations.
  • Documentation

    • Public method documentation updated to reflect it may return an integer or a string.

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

@Crabcyborg Crabcyborg added this to the 6.28 milestone Jan 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Added WordPress and PHPUnit linter integrations in configuration, tightened many PHPUnit test assertions from assertEquals to assertSame across tests, and updated the FrmFormsHelper::get_form_style docblock to indicate it may return int|string. No production logic or public API signatures changed.

Changes

Cohort / File(s) Summary
Configuration
mago.toml
Added wordpress and phpunit to linter integrations and appended linter.rules entries disabling specific PHPUnit and WordPress checks.
Global Test Assertion Tightening
tests/phpunit/...
Replaced numerous assertEquals calls with assertSame across ~35 PHPUnit test files (applications, database, emails, entries, fields, forms, styles, stripe, xml, misc). These are assertion-only changes.
Example Test Files (samples)
tests/phpunit/applications/test_FrmApplicationApi.php, tests/phpunit/database/test_FrmMigrate.php, tests/phpunit/emails/test_FrmEmail.php, tests/phpunit/entries/..., tests/phpunit/fields/..., tests/phpunit/forms/..., tests/phpunit/styles/..., tests/phpunit/xml/test_FrmXMLHelper.php
Concrete instances of assertions tightened to strict identity checks (assertSame) in their respective test suites.
Docs / Docblock
classes/helpers/FrmFormsHelper.php
Updated PHPDoc for get_form_style from @return string to `@return int

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Poem

🐰 I hopped through tests with tiny feet so spry,
I swapped loose equals for equals that won't lie.
Types now cuddle values snug and tight,
The code garden hums in order and light. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and accurately summarizes the main change: replacing non-strict PHPUnit assertions (assertEquals) with strict assertions (assertSame) throughout the test suite.
Docstring Coverage ✅ Passed Docstring coverage is 82.61% which is sufficient. The required threshold is 80.00%.

✏️ 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

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

1-1: Filename has double .php extension.

The file is named test_FrmFieldGridHelper.php.php which appears to be a typo. It should likely be test_FrmFieldGridHelper.php.

🤖 Fix all issues with AI agents
In `@tests/phpunit/forms/test_FrmFormsHelper.php`:
- Around line 100-101: Update the PHPUnit assertions that expect a string '1' to
expect the integer 1 so they match FrmFormsHelper::get_form_style()’s actual
return type; replace assertSame('1', FrmFormsHelper::get_form_style(...)) with
assertSame(1, FrmFormsHelper::get_form_style(...)) for the calls with null,
'default', and the array form without custom_style (and the other identical
assertion later in the file).
🧹 Nitpick comments (4)
tests/phpunit/entries/test_FrmTableHTMLGenerator.php (1)

55-58: Use assertSame() on line 58 for consistency with line 57.

remove_border() always returns a string via str_replace(), so switching the second assertion to assertSame maintains the strict-comparison approach consistently across both test cases.

♻️ Suggested update
-		$this->assertEquals( $table_generator->remove_border( $html, 'bottom' ), $html );
+		$this->assertSame( $table_generator->remove_border( $html, 'bottom' ), $html );
tests/phpunit/fields/test_FrmSubmitHelper.php (1)

18-18: Swap assertSame argument order to follow PHPUnit convention.

PHPUnit expects assertSame(expected, actual). Currently, the arguments are reversed—'Submit form' (the expected value) should come first, followed by $new_form->options['submit_value'] (the actual value). This ensures failure messages display the correct diff.

🔧 Proposed change
-		$this->assertSame( $new_form->options['submit_value'], 'Submit form' );
+		$this->assertSame( 'Submit form', $new_form->options['submit_value'] );
tests/phpunit/misc/test_FrmAddon.php (1)

46-46: Consider converting remaining assertions for consistency.

Lines 46 and 91 still use assertEquals. For a complete migration to strict comparisons, these could also be converted:

  • Line 46: $license_key is a string, so assertSame would work.
  • Line 91: $time['expected'] is a boolean, so assertSame would also be appropriate.
tests/phpunit/fields/test_FrmFieldGridHelper.php.php (1)

77-77: Consider converting remaining assertEquals for consistency.

Lines 77 and 147 still use assertEquals for current_list_size comparisons. For a complete migration to strict comparisons, these could also be converted to assertSame if the property is always an integer.

Comment thread tests/phpunit/forms/test_FrmFormsHelper.php Outdated
@Crabcyborg Crabcyborg changed the title Try using strict comparison in unit tests Try using strict comparison in unit tests (prefer assertSame over assertEquals) Jan 29, 2026
@Crabcyborg Crabcyborg merged commit cfe0754 into master Jan 29, 2026
15 of 16 checks passed
@Crabcyborg Crabcyborg deleted the try_using_strict_comparison_in_unit_tests branch January 29, 2026 17:24
stephywells pushed a commit that referenced this pull request Apr 4, 2026
…in_unit_tests

Try using strict comparison in unit tests (prefer assertSame over assertEquals)
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