Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 API: Mock Create Tag Tests #90

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion tests/ConvertKitAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,24 @@ public function testGetTagsPagination()
public function testCreateTag()
{
$tagName = 'Tag Test ' . mt_rand();

// Add mock handler for this API request, as the API doesn't provide
// a method to delete tags to cleanup the test.
$this->api = $this->mockResponse(
api: $this->api,
responseBody: [
'tag' => [
'id' => 12345,
'name' => $tagName,
'created_at' => date('Y-m-d') . 'T' . date('H:i:s') . 'Z',
],
]
);

// Send request.
$result = $this->api->create_tag($tagName);

// Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
// Assert response contains correct data.
$tag = get_object_vars($result->tag);
$this->assertArrayHasKey('id', $tag);
$this->assertArrayHasKey('name', $tag);
Expand Down Expand Up @@ -1678,6 +1693,28 @@ public function testCreateTags()
'Tag Test ' . mt_rand(),
'Tag Test ' . mt_rand(),
];

// Add mock handler for this API request, as the API doesn't provide
// a method to delete tags to cleanup the test.
$this->api = $this->mockResponse(
api: $this->api,
responseBody: [
'tags' => [
[
'id' => 12345,
'name' => $tagNames[0],
'created_at' => date('Y-m-d') . 'T' . date('H:i:s') . 'Z',
],
[
'id' => 23456,
'name' => $tagNames[1],
'created_at' => date('Y-m-d') . 'T' . date('H:i:s') . 'Z',
],
],
'failures' => [],
]
);

$result = $this->api->create_tags($tagNames);

// Assert no failures.
Expand Down
Loading