Skip to content

GH#716: test(limits,domain-mapping): add unit tests for Trial_Limits and SSO classes#718

Merged
superdav42 merged 1 commit intomainfrom
feature/gh716-trial-limits-sso-tests
Mar 31, 2026
Merged

GH#716: test(limits,domain-mapping): add unit tests for Trial_Limits and SSO classes#718
superdav42 merged 1 commit intomainfrom
feature/gh716-trial-limits-sso-tests

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Mar 31, 2026

Summary

Adds comprehensive unit tests for two previously untested classes:

  • Trial_Limits (inc/limits/class-trial-limits.php) - 10 tests covering singleton behavior, init method, and load_limitations
  • Domain_Mapping SSO (inc/domain-mapping/class-sso.php) - 9 tests covering the deprecated SSO compatibility shim

Both classes now have 100% test coverage (previously 0%).

Testing Evidence

Runtime verified - All tests pass:

vendor/bin/phpunit tests/WP_Ultimo/Limits/Trial_Limits_Test.php
# OK (10 tests, 12 assertions)

vendor/bin/phpunit tests/WP_Ultimo/Domain_Mapping/SSO_Test.php
# OK (9 tests, 14 assertions)

Coverage report confirms 100% coverage for both classes:

  • Trial_Limits: Methods 100.00% (2/2), Lines 100.00% (2/2)
  • Singleton trait: Methods 100.00% (4/4), Lines 100.00% (7/7)

Key Decisions

  1. Reflection-based instantiation - Both test classes use newInstanceWithoutConstructor() to bypass singleton init() which may have dependencies
  2. Comprehensive singleton testing - Tests verify get_instance() returns correct class and same instance
  3. SSO deprecation verification - Tests confirm the SSO class properly documents its deprecated status and references the new location
  4. Method visibility checks - Tests verify public/protected method visibility and return types

Files Changed

  • tests/WP_Ultimo/Limits/Trial_Limits_Test.php (new, 143 lines)
  • tests/WP_Ultimo/Domain_Mapping/SSO_Test.php (new, 140 lines)

Follow-up

None - both classes are simple singletons with minimal logic. Coverage is complete.

Closes #716


aidevops.sh v3.5.468 plugin for OpenCode v1.3.0 with claude-sonnet-4-5

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for SSO class, validating deprecation status, singleton trait implementation, consistent instance management across multiple calls, correct namespace declaration, and error-free instantiation
    • Added comprehensive test coverage for Trial_Limits class, validating singleton trait implementation, required public methods with correct signatures, and error-free execution of initialization and loading methods

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

The PR adds two comprehensive test suites for previously untested classes: Trial_Limits and SSO from the domain-mapping module. These test files validate class structure, singleton trait implementation, method existence, and basic invocation paths to achieve code coverage for business-critical trial enforcement and SSO integration flows.

Changes

Cohort / File(s) Summary
Unit Tests for Untested Classes
tests/WP_Ultimo/Domain_Mapping/SSO_Test.php, tests/WP_Ultimo/Limits/Trial_Limits_Test.php
New test suites with 9 and multiple test methods respectively, validating class existence, singleton trait usage, get_instance() behavior, method signatures, and deprecation annotations. Tests use reflection helpers to instantiate classes without constructor execution, covering previously 0% coverage classes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

needs-review-fixes

Poem

🐰 Two test files hop into place,
SSO and Limits join the race,
Coverage gaps we did close,
With assertions, as any tester knows,
Business logic shines bright today! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and specifically describes the main change: adding unit tests for Trial_Limits and SSO classes, with relevant issue reference.
Linked Issues check ✅ Passed All acceptance criteria from issue #716 are met: test files created at specified paths, main logic paths covered, and all tests pass locally with 100% coverage.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #716 objectives: two test files for Trial_Limits and SSO classes with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/gh716-trial-limits-sso-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.

…classes

- Add Trial_Limits_Test.php with 10 tests covering singleton behavior, init method, and load_limitations
- Add SSO_Test.php with 9 tests covering deprecated SSO compatibility shim
- Both classes now have 100% test coverage (previously 0%)
- Tests verify singleton pattern, method existence, and deprecation documentation
- Closes #716
@superdav42 superdav42 force-pushed the feature/gh716-trial-limits-sso-tests branch from c24fed8 to c9ffca6 Compare March 31, 2026 02:53
@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

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.

🧹 Nitpick comments (4)
tests/WP_Ultimo/Limits/Trial_Limits_Test.php (2)

118-139: Consider using $this->expectNotToPerformAssertions() for "no error" tests.

The $this->assertTrue(true) pattern works but is considered a weak assertion. PHPUnit provides $this->expectNotToPerformAssertions() specifically for tests that verify no exception is thrown.

🔧 Alternative approach
 	public function test_load_limitations_can_be_called() {
+		$this->expectNotToPerformAssertions();

 		$instance = $this->get_instance();

 		// Should not throw any errors
 		$instance->load_limitations();
-
-		$this->assertTrue(true);
 	}

 	/**
 	 * Test init can be called without errors.
 	 */
 	public function test_init_can_be_called() {
+		$this->expectNotToPerformAssertions();

 		$instance = $this->get_instance();

 		// Should not throw any errors
 		$instance->init();
-
-		$this->assertTrue(true);
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Limits/Trial_Limits_Test.php` around lines 118 - 139, Replace
the weak no-op assertions in test_load_limitations_can_be_called and
test_init_can_be_called: instead of calling $this->assertTrue(true) after
invoking $this->get_instance()->load_limitations() and
$this->get_instance()->init(), call $this->expectNotToPerformAssertions() at the
start of each test so the tests explicitly state they only assert that no
exceptions are thrown when calling load_limitations() and init().

1-8: Missing defined('ABSPATH') || exit; guard.

Per coding guidelines, every PHP file should start with defined('ABSPATH') || exit;. While test files have relaxed requirements, adding this guard maintains consistency across the codebase.

🔧 Suggested fix
 <?php
+
+defined('ABSPATH') || exit;

 namespace WP_Ultimo\Limits;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Limits/Trial_Limits_Test.php` around lines 1 - 8, Add the
standard WordPress file guard at the top of the test file by inserting
defined('ABSPATH') || exit; as the first executable statement so the file
short-circuits when loaded outside WP; update the
tests/WP_Ultimo/Limits/Trial_Limits_Test.php file above the namespace
declaration (before the namespace and the Trial_Limits_Test class) to maintain
consistency with coding guidelines.
tests/WP_Ultimo/Domain_Mapping/SSO_Test.php (2)

1-11: Missing defined('ABSPATH') || exit; guard.

Same as the other test file - consider adding the ABSPATH guard for consistency.

🔧 Suggested fix
 <?php
+
+defined('ABSPATH') || exit;

 namespace WP_Ultimo\Domain_Mapping\SSO;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Domain_Mapping/SSO_Test.php` around lines 1 - 11, Add the
WordPress ABSPATH guard to this test file by inserting a defined('ABSPATH') ||
exit; check immediately after the opening PHP tag and before the namespace
declaration so the file exits when loaded outside WP; update the SSO_Test class
file (the class named SSO_Test in the WP_Ultimo\Domain_Mapping\SSO namespace) to
include that guard for consistency with other tests.

116-138: LGTM on public method verification.

The test correctly verifies that the SSO class exposes only the methods from the Singleton trait (get_instance, init, has_parents), confirming it's a minimal compatibility shim with no additional functionality.

One minor improvement: use strict comparison in in_array() for type safety.

🔧 Suggested strict comparison
 		// Filter out Singleton methods
 		$non_singleton_methods = array_filter($method_names, function ($name) {
-			return !in_array($name, ['get_instance', 'init', 'has_parents']);
+			return !in_array($name, ['get_instance', 'init', 'has_parents'], true);
 		});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Domain_Mapping/SSO_Test.php` around lines 116 - 138, In
test_has_only_singleton_public_methods update the in_array calls to use strict
comparison by passing the third argument true; specifically modify the in_array
usage inside the array_filter closure that builds $non_singleton_methods (and
any other in_array call in this test) so it becomes in_array($name,
['get_instance','init','has_parents'], true) to ensure type-safe matching when
filtering public method names.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/WP_Ultimo/Domain_Mapping/SSO_Test.php`:
- Around line 1-11: Add the WordPress ABSPATH guard to this test file by
inserting a defined('ABSPATH') || exit; check immediately after the opening PHP
tag and before the namespace declaration so the file exits when loaded outside
WP; update the SSO_Test class file (the class named SSO_Test in the
WP_Ultimo\Domain_Mapping\SSO namespace) to include that guard for consistency
with other tests.
- Around line 116-138: In test_has_only_singleton_public_methods update the
in_array calls to use strict comparison by passing the third argument true;
specifically modify the in_array usage inside the array_filter closure that
builds $non_singleton_methods (and any other in_array call in this test) so it
becomes in_array($name, ['get_instance','init','has_parents'], true) to ensure
type-safe matching when filtering public method names.

In `@tests/WP_Ultimo/Limits/Trial_Limits_Test.php`:
- Around line 118-139: Replace the weak no-op assertions in
test_load_limitations_can_be_called and test_init_can_be_called: instead of
calling $this->assertTrue(true) after invoking
$this->get_instance()->load_limitations() and $this->get_instance()->init(),
call $this->expectNotToPerformAssertions() at the start of each test so the
tests explicitly state they only assert that no exceptions are thrown when
calling load_limitations() and init().
- Around line 1-8: Add the standard WordPress file guard at the top of the test
file by inserting defined('ABSPATH') || exit; as the first executable statement
so the file short-circuits when loaded outside WP; update the
tests/WP_Ultimo/Limits/Trial_Limits_Test.php file above the namespace
declaration (before the namespace and the Trial_Limits_Test class) to maintain
consistency with coding guidelines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bc359ba8-2329-4bde-b5bf-21580431f597

📥 Commits

Reviewing files that changed from the base of the PR and between a895c8c and c9ffca6.

📒 Files selected for processing (2)
  • tests/WP_Ultimo/Domain_Mapping/SSO_Test.php
  • tests/WP_Ultimo/Limits/Trial_Limits_Test.php

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Performance Test Results

Performance test results for c8205ac are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.78 MB 902.00 ms (-60.50 ms / -7% ) 179.50 ms (-7.00 ms / -4% ) 1171.00 ms 2176.00 ms 2089.30 ms 92.80 ms (+1.95 ms / +2% )
1 56 49.01 MB 987.00 ms 163.00 ms (+5.50 ms / +3% ) 1153.00 ms 2186.00 ms 2096.15 ms 86.60 ms (+2.20 ms / +3% )

@superdav42 superdav42 merged commit 7e42688 into main Mar 31, 2026
11 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

What Was Done

Added comprehensive unit tests for two previously untested classes:

  • Trial_Limits (inc/limits/class-trial-limits.php) - 10 tests covering singleton behavior, init method, and load_limitations
  • Domain_Mapping SSO (inc/domain-mapping/class-sso.php) - 9 tests covering the deprecated SSO compatibility shim

Both classes now have 100% test coverage (previously 0%).

Testing Evidence

Runtime verified - All tests pass:

vendor/bin/phpunit tests/WP_Ultimo/Limits/Trial_Limits_Test.php
# OK (10 tests, 12 assertions)

vendor/bin/phpunit tests/WP_Ultimo/Domain_Mapping/SSO_Test.php
# OK (9 tests, 14 assertions)

Coverage report confirms 100% coverage:

  • Trial_Limits: Methods 100.00% (2/2), Lines 100.00% (2/2)
  • Singleton trait: Methods 100.00% (4/4), Lines 100.00% (7/7)

All CI checks passed (PHP 8.2-8.5, Cypress E2E, Code Quality, PHP Lint).

Key Decisions

  1. Reflection-based instantiation - Both test classes use newInstanceWithoutConstructor() to bypass singleton init() which may have dependencies
  2. Comprehensive singleton testing - Tests verify get_instance() returns correct class and same instance
  3. SSO deprecation verification - Tests confirm the SSO class properly documents its deprecated status and references the new location
  4. Method visibility checks - Tests verify public/protected method visibility and return types

Files Changed

  • tests/WP_Ultimo/Limits/Trial_Limits_Test.php (new, 143 lines)
  • tests/WP_Ultimo/Domain_Mapping/SSO_Test.php (new, 140 lines)

Blockers

None

Follow-up

None - both classes are simple singletons with minimal logic. Coverage is complete.

Released In

Merged to main via PR #718

Closes #716


aidevops.sh v3.5.470 plugin for OpenCode v1.3.0 with claude-sonnet-4-5

@superdav42 superdav42 deleted the feature/gh716-trial-limits-sso-tests branch March 31, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(limits,domain-mapping): write unit tests for Trial_Limits and Domain_Mapping SSO class (0% coverage)

1 participant