Skip to content

Commit 8754ed6

Browse files
committed
Fix tests
1 parent ebe0e95 commit 8754ed6

1 file changed

Lines changed: 52 additions & 7 deletions

File tree

tests/ConvertKitAPITest.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,8 @@ public function testGetInlineSnippets()
16451645
$this->assertDataExists($result, 'snippets');
16461646
$this->assertPaginationExists($result);
16471647

1648-
// Assert two snippets were returned.
1649-
$this->assertCount(2, $result->snippets);
1648+
// Assert snippets were returned.
1649+
$this->assertGreaterThan(0, count($result->snippets));
16501650
}
16511651

16521652
/**
@@ -1671,6 +1671,28 @@ public function testGetBlockSnippets()
16711671
$this->assertCount(0, $result->snippets);
16721672
}
16731673

1674+
/**
1675+
* Test that get_snippets() returns the expected data when
1676+
* the archived parameter is used.
1677+
*
1678+
* @since 2.5.0
1679+
*
1680+
* @return void
1681+
*/
1682+
public function testGetSnippetsWithArchivedParam()
1683+
{
1684+
$result = $this->api->get_snippets(
1685+
archived: true
1686+
);
1687+
1688+
// Assert snippets and pagination exist.
1689+
$this->assertDataExists($result, 'snippets');
1690+
$this->assertPaginationExists($result);
1691+
1692+
// Assert snippets were returned.
1693+
$this->assertGreaterThan(0, count($result->snippets));
1694+
}
1695+
16741696
/**
16751697
* Test that get_snippets() returns the expected data
16761698
* when the total count is included.
@@ -1698,7 +1720,7 @@ public function testGetSnippetsWithTotalCount()
16981720
* Test that get_snippets() returns the expected data when
16991721
* pagination parameters and per_page limits are specified.
17001722
*
1701-
* @since 2.0.0
1723+
* @since 2.5.0
17021724
*
17031725
* @return void
17041726
*/
@@ -1751,14 +1773,28 @@ public function testGetSnippetsPagination()
17511773
}
17521774

17531775
/**
1754-
* Test that create_snippet() and update_snippet() works.
1776+
* Test that create_snippet() works.
17551777
*
17561778
* @since 2.5.0
17571779
*
17581780
* @return void
17591781
*/
1760-
public function testCreateAndUpdateSnippet()
1782+
public function testCreateSnippet()
17611783
{
1784+
// Add mock handler for this API request, as the API doesn't provide
1785+
// a method to delete snippets to cleanup the test.
1786+
$this->api = $this->mockResponse(
1787+
api: $this->api,
1788+
responseBody: [
1789+
'snippet' => [
1790+
'id' => 12345,
1791+
'name' => 'Test Snippet',
1792+
'snippet_type' => 'inline',
1793+
'content' => 'Test Content',
1794+
],
1795+
]
1796+
);
1797+
17621798
// Create a snippet.
17631799
$result = $this->api->create_snippet(
17641800
name: 'Test Snippet',
@@ -1773,10 +1809,19 @@ public function testCreateAndUpdateSnippet()
17731809
$this->assertEquals('Test Snippet', $result['name']);
17741810
$this->assertEquals('inline', $result['snippet_type']);
17751811
$this->assertEquals('Test Content', $result['content']);
1812+
}
17761813

1777-
// Update the existing sequence.
1814+
/**
1815+
* Test that update_snippet() works.
1816+
*
1817+
* @since 2.5.0
1818+
*
1819+
* @return void
1820+
*/
1821+
public function testUpdateSnippet()
1822+
{
17781823
$result = $this->api->update_snippet(
1779-
snippet_id: $snippetID,
1824+
snippet_id: (int) $_ENV['CONVERTKIT_API_SNIPPET_ID'],
17801825
name: 'Edited Test Snippet',
17811826
snippet_type: 'inline',
17821827
content: 'Edited Test Content'

0 commit comments

Comments
 (0)