Skip to content

Commit

Permalink
Fix cache tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaitholabi committed Oct 25, 2020
1 parent 5775a06 commit 1999987
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
run: TESTSUITE=integration MINCOVERAGE=85 ci/test.sh

- name: Execute Cache tests
run: ./vendor/bin/phpunit --testsuite=cache --stop-on-fail
run: /vendor/bin/phpunit --testsuite=cache --stop-on-fail
45 changes: 45 additions & 0 deletions test/AppTestTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php declare(strict_types=1);

namespace SupportPal\ApiClient\Tests;

use PHPUnit\Framework\TestCase;
use SupportPal\ApiClient\SupportPal;

use function dd;

class AppTestCase extends TestCase
{
public function testApps()
{
$sp = new SupportPal(
'http://localhost:8080/',
'xp6BhmJU2WH6v22ATd=5cSDcz785yUte',
['whmcs' => 1],
['whmcs' => 1]
);

dd($sp->getCoreApi()->getSettings());
// $createTicket = new CreateTicket;
// $createTicket->fill(
// [
// 'department' => 1,
// 'status' => 1,
// 'priority' => 2,
// 'subject' => 'subject',
// 'text' => 'text',
// 'name' => 'test',
// 'user_email' => 'test@email.com'
// ]
// );
//
// $createUser = (new CreateUser)->fill(['email' => 'newtestnametest@test.com']);
//
// /** @var User $user */
// $user = $sp->getApi()->getUsers(['start' => 50])->filter(function (User $user) {
// return $user->getId() === 62;
// })->first();
//
// $updated = $sp->getApi()->updateUser($user, ['email' => 'hello@email.com']);
// dd($updated);
}
}
87 changes: 53 additions & 34 deletions test/Cache/CacheableApisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
use Kevinrob\GuzzleCache\CacheMiddleware;
use Kevinrob\GuzzleCache\Strategy\CacheStrategyInterface;
use SupportPal\ApiClient\ApiClient;
use SupportPal\ApiClient\ApiClient\CoreApiClient;
use SupportPal\ApiClient\ApiClient\SelfServiceApiClient;
use SupportPal\ApiClient\ApiClient\TicketApiClient;
use SupportPal\ApiClient\ApiClient\UserApiClient;
use SupportPal\ApiClient\Cache\ApiCacheMap;
use SupportPal\ApiClient\Cache\CacheStrategyConfigurator;
use SupportPal\ApiClient\Dictionary\ApiDictionary;
Expand Down Expand Up @@ -43,13 +47,18 @@ class CacheableApisTest extends ContainerAwareBaseTestCase
* @param string $endpoint
* @param array<mixed> $data
* @param array<mixed> $parameters
* @param class-string $apiClientClass
* @throws Exception
* @dataProvider provideCacheableApiCalls
*/
public function testGetCacheableApiTestCacheHit(string $endpoint, array $data, array $parameters): void
{
public function testGetCacheableApiTestCacheHit(
string $endpoint,
array $data,
array $parameters,
string $apiClientClass
): void {
/** @var ApiClient $apiClient */
$apiClient = $this->getContainer()->get(ApiClient::class);
$apiClient = $this->getContainer()->get($apiClientClass);

$response = new Response(200, [], (string) $this->getEncoder()->encode($data, $this->getFormatType()));
$response2 = new Response(200, [], (string) $this->getEncoder()->encode($data, $this->getFormatType()));
Expand Down Expand Up @@ -78,13 +87,18 @@ public function testGetCacheableApiTestCacheHit(string $endpoint, array $data, a
* @param string $endpoint
* @param array<mixed> $data
* @param array<mixed> $parameters
* @param class-string $apiClientClass
* @throws Exception
* @dataProvider provideCacheableApiCalls
*/
public function testGetCacheableApiTestCacheMiss(string $endpoint, array $data, array $parameters): void
{
public function testGetCacheableApiTestCacheMiss(
string $endpoint,
array $data,
array $parameters,
string $apiClientClass
): void {
/** @var ApiClient $apiClient */
$apiClient = $this->getContainer()->get(ApiClient::class);
$apiClient = $this->getContainer()->get($apiClientClass);

$response = new Response(200, [], (string) $this->getEncoder()->encode($data, $this->getFormatType()));
$response2 = new Response(200, [], (string) $this->getEncoder()->encode($data, $this->getFormatType()));
Expand Down Expand Up @@ -114,13 +128,18 @@ public function testGetCacheableApiTestCacheMiss(string $endpoint, array $data,
* @param string $endpoint
* @param array<mixed> $data
* @param array<mixed> $parameters
* @param class-string $apiClientClass
* @throws Exception
* @dataProvider provideNonCacheableApis
*/
public function testNonCacheableApisAlwaysMiss(string $endpoint, array $data, array $parameters): void
{
public function testNonCacheableApisAlwaysMiss(
string $endpoint,
array $data,
array $parameters,
string $apiClientClass
): void {
/** @var ApiClient $apiClient */
$apiClient = $this->getContainer()->get(ApiClient::class);
$apiClient = $this->getContainer()->get($apiClientClass);

$response = new Response(200, [], (string) $this->getEncoder()->encode($data, $this->getFormatType()));
$response2 = new Response(200, [], (string) $this->getEncoder()->encode($data, $this->getFormatType()));
Expand Down Expand Up @@ -167,15 +186,15 @@ public function provideCacheableApiCalls(): iterable
$articleData = new ArticleData;
$tagData = new TagData;

yield ['getCoreSettings' ,(new CoreSettingsData)->getResponse(), []];
yield ['getCategories' ,$categoryData->getAllResponse(), [[]]];
yield ['getCategory' ,$categoryData->getResponse(), [1]];
yield ['getArticle' ,$articleData->getResponse(), [1, []]];
yield ['getTag' ,$tagData->getResponse(), [1]];
yield ['getArticles' ,$articleData->getAllResponse(), [[]]];
yield ['getSelfServiceSettings' ,$settingsData->getResponse(), []];
yield ['getComments' ,$commentData->getAllResponse(), [[]]];
yield ['getTypes' ,$typeData->getAllResponse(), [[]]];
yield ['getSettings' ,(new CoreSettingsData)->getResponse(), [], CoreApiClient::class];
yield ['getCategories' ,$categoryData->getAllResponse(), [[]], SelfServiceApiClient::class];
yield ['getCategory' ,$categoryData->getResponse(), [1], SelfServiceApiClient::class];
yield ['getArticle' ,$articleData->getResponse(), [1, []], SelfServiceApiClient::class];
yield ['getTag' ,$tagData->getResponse(), [1], SelfServiceApiClient::class];
yield ['getArticles' ,$articleData->getAllResponse(), [[]], SelfServiceApiClient::class];
yield ['getSettings' ,$settingsData->getResponse(), [], SelfServiceApiClient::class];
yield ['getComments' ,$commentData->getAllResponse(), [[]], SelfServiceApiClient::class];
yield ['getTypes' ,$typeData->getAllResponse(), [[]], SelfServiceApiClient::class];
}

/**
Expand All @@ -194,22 +213,22 @@ public function provideNonCacheableApis(): iterable
$messageData = new MessageData;
$userData = new UserData;

yield ['getDepartments', $departmentData->getAllResponse(), [[]]];
yield ['getDepartment', $departmentData->getResponse(), [1]];
yield ['getTicketSettings', $settingsData->getResponse(), []];
yield ['getChannelSettings', $channelSettingsData->getResponse(), ['web']];
yield ['getTicketCustomFields', $ticketCustomFieldData->getAllResponse(), [[]]];
yield ['getTicketPriorities', $priorityData->getAllResponse(), [[]]];
yield ['getTicketPriority', $statusData->getResponse(), [1]];
yield ['getTicketStatuses', $statusData->getAllResponse(), [[]]];
yield ['getTicketStatus', $statusData->getResponse(), [1]];
yield ['getTicketAttachments', $attachmentData->getAllResponse(), [[]]];
yield ['getTicketAttachment', $attachmentData->getResponse(), [1]];
yield ['getTickets', $ticketData->getAllResponse(), [[]]];
yield ['getTicket', $ticketData->getResponse(), [1]];
yield ['getTicketMessage', $messageData->getResponse(), [1]];
yield ['getTicketMessages', $messageData->getAllResponse(), [[]]];
yield ['getUsers', $userData->getAllResponse(), [[]]];
yield ['getDepartments', $departmentData->getAllResponse(), [[]], TicketApiClient::class];
yield ['getDepartment', $departmentData->getResponse(), [1], TicketApiClient::class];
yield ['getSettings', $settingsData->getResponse(), [], TicketApiClient::class];
yield ['getChannelSettings', $channelSettingsData->getResponse(), ['web'], TicketApiClient::class];
yield ['getCustomFields', $ticketCustomFieldData->getAllResponse(), [[]], TicketApiClient::class];
yield ['getPriorities', $priorityData->getAllResponse(), [[]], TicketApiClient::class];
yield ['getPriority', $statusData->getResponse(), [1], TicketApiClient::class];
yield ['getStatuses', $statusData->getAllResponse(), [[]], TicketApiClient::class];
yield ['getStatus', $statusData->getResponse(), [1], TicketApiClient::class];
yield ['getAttachments', $attachmentData->getAllResponse(), [[]], TicketApiClient::class];
yield ['getAttachment', $attachmentData->getResponse(), [1], TicketApiClient::class];
yield ['getTickets', $ticketData->getAllResponse(), [[]], TicketApiClient::class];
yield ['getTicket', $ticketData->getResponse(), [1], TicketApiClient::class];
yield ['getMessage', $messageData->getResponse(), [1], TicketApiClient::class];
yield ['getMessages', $messageData->getAllResponse(), [[]], TicketApiClient::class];
yield ['getUsers', $userData->getAllResponse(), [[]], UserApiClient::class];
}

/**
Expand Down

0 comments on commit 1999987

Please sign in to comment.