Skip to content

test: add comprehensive unit test coverage across all major components - #153

Open
MaximillianGroup with Copilot wants to merge 10 commits into
mainfrom
copilot/analyze-test-coverage
Open

test: add comprehensive unit test coverage across all major components#153
MaximillianGroup with Copilot wants to merge 10 commits into
mainfrom
copilot/analyze-test-coverage

Conversation

Copilot AI commented May 16, 2026

Copy link
Copy Markdown
Contributor
  • Analyze existing test coverage (15 tests across 7 test classes)
  • Add missing WP stubs to tests/bootstrap-unit.php
  • Add 9 new test classes (154 tests total, 217 assertions)
  • Fix pnpm-lock.yaml out-of-sync with package.json (rollup ^4.60.1^4.60.2)
  • Add .phpunit.result.cache to .gitignore and remove from git tracking
  • Tighten SparxstarUECRESTControllerTest: split into error-path (db_table_missing) and success-path (seeded wpdb stub returns a 200 WP_REST_Response with status=ok, action=inserted)
  • Fix getUserOS() map ordering in src/StarUserEnv.php: more-specific UA patterns (Windows Phone, iOS, Android) now precede generic ones (Windows, Mac, Linux)
  • Fix StarUserEnvGettersTest.php: update Android/iOS test assertions and docblocks to match corrected getUserOS() behavior (Android UA → 'Android', iOS UA → 'iOS')

@MaximillianGroup
MaximillianGroup marked this pull request as ready for review May 17, 2026 02:07
Copilot AI review requested due to automatic review settings May 17, 2026 02:07
@MaximillianGroup

Copy link
Copy Markdown
Collaborator

@copilot - still having this error - Run pnpm install --frozen-lockfile
 ERR_PNPM_OUTDATED_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to date with package.json

Note that in CI environments this setting is true by default. If you still need to run install in such cases, use "pnpm install --no-frozen-lockfile"

Failure reason:
specifiers in the lockfile ({"@fingerprintjs/fingerprintjs":"^5.2.0","device-detector-js":"^3.0.3","@rollup/plugin-commonjs":"^29.0.2","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^16.0.3","@rollup/plugin-terser":"^1.0.0","cssnano":"^7.1.5","eslint":"^9.39.2","eslint-config-prettier":"^10.1.8","eslint-plugin-import":"^2.32.0","eslint-plugin-prettier":"^5.5.5","jsdoc":"^4.0.5","jsdoc-to-markdown":"^9.1.3","postcss":"^8.5.14","postcss-cli":"^11.0.1","prettier":"^3.8.3","rollup":"^4.60.1","stylelint":"^16.26.1","stylelint-config-standard":"^39.0.1"}) don't match specs in package.json ({"@rollup/plugin-commonjs":"^29.0.2","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^16.0.3","@rollup/plugin-terser":"^1.0.0","cssnano":"^7.1.5","eslint":"^9.39.2","eslint-config-prettier":"^10.1.8","eslint-plugin-import":"^2.32.0","eslint-plugin-prettier":"^5.5.5","jsdoc":"^4.0.5","jsdoc-to-markdown":"^9.1.3","postcss":"^8.5.14","postcss-cli":"^11.0.1","prettier":"^3.8.3","rollup":"^4.60.2","stylelint":"^16.26.1","stylelint-config-standard":"^39.0.1","@fingerprintjs/fingerprintjs":"^5.2.0","device-detector-js":"^3.0.3"})

Error: Process completed with exit code 1.

Copilot AI commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot - still having this error - Run pnpm install --frozen-lockfile
 ERR_PNPM_OUTDATED_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to date with package.js...

Fixed in aa12459. The pnpm-lock.yaml specifier for rollup was ^4.60.1 while package.json had been updated to ^4.60.2. Regenerated the lockfile with pnpm install --no-frozen-lockfilepnpm install --frozen-lockfile now exits cleanly.

Copilot AI 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.

Pull request overview

This PR expands isolated PHPUnit coverage for major SPARXSTAR UEC components and extends the shared WordPress test bootstrap with additional stubs needed by those tests.

Changes:

  • Adds new unit tests for database, REST, logging, scheduler, session, repository, GeoIP, installer deactivation, and StarUserEnv getters.
  • Expands tests/bootstrap-unit.php with WordPress constants, class stubs, transient helpers, and updated wpdb::get_row() compatibility.
  • Updates PHPUnit result cache metadata.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/bootstrap-unit.php Adds WP test shims and transient storage support.
tests/unit/SparxstarUECDatabaseTest.php Covers schema, table naming, snapshot storage, and cleanup paths.
tests/unit/SparxstarUECGeoIPServiceTest.php Covers provider selection, invalid IPs, and transient cache behavior.
tests/unit/SparxstarUECInstallerDeactivateTest.php Covers single-site and multisite deactivation cleanup.
tests/unit/SparxstarUECRESTControllerTest.php Covers permission checks and REST request handling.
tests/unit/SparxstarUECSchedulerTest.php Covers cron interval mapping, scheduling, deduplication, and clearing.
tests/unit/SparxstarUECSessionManagerTest.php Covers dot-path lookup and session manager stubs.
tests/unit/SparxstarUECSnapshotRepositoryTest.php Covers null guards and cache flushing.
tests/unit/StarLoggerTest.php Covers logging levels, sanitization, wrappers, correlation IDs, and timers.
tests/unit/StarUserEnvGettersTest.php Covers public snapshot getters and server-side helper methods.
.phpunit.result.cache Updates generated PHPUnit cache metadata.
Files not reviewed (1)
  • .phpunit.result.cache: Language not supported

Comment thread .phpunit.result.cache Outdated
Comment thread tests/unit/StarLoggerTest.php Outdated
Comment thread tests/unit/SparxstarUECRESTControllerTest.php Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Max Barrett <34328348+MaximillianGroup@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 17, 2026 03:38
@MaximillianGroup

Copy link
Copy Markdown
Collaborator

@copilot apply changes based on the comments in this thread

…rror code in REST controller test

Agent-Logs-Url: https://github.com/Starisian-Technologies/sparxstar-user-environment-check/sessions/ff12c0e0-a034-4363-aff1-c87916605e9d

Co-authored-by: MaximillianGroup <34328348+MaximillianGroup@users.noreply.github.com>

Copilot AI commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Applied in 9076a35:

  • .phpunit.result.cache — added to .gitignore and removed from git tracking (it had stale defect entries for two tests that now pass)
  • SparxstarUECRESTControllerTest.php — replaced the assertNotSame('invalid_data', ...) weak check with assertInstanceOf(WP_Error::class, $result) + assertSame('db_table_missing', $result->get_error_code()), which exactly matches the known code path: the stub wpdb::get_var returns nulltable_exists() = false → WP_Error('db_table_missing') propagated by the controller
  • StarLoggerTest.php — the Throwable formatting test already uses reflection to call formatMessageContent directly and asserts all four string parts (class, message, file, line); no change needed (thread was already resolved)

All 153 tests still pass (212 assertions).

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 13 changed files in this pull request and generated 3 comments.

Files not reviewed (2)
  • .phpunit.result.cache: Language not supported
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

tests/unit/StarUserEnvGettersTest.php:535

  • This test locks in the current misclassification of iPhone user agents as Mac instead of covering the intended iOS branch in getUserOS. Update it to assert iOS detection (or isolate the production bug as an expected-failure/TODO) so the new suite does not prevent correcting mobile OS detection later.
    public function test_get_user_os_returns_mac_for_ios_ua(): void
    {
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)';

        // 'mac os x' matches before 'iphone' in the ordered pattern map.
        $this->assertSame('Mac', StarUserEnv::getUserOS());

Comment thread tests/unit/StarUserEnvGettersTest.php Outdated
Comment thread tests/unit/SparxstarUECRESTControllerTest.php Outdated
Copilot AI requested a review from MaximillianGroup May 17, 2026 03:41
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Max Barrett <34328348+MaximillianGroup@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 17, 2026 21:52
@MaximillianGroup

Copy link
Copy Markdown
Collaborator

@copilot apply changes based on the comments in this thread

Copilot AI 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.

Pull request overview

Copilot reviewed 11 out of 13 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment thread tests/unit/StarUserEnvGettersTest.php
Comment thread tests/unit/StarUserEnvGettersTest.php
… add 200-success REST controller test

Agent-Logs-Url: https://github.com/Starisian-Technologies/sparxstar-user-environment-check/sessions/18c0bbd3-d338-4608-94df-c4b9df3d8c17

Co-authored-by: MaximillianGroup <34328348+MaximillianGroup@users.noreply.github.com>

Copilot AI commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Applied in 99c8502:

SparxstarUECRESTControllerTest.php — Replaced the single weak test with two clear tests:

  • test_handle_log_request_propagates_db_table_missing_error — keeps the error-path coverage (stub wpdb returns null → table missing → WP_Error('db_table_missing'))
  • test_handle_log_request_with_valid_payload_returns_200_response — new success-path test that seeds an anonymous wpdb subclass returning 1 for SHOW TABLES LIKE (table exists) and null for SELECT id (new record); asserts WP_REST_Response(200) with status=ok, action=inserted

src/StarUserEnv.php / getUserOS() — Fixed a map-ordering bug: 'android' and 'ipad|ipod|iphone' were listed after 'linux' and 'macintosh|mac os x|macos' respectively, causing Android UAs to return 'Linux' and iOS UAs to return 'Mac'. Reordered so specific patterns come first. The previously-failing test_get_user_os_detects_android and test_get_user_os_detects_ios now pass.

All 154 tests pass (217 assertions).

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Max Barrett <34328348+MaximillianGroup@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 03:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Max Barrett <34328348+MaximillianGroup@users.noreply.github.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 12 out of 14 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment thread tests/unit/StarUserEnvGettersTest.php Outdated
Comment on lines +515 to +521
* An Android User-Agent string with a Linux token is currently classified as 'Linux'.
*/
public function test_get_user_os_detects_android(): void
{
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36';

$this->assertSame('Linux', StarUserEnv::getUserOS());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 25b9212: this test now expects Android, matching the updated getUserOS() ordering.

Comment thread tests/unit/StarUserEnvGettersTest.php Outdated
Comment on lines +525 to +531
* An iPhone User-Agent string currently matches the Mac pattern first and is classified as 'Mac'.
*/
public function test_get_user_os_detects_ios(): void
{
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)';

$this->assertSame('Mac', StarUserEnv::getUserOS());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 25b9212: this test now expects iOS, matching the updated getUserOS() ordering.

Copilot AI commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot - still having this error - Run pnpm install --frozen-lockfile
 ERR_PNPM_OUTDATED_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to date with package.js...

The pnpm-lock.yaml specifier was corrected to ^4.60.2 in commit aa12459pnpm install --frozen-lockfile now passes (visible in the CI log for commit 1d26e42 which shows + rollup 4.60.2 installed successfully). The CI failure that run was ESLint errors in sparxstar-integrator.js (pre-existing empty catch blocks, not introduced by this PR).

@copilot apply changes based on the comments in this thread

The remaining open items from that review thread were addressed in 99c8502 (REST controller success-path test + getUserOS() ordering fix). The two tests that were still failing due to stale expectations from a subsequent commit have now been corrected in 25b9212test_get_user_os_detects_android now asserts 'Android' and test_get_user_os_detects_ios asserts 'iOS'. All 154 tests pass (217 assertions).

@copilot apply changes based on the comments in this thread

Fixed in 25b9212. Both test_get_user_os_detects_android (now expects 'Android') and test_get_user_os_detects_ios (now expects 'iOS') are updated with accurate docblocks explaining that the specific patterns (android, ipad|ipod|iphone) precede the generic ones (linux, macintosh|mac os x|macos) in the detector map. All 154 tests pass.

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.

3 participants