From 8d88836318ac75c112dc8450ce1f77d6a3cb3277 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 30 Sep 2025 19:18:16 +0800 Subject: [PATCH 1/9] Add `tag_subscribers` method --- src/ConvertKit_API_Traits.php | 37 +++++++++++ tests/ConvertKitAPITest.php | 119 ++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index 71f2175..b90ec9e 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -585,6 +585,43 @@ public function create_tags(array $tags, string $callback_url = '') ); } + /** + * Tags the given subscribers with the given existing Tags. + * + * @param array> $taggings Taggings, in the format: + * [ + * [ + * "tag_id" => 0, + * "subscriber_id" => 0 + * ], + * [ + * "tag_id" => 1, + * "subscriber_id" => 1 + * ], + * ]. + * @param string $callback_url URL to notify for large batch size when async processing complete. + * + * @since 2.2.1 + * + * @see https://developers.kit.com/api-reference/tags/bulk-tag-subscribers + * + * @return false|mixed + */ + public function tag_subscribers(array $taggings, string $callback_url = '') + { + // Build parameters. + $options = $taggings; + if (!empty($callback_url)) { + $options['callback_url'] = $callback_url; + } + + // Send request. + return $this->post( + 'bulk/tags/subscribers', + $options + ); + } + /** * Tags a subscriber with the given existing Tag. * diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index e05a025..fa0d6bc 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -1722,6 +1722,125 @@ public function testCreateTagsThatExist() $this->assertEquals($result->tags[0]->name, $_ENV['CONVERTKIT_API_TAG_NAME_2']); } + /** + * Test that tag_subscribers() returns the expected data. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribers() + { + // Create subscribers. + $subscribers = [ + [ + 'email_address' => str_replace('@convertkit.com', '-1@convertkit.com', $this->generateEmailAddress()), + ], + [ + 'email_address' => str_replace('@convertkit.com', '-2@convertkit.com', $this->generateEmailAddress()), + ], + ]; + $result = $this->api->create_subscribers($subscribers); + + // Set subscriber_id to ensure subscriber is unsubscribed after test. + foreach ($result->subscribers as $i => $subscriber) { + $this->subscriber_ids[] = $subscriber->id; + } + + // Tag subscribers. + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => $this->subscriber_ids[0] + ], + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => $this->subscriber_ids[1] + ], + ] + ); + + // Assert no failures. + $this->assertCount(0, $result->failures); + + // Confirm result is an array comprising of each subscriber that was created. + $this->assertIsArray($result->subscribers); + $this->assertCount(2, $result->subscribers); + } + + /** + * Test that tag_subscribers() throws a ClientException when an invalid + * tag ID is specified. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribersWithInvalidTagID() + { + // Create subscribers. + $subscribers = [ + [ + 'email_address' => str_replace('@convertkit.com', '-1@convertkit.com', $this->generateEmailAddress()), + ], + [ + 'email_address' => str_replace('@convertkit.com', '-2@convertkit.com', $this->generateEmailAddress()), + ], + ]; + $result = $this->api->create_subscribers($subscribers); + + // Set subscriber_id to ensure subscriber is unsubscribed after test. + foreach ($result->subscribers as $i => $subscriber) { + $this->subscriber_ids[] = $subscriber->id; + } + + // Tag subscribers. + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => 12345, + 'subscriber_id' => $this->subscriber_ids[0] + ], + [ + 'tag_id' => 12345, + 'subscriber_id' => $this->subscriber_ids[1] + ], + ] + ); + + // Assert failures. + $this->assertCount(2, $result->failures); + } + + /** + * Test that tag_subscribers() throws a ClientException when an invalid + * subscriber ID is specified. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribersWithInvalidSubscriberID() + { + // Tag subscribers that do not exist. + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => 12345, + ], + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => 67890, + ], + ] + ); + + // Assert failures. + $this->assertCount(2, $result->failures); + } + /** * Test that tag_subscriber_by_email() returns the expected data. * From 00b83014081c6dd28fa25e262a64ef99693dd200 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 30 Sep 2025 21:25:27 +0800 Subject: [PATCH 2/9] Fix tests and method --- src/ConvertKit_API_Traits.php | 2 +- tests/ConvertKitAPIKeyTest.php | 67 ++++++++++++++++++++++++++++++++++ tests/ConvertKitAPITest.php | 12 +++--- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index b90ec9e..8e73203 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -610,7 +610,7 @@ public function create_tags(array $tags, string $callback_url = '') public function tag_subscribers(array $taggings, string $callback_url = '') { // Build parameters. - $options = $taggings; + $options = ['taggings' => $taggings]; if (!empty($callback_url)) { $options['callback_url'] = $callback_url; } diff --git a/tests/ConvertKitAPIKeyTest.php b/tests/ConvertKitAPIKeyTest.php index 6558399..0443de8 100644 --- a/tests/ConvertKitAPIKeyTest.php +++ b/tests/ConvertKitAPIKeyTest.php @@ -282,6 +282,73 @@ public function testCreateTagsThatExist() ); } + /** + * Test that tag_subscribers() throws a ClientException when attempting + * to tag subscribers, as this is only supported using OAuth. + * + * @since 2.2.0 + * + * @return void + */ + public function testTagSubscribers() + { + $this->expectException(ClientException::class); + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => (int) $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] + ], + ] + ); + } + + /** + * Test that tag_subscribers() throws a ClientException when an invalid + * tag ID is specified, as this is only supported using OAuth. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribersWithInvalidTagID() + { + $this->expectException(ClientException::class); + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => 12345, + 'subscriber_id' => (int) $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] + ], + ] + ); + } + + /** + * Test that tag_subscribers() throws a ClientException when an invalid + * subscriber ID is specified, as this is only supported using OAuth. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribersWithInvalidSubscriberID() + { + $this->expectException(ClientException::class); + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => 12345, + ], + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => 67890, + ], + ] + ); + } + /** * Test that add_subscribers_to_forms() throws a ClientException when * attempting to add subscribers to forms, as this is only supported diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index fa0d6bc..b815cca 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -1734,10 +1734,10 @@ public function testTagSubscribers() // Create subscribers. $subscribers = [ [ - 'email_address' => str_replace('@convertkit.com', '-1@convertkit.com', $this->generateEmailAddress()), + 'email_address' => str_replace('@kit.com', '-1@kit.com', $this->generateEmailAddress()), ], [ - 'email_address' => str_replace('@convertkit.com', '-2@convertkit.com', $this->generateEmailAddress()), + 'email_address' => str_replace('@kit.com', '-2@kit.com', $this->generateEmailAddress()), ], ]; $result = $this->api->create_subscribers($subscribers); @@ -1770,7 +1770,7 @@ public function testTagSubscribers() } /** - * Test that tag_subscribers() throws a ClientException when an invalid + * Test that tag_subscribers() returns failures when an invalid * tag ID is specified. * * @since 2.2.1 @@ -1782,10 +1782,10 @@ public function testTagSubscribersWithInvalidTagID() // Create subscribers. $subscribers = [ [ - 'email_address' => str_replace('@convertkit.com', '-1@convertkit.com', $this->generateEmailAddress()), + 'email_address' => str_replace('@kit.com', '-1@kit.com', $this->generateEmailAddress()), ], [ - 'email_address' => str_replace('@convertkit.com', '-2@convertkit.com', $this->generateEmailAddress()), + 'email_address' => str_replace('@kit.com', '-2@kit.com', $this->generateEmailAddress()), ], ]; $result = $this->api->create_subscribers($subscribers); @@ -1814,7 +1814,7 @@ public function testTagSubscribersWithInvalidTagID() } /** - * Test that tag_subscribers() throws a ClientException when an invalid + * Test that tag_subscribers() returns failures when an invalid * subscriber ID is specified. * * @since 2.2.1 From beede07450a4e2ee3a3abc1d86d59f1ff0f50572 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Fri, 3 Oct 2025 11:01:36 +0800 Subject: [PATCH 3/9] Update tests --- src/ConvertKit_API_Traits.php | 37 +++++++++++ tests/ConvertKitAPITest.php | 119 ++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index e08aaee..e578108 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -602,6 +602,43 @@ public function update_tag_name(int $tag_id, string $name) return $this->put(sprintf('tags/%s', $tag_id), ['name' => $name]); } + /** + * Tags the given subscribers with the given existing Tags. + * + * @param array> $taggings Taggings, in the format: + * [ + * [ + * "tag_id" => 0, + * "subscriber_id" => 0 + * ], + * [ + * "tag_id" => 1, + * "subscriber_id" => 1 + * ], + * ]. + * @param string $callback_url URL to notify for large batch size when async processing complete. + * + * @since 2.2.1 + * + * @see https://developers.kit.com/api-reference/tags/bulk-tag-subscribers + * + * @return false|mixed + */ + public function tag_subscribers(array $taggings, string $callback_url = '') + { + // Build parameters. + $options = ['taggings' => $taggings]; + if (!empty($callback_url)) { + $options['callback_url'] = $callback_url; + } + + // Send request. + return $this->post( + 'bulk/tags/subscribers', + $options + ); + } + /** * Tags a subscriber with the given existing Tag. * diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index 1761569..641f374 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -1818,6 +1818,125 @@ public function testGetSubscriberStatsWithInvalidSubscriberID() $result = $this->api->get_subscriber_stats(12345); } + /** + * Test that tag_subscribers() returns the expected data. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribers() + { + // Create subscribers. + $subscribers = [ + [ + 'email_address' => str_replace('@kit.com', '-1@kit.com', $this->generateEmailAddress()), + ], + [ + 'email_address' => str_replace('@kit.com', '-2@kit.com', $this->generateEmailAddress()), + ], + ]; + $result = $this->api->create_subscribers($subscribers); + + // Set subscriber_id to ensure subscriber is unsubscribed after test. + foreach ($result->subscribers as $i => $subscriber) { + $this->subscriber_ids[] = $subscriber->id; + } + + // Tag subscribers. + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => $this->subscriber_ids[0] + ], + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => $this->subscriber_ids[1] + ], + ] + ); + + // Assert no failures. + $this->assertCount(0, $result->failures); + + // Confirm result is an array comprising of each subscriber that was created. + $this->assertIsArray($result->subscribers); + $this->assertCount(2, $result->subscribers); + } + + /** + * Test that tag_subscribers() returns failures when an invalid + * tag ID is specified. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribersWithInvalidTagID() + { + // Create subscribers. + $subscribers = [ + [ + 'email_address' => str_replace('@kit.com', '-1@kit.com', $this->generateEmailAddress()), + ], + [ + 'email_address' => str_replace('@kit.com', '-2@kit.com', $this->generateEmailAddress()), + ], + ]; + $result = $this->api->create_subscribers($subscribers); + + // Set subscriber_id to ensure subscriber is unsubscribed after test. + foreach ($result->subscribers as $i => $subscriber) { + $this->subscriber_ids[] = $subscriber->id; + } + + // Tag subscribers. + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => 12345, + 'subscriber_id' => $this->subscriber_ids[0] + ], + [ + 'tag_id' => 12345, + 'subscriber_id' => $this->subscriber_ids[1] + ], + ] + ); + + // Assert failures. + $this->assertCount(2, $result->failures); + } + + /** + * Test that tag_subscribers() returns failures when an invalid + * subscriber ID is specified. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribersWithInvalidSubscriberID() + { + // Tag subscribers that do not exist. + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => 12345, + ], + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => 67890, + ], + ] + ); + + // Assert failures. + $this->assertCount(2, $result->failures); + } + /** * Test that tag_subscriber_by_email() returns the expected data. * From a8053067cd32e1614afeb05beba8d8377e19ddad Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 7 Oct 2025 17:58:58 +0800 Subject: [PATCH 4/9] PHPStan compat. --- src/ConvertKit_API_Traits.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index 5f47b92..f6bc7b0 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -605,7 +605,7 @@ public function update_tag_name(int $tag_id, string $name) /** * Tags the given subscribers with the given existing Tags. * - * @param array> $taggings Taggings, in the format: + * @param array> $taggings Taggings, in the format: * [ * [ * "tag_id" => 0, @@ -616,7 +616,7 @@ public function update_tag_name(int $tag_id, string $name) * "subscriber_id" => 1 * ], * ]. - * @param string $callback_url URL to notify for large batch size when async processing complete. + * @param string $callback_url URL to notify for large batch size when async processing complete. * * @since 2.2.1 * From 26feccb92f8dfa6f2abd4efcc0cbae5be1cdf7e2 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 9 Oct 2025 17:26:33 +0800 Subject: [PATCH 5/9] Remove pointless tests --- tests/ConvertKitAPIKeyTest.php | 46 ---------------------------------- 1 file changed, 46 deletions(-) diff --git a/tests/ConvertKitAPIKeyTest.php b/tests/ConvertKitAPIKeyTest.php index 70df401..2485a05 100644 --- a/tests/ConvertKitAPIKeyTest.php +++ b/tests/ConvertKitAPIKeyTest.php @@ -303,52 +303,6 @@ public function testTagSubscribers() ); } - /** - * Test that tag_subscribers() throws a ClientException when an invalid - * tag ID is specified, as this is only supported using OAuth. - * - * @since 2.2.1 - * - * @return void - */ - public function testTagSubscribersWithInvalidTagID() - { - $this->expectException(ClientException::class); - $result = $this->api->tag_subscribers( - [ - [ - 'tag_id' => 12345, - 'subscriber_id' => (int) $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] - ], - ] - ); - } - - /** - * Test that tag_subscribers() throws a ClientException when an invalid - * subscriber ID is specified, as this is only supported using OAuth. - * - * @since 2.2.1 - * - * @return void - */ - public function testTagSubscribersWithInvalidSubscriberID() - { - $this->expectException(ClientException::class); - $result = $this->api->tag_subscribers( - [ - [ - 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], - 'subscriber_id' => 12345, - ], - [ - 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], - 'subscriber_id' => 67890, - ], - ] - ); - } - /** * Test that add_subscribers_to_forms() throws a ClientException when * attempting to add subscribers to forms, as this is only supported From f778ae425e5de96c7f20109dc036b9203cb19bf5 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 9 Oct 2025 17:28:32 +0800 Subject: [PATCH 6/9] Remove redundant tests --- tests/ConvertKitAPIKeyTest.php | 358 --------------------------------- 1 file changed, 358 deletions(-) diff --git a/tests/ConvertKitAPIKeyTest.php b/tests/ConvertKitAPIKeyTest.php index d6f0b0c..16732f3 100644 --- a/tests/ConvertKitAPIKeyTest.php +++ b/tests/ConvertKitAPIKeyTest.php @@ -246,42 +246,6 @@ public function testCreateTags() ]); } - /** - * Test that create_tags() throws a ClientException when attempting - * to create blank tags, as this is only supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testCreateTagsBlank() - { - $this->expectException(ClientException::class); - $result = $this->api->create_tags([ - '', - '', - ]); - } - - /** - * Test that create_tags() throws a ClientException when creating - * tags that already exists, as this is only supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testCreateTagsThatExist() - { - $this->expectException(ClientException::class); - $result = $this->api->create_tags( - [ - $_ENV['CONVERTKIT_API_TAG_NAME'], - $_ENV['CONVERTKIT_API_TAG_NAME_2'], - ] - ); - } - /** * Test that add_subscribers_to_forms() throws a ClientException when * attempting to add subscribers to forms, as this is only supported @@ -319,167 +283,6 @@ public function testAddSubscribersToForms() ); } - /** - * Test that add_subscribers_to_forms() returns a ClientException - * when a referrer URL is specified, as this is only supported - * using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testAddSubscribersToFormsWithReferrer() - { - // Create subscriber. - $emailAddress = $this->generateEmailAddress(); - $subscriber = $this->api->create_subscriber( - email_address: $emailAddress - ); - - // Set subscriber_id to ensure subscriber is unsubscribed after test. - $this->subscriber_ids[] = $subscriber->subscriber->id; - - $this->expectException(ClientException::class); - - // Add subscribers to forms. - $result = $this->api->add_subscribers_to_forms( - forms_subscribers_ids: [ - [ - 'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID'], - 'subscriber_id' => $subscriber->subscriber->id, - 'referrer' => 'https://mywebsite.com/bfpromo/', - ], - [ - 'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID_2'], - 'subscriber_id' => $subscriber->subscriber->id, - 'referrer' => 'https://mywebsite.com/bfpromo/', - ], - ] - ); - } - - /** - * Test that add_subscribers_to_forms() returns a ClientException - * when a referrer URL with UTM parameters is specified, as this is only - * supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testAddSubscribersToFormsWithReferrerUTMParams() - { - // Define referrer. - $referrerUTMParams = [ - 'utm_source' => 'facebook', - 'utm_medium' => 'cpc', - 'utm_campaign' => 'black_friday', - 'utm_term' => 'car_owners', - 'utm_content' => 'get_10_off', - ]; - $referrer = 'https://mywebsite.com/bfpromo/?' . http_build_query($referrerUTMParams); - - // Create subscriber. - $emailAddress = $this->generateEmailAddress(); - $subscriber = $this->api->create_subscriber( - email_address: $emailAddress - ); - - // Set subscriber_id to ensure subscriber is unsubscribed after test. - $this->subscriber_ids[] = $subscriber->subscriber->id; - - $this->expectException(ClientException::class); - - // Add subscribers to forms. - $result = $this->api->add_subscribers_to_forms( - forms_subscribers_ids: [ - [ - 'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID'], - 'subscriber_id' => $subscriber->subscriber->id, - 'referrer' => $referrer, - ], - [ - 'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID_2'], - 'subscriber_id' => $subscriber->subscriber->id, - 'referrer' => $referrer, - ], - ] - ); - } - - /** - * Test that add_subscribers_to_forms() returns a ClientException - * when invalid Form IDs are specified, as this is only supported - * using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testAddSubscribersToFormsWithInvalidFormIDs() - { - // Create subscriber. - $emailAddress = $this->generateEmailAddress(); - $subscriber = $this->api->create_subscriber( - email_address: $emailAddress - ); - - // Set subscriber_id to ensure subscriber is unsubscribed after test. - $this->subscriber_ids[] = $subscriber->subscriber->id; - - $this->expectException(ClientException::class); - - // Add subscribers to forms. - $result = $this->api->add_subscribers_to_forms( - forms_subscribers_ids: [ - [ - 'form_id' => 9999999, - 'subscriber_id' => $subscriber->subscriber->id, - ], - [ - 'form_id' => 9999999, - 'subscriber_id' => $subscriber->subscriber->id, - ], - ] - ); - } - - /** - * Test that add_subscribers_to_forms() returns a ClientException - * when invalid Subscriber IDs are specified, as this is only supported - * - * @since 2.2.0 - * - * @return void - */ - public function testAddSubscribersToFormsWithInvalidSubscriberIDs() - { - // Create subscriber. - $emailAddress = $this->generateEmailAddress(); - $subscriber = $this->api->create_subscriber( - email_address: $emailAddress - ); - - // Set subscriber_id to ensure subscriber is unsubscribed after test. - $this->subscriber_ids[] = $subscriber->subscriber->id; - - $this->expectException(ClientException::class); - - // Add subscribers to forms. - $result = $this->api->add_subscribers_to_forms( - forms_subscribers_ids: [ - [ - 'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID'], - 'subscriber_id' => 999999, - ], - [ - 'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID_2'], - 'subscriber_id' => 999999, - ], - ] - ); - } - /** * Test that create_subscribers() returns a ClientException * when attempting to create subscribers, as this is only supported @@ -503,43 +306,6 @@ public function testCreateSubscribers() $result = $this->api->create_subscribers($subscribers); } - /** - * Test that create_subscribers() throws a ClientException when no data is specified. - * - * @since 2.2.0 - * - * @return void - */ - public function testCreateSubscribersWithBlankData() - { - $this->expectException(ClientException::class); - $result = $this->api->create_subscribers([ - [], - ]); - } - - /** - * Test that create_subscribers() throws a ClientException when invalid email addresses - * are specified, as this is only supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testCreateSubscribersWithInvalidEmailAddresses() - { - $this->expectException(ClientException::class); - $subscribers = [ - [ - 'email_address' => 'not-an-email-address', - ], - [ - 'email_address' => 'not-an-email-address-again', - ], - ]; - $result = $this->api->create_subscribers($subscribers); - } - /** * Test that create_custom_fields() throws a ClientException * as this is only supported using OAuth. @@ -572,40 +338,6 @@ public function testGetPurchases() $result = $this->api->get_purchases(); } - /** - * Test that get_purchases() throws a ClientException - * when the total count is included, as this is only - * supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testGetPurchasesWithTotalCount() - { - $this->expectException(ClientException::class); - $result = $this->api->get_purchases( - include_total_count: true - ); - } - - /** - * Test that get_purchases() throws a ClientException - * when pagination parameters and per_page limits are specified, - * as this is only supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testGetPurchasesPagination() - { - $this->expectException(ClientException::class); - $result = $this->api->get_purchases( - per_page: 1 - ); - } - /** * Test that get_purchases() throws a ClientException * when a purchase ID is specified, as this is only @@ -621,21 +353,6 @@ public function testGetPurchase() $result = $this->api->get_purchase(12345); } - /** - * Test that get_purchases() throws a ClientException when an invalid - * purchase ID is specified, as this is only supported - * using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testGetPurchaseWithInvalidID() - { - $this->expectException(ClientException::class); - $this->api->get_purchase(12345); - } - /** * Test that create_purchase() throws a ClientException * as this is only supported using OAuth. @@ -681,79 +398,4 @@ public function testCreatePurchase() transaction_time: new DateTime('now'), ); } - - /** - * Test that create_purchase() throws a ClientException when an invalid - * email address is specified, as this is only supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testCreatePurchaseWithInvalidEmailAddress() - { - $this->expectException(ClientException::class); - $this->api->create_purchase( - email_address: 'not-an-email-address', - transaction_id: str_shuffle('wfervdrtgsdewrafvwefds'), - currency: 'usd', - products: [ - [ - 'name' => 'Floppy Disk (512k)', - 'sku' => '7890-ijkl', - 'pid' => 9999, - 'lid' => 7777, - 'quantity' => 2, - 'unit_price' => 5.00, - ], - ], - ); - } - - /** - * Test that create_purchase() throws a ClientException when a blank - * transaction ID is specified, as this is only supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testCreatePurchaseWithBlankTransactionID() - { - $this->expectException(ClientException::class); - $this->api->create_purchase( - email_address: $this->generateEmailAddress(), - transaction_id: '', - currency: 'usd', - products: [ - [ - 'name' => 'Floppy Disk (512k)', - 'sku' => '7890-ijkl', - 'pid' => 9999, - 'lid' => 7777, - 'quantity' => 2, - 'unit_price' => 5.00, - ], - ], - ); - } - - /** - * Test that create_purchase() throws a ClientException when no products - * are specified, as this is only supported using OAuth. - * - * @since 2.2.0 - * - * @return void - */ - public function testCreatePurchaseWithNoProducts() - { - $this->expectException(ClientException::class); - $this->api->create_purchase( - email_address: $this->generateEmailAddress(), - transaction_id: str_shuffle('wfervdrtgsdewrafvwefds'), - currency: 'usd', - products: [], - ); - } } From c0c435114f327785b76d545ed30dd61c34a0ddb6 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 9 Oct 2025 19:19:33 +0800 Subject: [PATCH 7/9] Skip tests --- tests/ConvertKitAPIKeyTest.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/ConvertKitAPIKeyTest.php b/tests/ConvertKitAPIKeyTest.php index 2485a05..f504b12 100644 --- a/tests/ConvertKitAPIKeyTest.php +++ b/tests/ConvertKitAPIKeyTest.php @@ -247,8 +247,8 @@ public function testCreateTags() } /** - * Test that create_tags() throws a ClientException when attempting - * to create blank tags, as this is only supported using OAuth. + * Skip this test from ConvertKitAPITest, as testCreateTags() above + * confirms a ClientException is thrown. * * @since 2.2.0 * @@ -256,16 +256,12 @@ public function testCreateTags() */ public function testCreateTagsBlank() { - $this->expectException(ClientException::class); - $result = $this->api->create_tags([ - '', - '', - ]); + $this->markTestSkipped('testCreateTags() above confirms a ClientException is thrown.'); } /** - * Test that create_tags() throws a ClientException when creating - * tags that already exists, as this is only supported using OAuth. + * Skip this test from ConvertKitAPITest, as testCreateTags() above + * confirms a ClientException is thrown. * * @since 2.2.0 * @@ -273,13 +269,7 @@ public function testCreateTagsBlank() */ public function testCreateTagsThatExist() { - $this->expectException(ClientException::class); - $result = $this->api->create_tags( - [ - $_ENV['CONVERTKIT_API_TAG_NAME'], - $_ENV['CONVERTKIT_API_TAG_NAME_2'], - ] - ); + $this->markTestSkipped('testCreateTags() above confirms a ClientException is thrown.'); } /** From 011f51664fa389ada6cf8ff859d823e9ae475d2c Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 9 Oct 2025 19:26:55 +0800 Subject: [PATCH 8/9] Skip tests --- tests/ConvertKitAPIKeyTest.php | 203 +++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) diff --git a/tests/ConvertKitAPIKeyTest.php b/tests/ConvertKitAPIKeyTest.php index 16732f3..c3df735 100644 --- a/tests/ConvertKitAPIKeyTest.php +++ b/tests/ConvertKitAPIKeyTest.php @@ -246,6 +246,53 @@ public function testCreateTags() ]); } + /** + * Skip this test from ConvertKitAPITest, as testCreateTags() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testCreateTagsBlank() + { + $this->markTestSkipped('testCreateTags() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testCreateTags() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testCreateTagsThatExist() + { + $this->markTestSkipped('testCreateTags() above confirms a ClientException is thrown.'); + } + + /** + * Test that tag_subscribers() throws a ClientException when attempting + * to tag subscribers, as this is only supported using OAuth. + * + * @since 2.2.0 + * + * @return void + */ + public function testTagSubscribers() + { + $this->expectException(ClientException::class); + $result = $this->api->tag_subscribers( + [ + [ + 'tag_id' => (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 'subscriber_id' => (int) $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] + ], + ] + ); + } + /** * Test that add_subscribers_to_forms() throws a ClientException when * attempting to add subscribers to forms, as this is only supported @@ -283,6 +330,58 @@ public function testAddSubscribersToForms() ); } + /** + * Skip this test from ConvertKitAPITest, as testAddSubscribersToForms() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testAddSubscribersToFormsWithReferrer() + { + $this->markTestSkipped('testAddSubscribersToForms() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testAddSubscribersToForms() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testAddSubscribersToFormsWithReferrerUTMParams() + { + $this->markTestSkipped('testAddSubscribersToForms() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testAddSubscribersToForms() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testAddSubscribersToFormsWithInvalidFormIDs() + { + $this->markTestSkipped('testAddSubscribersToForms() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testAddSubscribersToForms() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testAddSubscribersToFormsWithInvalidSubscriberIDs() + { + $this->markTestSkipped('testAddSubscribersToForms() above confirms a ClientException is thrown.'); + } + /** * Test that create_subscribers() returns a ClientException * when attempting to create subscribers, as this is only supported @@ -306,6 +405,32 @@ public function testCreateSubscribers() $result = $this->api->create_subscribers($subscribers); } + /** + * Skip this test from ConvertKitAPITest, as testCreateSubscribersWithBlankData() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testCreateSubscribersWithBlankData() + { + $this->markTestSkipped('testCreateSubscribers() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testCreateSubscribersWithBlankData() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testCreateSubscribersWithInvalidEmailAddresses() + { + $this->markTestSkipped('testCreateSubscribers() above confirms a ClientException is thrown.'); + } + /** * Test that create_custom_fields() throws a ClientException * as this is only supported using OAuth. @@ -338,6 +463,32 @@ public function testGetPurchases() $result = $this->api->get_purchases(); } + /** + * Skip this test from ConvertKitAPITest, as testGetPurchases() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testGetPurchasesWithTotalCount() + { + $this->markTestSkipped('testGetPurchases() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testGetPurchases() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testGetPurchasesPagination() + { + $this->markTestSkipped('testGetPurchases() above confirms a ClientException is thrown.'); + } + /** * Test that get_purchases() throws a ClientException * when a purchase ID is specified, as this is only @@ -353,6 +504,19 @@ public function testGetPurchase() $result = $this->api->get_purchase(12345); } + /** + * Skip this test from ConvertKitAPITest, as testGetPurchase() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testGetPurchaseWithInvalidID() + { + $this->markTestSkipped('testGetPurchase() above confirms a ClientException is thrown.'); + } + /** * Test that create_purchase() throws a ClientException * as this is only supported using OAuth. @@ -398,4 +562,43 @@ public function testCreatePurchase() transaction_time: new DateTime('now'), ); } + + /** + * Skip this test from ConvertKitAPITest, as testCreatePurchase() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testCreatePurchaseWithInvalidEmailAddress() + { + $this->markTestSkipped('testCreatePurchase() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testCreatePurchase() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testCreatePurchaseWithBlankTransactionID() + { + $this->markTestSkipped('testCreatePurchase() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testCreatePurchase() above + * confirms a ClientException is thrown. + * + * @since 2.2.0 + * + * @return void + */ + public function testCreatePurchaseWithNoProducts() + { + $this->markTestSkipped('testCreatePurchase() above confirms a ClientException is thrown.'); + } } From 8817aee8ec6a2c1143e9cb1b695ea15134a5b8b0 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 9 Oct 2025 21:30:46 +0800 Subject: [PATCH 9/9] Skip tag_subscribers() tests for API Keys --- tests/ConvertKitAPIKeyTest.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/ConvertKitAPIKeyTest.php b/tests/ConvertKitAPIKeyTest.php index f504b12..5c8872d 100644 --- a/tests/ConvertKitAPIKeyTest.php +++ b/tests/ConvertKitAPIKeyTest.php @@ -276,7 +276,7 @@ public function testCreateTagsThatExist() * Test that tag_subscribers() throws a ClientException when attempting * to tag subscribers, as this is only supported using OAuth. * - * @since 2.2.0 + * @since 2.2.1 * * @return void */ @@ -293,6 +293,32 @@ public function testTagSubscribers() ); } + /** + * Skip this test from ConvertKitAPITest, as testTagSubscribers() above + * confirms a ClientException is thrown. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribersWithInvalidTagID() + { + $this->markTestSkipped('testTagSubscribers() above confirms a ClientException is thrown.'); + } + + /** + * Skip this test from ConvertKitAPITest, as testTagSubscribers() above + * confirms a ClientException is thrown. + * + * @since 2.2.1 + * + * @return void + */ + public function testTagSubscribersWithInvalidSubscriberID() + { + $this->markTestSkipped('testTagSubscribers() above confirms a ClientException is thrown.'); + } + /** * Test that add_subscribers_to_forms() throws a ClientException when * attempting to add subscribers to forms, as this is only supported