Tests: Add unit test coverage for MC4WP_MailChimp_Subscriber - #855
Open
noruzzamans wants to merge 1 commit into
Open
noruzzamans wants to merge 1 commit into
noruzzamans wants to merge 1 commit into
Conversation
noruzzamans
marked this pull request as ready for review
September 17, 2026 11:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds comprehensive PHPUnit unit test coverage for the
MC4WP_MailChimp_Subscriberclass (includes/class-mailchimp-subscriber.php).Why
MC4WP_MailChimp_Subscriberis the core data transfer object representing subscriber payload data sent to Mailchimp API v3 throughout the plugin:MC4WP_List_Data_Mapper(mapping form and integration input into subscriber payloads)MC4WP_Form_Listener(handling newsletter form submissions and lifecycle filters)MC4WP_Integration(processing integration submissions from WooCommerce, Contact Form 7, WPForms, etc.)Despite being central to subscription processing, the class currently has zero dedicated unit tests in
tests/. Adding isolated test coverage ensures its default values, null-filtering behavior, and array conversion remain consistent and regression-free.What was tested
Introduced
tests/MailchimpSubscriberTest.phpwith 7 tests and 42 assertions covering:test_default_properties: verifies default values (email_address,status = 'pending',email_type = 'html', empty arrays forinterests,merge_fields,tags,marketing_permissions, and nullable properties initialized tonull).test_to_array_default_values: validates thatto_array()retains non-null defaults, excludesnullproperties (ip_signup,language,vip), and skips emptymarketing_permissions.test_to_array_with_custom_values: verifies populated scalar and array properties (email, status, email type, interests, merge fields, tags) are correctly serialized.test_to_array_includes_marketing_permissions_when_not_empty: verifies that non-empty marketing permissions arrays are preserved into_array().test_to_array_with_nullable_fields_populated: verifies that when$ip_signup,$language, and$vipare populated, they are included into_array().test_to_array_filters_out_explicit_null_values: verifies setting any property explicitly tonullexcludes it fromto_array().test_to_array_preserves_falsy_non_null_values: verifies non-null falsy values (such as$subscriber->vip = false) are preserved into_array().Note: This is a 100% test-only contribution with 0 modifications to production code.
Testing Instructions
1. Run the new test suite:
Output:
2. Run full regression suite:
Output:
3. Run coding standards linter:
(0 errors, 0 warnings)