Skip to content

Commit 59c50ab

Browse files
authored
Merge pull request #93 from ConvertKit/v4-api-improve-subscriber-tests
v4 API: Improve Subscriber Tests
2 parents dba401b + 0abfdc3 commit 59c50ab

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

tests/ConvertKitAPITest.php

+48-8
Original file line numberDiff line numberDiff line change
@@ -1162,16 +1162,26 @@ public function testGetSequencesPagination()
11621162
*/
11631163
public function testAddSubscriberToSequenceByEmail()
11641164
{
1165+
// Create subscriber.
1166+
$emailAddress = $this->generateEmailAddress();
1167+
$subscriber = $this->api->create_subscriber(
1168+
email_address: $emailAddress
1169+
);
1170+
1171+
// Set subscriber_id to ensure subscriber is unsubscribed after test.
1172+
$this->subscriber_ids[] = $subscriber->subscriber->id;
1173+
1174+
// Add subscriber to sequence.
11651175
$result = $this->api->add_subscriber_to_sequence_by_email(
11661176
sequence_id: $_ENV['CONVERTKIT_API_SEQUENCE_ID'],
1167-
email_address: $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']
1177+
email_address: $emailAddress
11681178
);
11691179
$this->assertInstanceOf('stdClass', $result);
11701180
$this->assertArrayHasKey('subscriber', get_object_vars($result));
11711181
$this->assertArrayHasKey('id', get_object_vars($result->subscriber));
11721182
$this->assertEquals(
11731183
get_object_vars($result->subscriber)['email_address'],
1174-
$_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']
1184+
$emailAddress
11751185
);
11761186
}
11771187

@@ -1218,14 +1228,23 @@ public function testAddSubscriberToSequenceByEmailWithInvalidEmailAddress()
12181228
*/
12191229
public function testAddSubscriberToSequence()
12201230
{
1231+
// Create subscriber.
1232+
$subscriber = $this->api->create_subscriber(
1233+
email_address: $this->generateEmailAddress()
1234+
);
1235+
1236+
// Set subscriber_id to ensure subscriber is unsubscribed after test.
1237+
$this->subscriber_ids[] = $subscriber->subscriber->id;
1238+
1239+
// Add subscriber to sequence.
12211240
$result = $this->api->add_subscriber_to_sequence(
12221241
sequence_id: (int) $_ENV['CONVERTKIT_API_SEQUENCE_ID'],
1223-
subscriber_id: $_ENV['CONVERTKIT_API_SUBSCRIBER_ID']
1242+
subscriber_id: $subscriber->subscriber->id
12241243
);
12251244
$this->assertInstanceOf('stdClass', $result);
12261245
$this->assertArrayHasKey('subscriber', get_object_vars($result));
12271246
$this->assertArrayHasKey('id', get_object_vars($result->subscriber));
1228-
$this->assertEquals(get_object_vars($result->subscriber)['id'], $_ENV['CONVERTKIT_API_SUBSCRIBER_ID']);
1247+
$this->assertEquals(get_object_vars($result->subscriber)['id'], $subscriber->subscriber->id);
12291248
}
12301249

12311250
/**
@@ -2416,14 +2435,27 @@ public function testGetResourcesInvalidResourceType()
24162435
*/
24172436
public function testAddSubscriberToFormByEmail()
24182437
{
2438+
// Create subscriber.
2439+
$emailAddress = $this->generateEmailAddress();
2440+
$subscriber = $this->api->create_subscriber(
2441+
email_address: $emailAddress
2442+
);
2443+
2444+
// Set subscriber_id to ensure subscriber is unsubscribed after test.
2445+
$this->subscriber_ids[] = $subscriber->subscriber->id;
2446+
2447+
// Add subscriber to form.
24192448
$result = $this->api->add_subscriber_to_form_by_email(
24202449
form_id: (int) $_ENV['CONVERTKIT_API_FORM_ID'],
2421-
email_address: $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']
2450+
email_address: $emailAddress
24222451
);
24232452
$this->assertInstanceOf('stdClass', $result);
24242453
$this->assertArrayHasKey('subscriber', get_object_vars($result));
24252454
$this->assertArrayHasKey('id', get_object_vars($result->subscriber));
2426-
$this->assertEquals(get_object_vars($result->subscriber)['id'], $_ENV['CONVERTKIT_API_SUBSCRIBER_ID']);
2455+
$this->assertEquals(
2456+
get_object_vars($result->subscriber)['email_address'],
2457+
$emailAddress
2458+
);
24272459
}
24282460

24292461
/**
@@ -2469,14 +2501,22 @@ public function testAddSubscriberToFormByEmailWithInvalidEmailAddress()
24692501
*/
24702502
public function testAddSubscriberToForm()
24712503
{
2504+
// Create subscriber.
2505+
$subscriber = $this->api->create_subscriber(
2506+
email_address: $this->generateEmailAddress()
2507+
);
2508+
2509+
// Set subscriber_id to ensure subscriber is unsubscribed after test.
2510+
$this->subscriber_ids[] = $subscriber->subscriber->id;
2511+
24722512
$result = $this->api->add_subscriber_to_form(
24732513
form_id: (int) $_ENV['CONVERTKIT_API_FORM_ID'],
2474-
subscriber_id: $_ENV['CONVERTKIT_API_SUBSCRIBER_ID']
2514+
subscriber_id: $subscriber->subscriber->id
24752515
);
24762516
$this->assertInstanceOf('stdClass', $result);
24772517
$this->assertArrayHasKey('subscriber', get_object_vars($result));
24782518
$this->assertArrayHasKey('id', get_object_vars($result->subscriber));
2479-
$this->assertEquals(get_object_vars($result->subscriber)['id'], $_ENV['CONVERTKIT_API_SUBSCRIBER_ID']);
2519+
$this->assertEquals(get_object_vars($result->subscriber)['id'], $subscriber->subscriber->id);
24802520
}
24812521

24822522
/**

0 commit comments

Comments
 (0)