Skip to content

Commit 071c60f

Browse files
committed
add unit test for co api token cache
1 parent 7773e93 commit 071c60f

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/Service/CourseProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class CourseProvider implements CourseProviderInterface, LoggerAwareInterface
5959

6060
private ?CourseApi $courseApi = null;
6161
private array $config = [];
62-
private ?CacheItemPoolInterface $cachePool = null;
63-
private int $cacheTTL = 0;
6462
private ?CacheItemPoolInterface $campusonlineApiCacheItemPool = null;
6563
/**
6664
* @var string[]
@@ -173,6 +171,7 @@ public function setCampusonlineApiCacheItemPool(?CacheItemPoolInterface $coCache
173171
}
174172

175173
$this->campusonlineApiCacheItemPool = $coCacheItemPool;
174+
$this->courseApi?->getConnection()->setCache($coCacheItemPool);
176175
}
177176

178177
private function getEventTimeZone(): \DateTimeZone

tests/Service/CourseProviderTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use GuzzleHttp\HandlerStack;
2626
use GuzzleHttp\Psr7\Response;
2727
use Psr\Log\NullLogger;
28+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2829
use Symfony\Component\EventDispatcher\EventDispatcher;
2930

3031
class CourseProviderTest extends ApiTestCase
@@ -1773,6 +1774,28 @@ public function testGetCourseEventByIdentifier(): void
17731774
$this->assertSame('CLASS', $courseEvent->getTypeKey());
17741775
}
17751776

1777+
public function testCampusononlineApiTokenCache(): void
1778+
{
1779+
$this->courseProvider->setCampusonlineApiCacheItemPool(new ArrayAdapter());
1780+
1781+
$this->mockResponses([
1782+
new Response(200, ['Content-Type' => 'application/json;charset=utf-8'],
1783+
file_get_contents(__DIR__.'/appointment_api_item_response.json')),
1784+
]);
1785+
$courseEvent = $this->courseProvider->getCourseEventById('1');
1786+
$this->assertSame('1', $courseEvent->getIdentifier());
1787+
1788+
$this->courseProvider->reset(); // reset request (in-memory) cache
1789+
1790+
$this->mockResponses([
1791+
new Response(200, ['Content-Type' => 'application/json;charset=utf-8'],
1792+
file_get_contents(__DIR__.'/appointment_api_item_response.json')),
1793+
], mockAuthServerResponses: false
1794+
);
1795+
$courseEvent = $this->courseProvider->getCourseEventById('1');
1796+
$this->assertSame('1', $courseEvent->getIdentifier());
1797+
}
1798+
17761799
public function testGetCourseEventByIdentifierNotFound(): void
17771800
{
17781801
$this->mockResponses([

0 commit comments

Comments
 (0)