Skip to content

t453: Write unit tests for Checkout class#569

Merged
superdav42 merged 4 commits into
mainfrom
feature/t453-checkout-coverage
Mar 27, 2026
Merged

t453: Write unit tests for Checkout class#569
superdav42 merged 4 commits into
mainfrom
feature/t453-checkout-coverage

Conversation

@superdav42

@superdav42 superdav42 commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds 171 PHPUnit tests for WP_Ultimo\Checkout\Checkout covering all public methods and key protected methods via reflection
  • Tests are resilient to both canonical and worktree code differences (e.g. discount_code key presence)
  • All 171 tests pass, 1 skipped (environment-dependent customer lookup)

Coverage areas

Area Tests
Singleton 2
contains_auto_submittable_field 8
get_auto_submittable_fields 2
is_existing_user 2
handle_display_name 5
request_or_session 5
Step navigation (is_first_step, is_last_step, get_next_step_name) 10
Email verification status 5
errors property 2
should_process_checkout 3
validation_rules 9
should_collect_payment 5
get_thank_you_page 1
get_checkout_variables 20+
cleanup_expired_drafts 4
can_user_cancel_payment 3
validate 7
get_validation_rules 8
create_draft_payment / save_draft_progress 4
get_js_validation_rules 7
maybe_display_checkout_errors 2
get_checkout_from_query_vars 4
get_site_meta_fields 3
handle_customer_meta_fields 3
maybe_create_customer 6
maybe_create_membership 2
maybe_create_payment 4
maybe_create_site 3
setup_checkout 8
handle_cancel_payment 3
process_order 3
process_checkout 1
add_rewrite_rules / register_scripts 2

Runtime Testing

  • Testing level: unit-tested
  • Risk classification: low (test files only)
  • Dev environment: WordPress multisite test suite (/tmp/wordpress-tests-lib)
  • Result: 171 tests pass, 1 skipped

Closes #555

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for Checkout functionality, including setup flows, payment cancellation, error handling, and validation rules.
    • Enhanced test isolation to ensure reliable and independent test execution.

- 171 tests covering all public and key protected methods
- Singleton, step navigation, field helpers, validation rules
- should_collect_payment, email verification, display name
- request_or_session, cleanup_expired_drafts, can_user_cancel_payment
- should_process_checkout, get_thank_you_page, validate
- get_validation_rules, get_checkout_variables, get_js_validation_rules
- setup_checkout (idempotency, session init, pre-flight, resume, draft)
- handle_cancel_payment, create_draft_payment, save_draft_progress
- maybe_create_customer, maybe_create_membership, maybe_create_payment
- maybe_create_site, process_order, process_checkout error paths
- get_site_meta_fields, handle_customer_meta_fields via reflection
- discount_code assertions resilient to canonical vs worktree code differences

Closes #555
@coderabbitai

coderabbitai Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 51d7d94e-ae89-452d-8b42-7a2e70869b43

📥 Commits

Reviewing files that changed from the base of the PR and between 055e5e1 and fa99418.

📒 Files selected for processing (1)
  • tests/WP_Ultimo/Checkout/Checkout_Test.php

📝 Walkthrough

Walkthrough

The PR adds comprehensive unit test coverage for the Checkout class, including setup initialization, payment cancellation handling, getter methods, validation rules, session handling, and error path scenarios. Test setup enhances database isolation through user and customer deletion.

Changes

Cohort / File(s) Summary
Checkout Unit Tests
tests/WP_Ultimo/Checkout/Checkout_Test.php
Adds 2779 lines of test coverage for Checkout class including setup state verification, payment cancellation behavior, getter methods with branch coverage, validation rules, session management, reflection-based protected method testing, error path handling, and improved test isolation via database cleanup.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • PR #372: The expanded Checkout tests covering setup, payment cancellation, variables retrieval, and error paths directly validate the functional changes to checkout/cart/payment and class-checkout.php behavior.
  • PR #367: Directly modifies the same test file (tests/WP_Ultimo/Checkout/Checkout_Test.php) with related Checkout test additions and setup/teardown enhancements.

Poem

🐰 A burrow of tests, now thoroughly sewn,
Each path through Checkout is carefully known,
Setup, cancellation, validation so bright,
Error cases tested from left to right,
Coverage takes flight, our goals now full-grown! ✨

✨ 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/t453-checkout-coverage

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.

@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

Performance Test Results

Performance test results for 15a52a8 are in 🛎️!

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 57 36.39 MB 293.50 ms 103.50 ms 397.00 ms 490.05 ms 410.80 ms 79.55 ms
1 57 36.39 MB 293.00 ms 102.00 ms 395.50 ms 489.50 ms 409.75 ms 79.85 ms

@superdav42 superdav42 merged commit 1acbe54 into main Mar 27, 2026
6 of 8 checks passed
@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

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(checkout): write unit tests for Checkout class

1 participant