2.6.0: Update Traits from PHP SDK - #127
Conversation
| * | ||
| * @return int HTTP status code of the last API response (0 if none). | ||
| */ | ||
| public function get_last_response_code() { |
There was a problem hiding this comment.
This mirrors how the PHP SDK works, when a developer wants to fetch the last response code for a request.
| } | ||
|
|
||
| // Treat any 4xx or 5xx status as an error. | ||
| if ( $http_response_code >= 400 ) { |
There was a problem hiding this comment.
This mirrors the PHP SDK, where a 4xx or 5xx status code returns an error
| // Build array of arguments depending on the resource type. | ||
| switch ( $resource_type ) { | ||
| case 'forms': | ||
| $args = array( |
There was a problem hiding this comment.
These arguments are modified to work with the new API Traits, which come from the PHP SDK Traits, which provide more parameters.
| namespace Helper\WPUnit; | ||
|
|
||
| /** | ||
| * Wraps `ConvertKit_API_V4` and converts every array response to a nested `stdClass` |
There was a problem hiding this comment.
There's always been a difference between the WordPress Libraries and PHP SDK:
- WordPress Libraries return an array of data on success
- PHP SDK returns a nested stdClass object on success
Rather than rewrite all of the tests in TestsTrait, this proxy converts array responses to stdClass objects so they can be run through the TestsTrait.
ciccio-kit
left a comment
There was a problem hiding this comment.
LGTM from a quick look and also came clean from another Claude pass I delegated to because of size, approved ✅
Summary
Restructures the Kit WordPress Libraries as a WordPress mirror of the PHP SDK. API surface, tests, and version numbers now track the SDK; only genuinely WordPress-specific methods and tests stay unique to this repo.
Based on ConvertKitSDK-PHP #155:
ConvertKit_API_Traits, adjusted for PHP 7.x (nullable shorthand, positional args, etc.).TestsTraitverbatim.APITest.phpnow uses the trait and provides two shims (assertApiError,assertLastResponseStatusCode) that translate SDK-style thrown exceptions intoWP_Errorassertions. WP-only tests remain inAPITest.php/ResourceTest.php/APINoDataTest.php.2.6.0to match the SDK release.Future SDK updates port over in two steps: copy the changed API methods into
ConvertKit_API_Traits(with PHP 7.x tweaks), then copy the SDK'sTestsTrait.phpinto this repo.Testing
Existing tests pass. This is a large PR which is difficult to review, so I've added comments to cover the main items, and tests are also performed on each Kit WordPress Plugin against this branch to confirm no breaking changes:
Checklist