Assert that version is cached

This commit is contained in:
Phan An 2018-08-30 12:42:47 +07:00
parent b91d478fdf
commit c4beca787b
2 changed files with 8 additions and 1 deletions

View file

@ -10,6 +10,8 @@ use Illuminate\Log\Logger;
class ApplicationInformationService
{
private const CACHE_KEY = 'latestKoelVersion';
private $client;
private $cache;
private $logger;
@ -26,7 +28,7 @@ class ApplicationInformationService
*/
public function getLatestVersionNumber(): string
{
return $this->cache->remember('latestKoelVersion', 1 * 24 * 60, function (): string {
return $this->cache->remember(self::CACHE_KEY, 1 * 24 * 60, function (): string {
try {
return json_decode(
$this->client->get('https://api.github.com/repos/phanan/koel/tags')->getBody()

View file

@ -3,6 +3,7 @@
namespace Tests\Integration\Services;
use App\Services\ApplicationInformationService;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
@ -13,6 +14,9 @@ use Tests\TestCase;
class ApplicationInformationServiceTest extends TestCase
{
/**
* @throws Exception
*/
public function testGetLatestVersionNumber(): void
{
$latestVersion = 'v1.1.2';
@ -25,5 +29,6 @@ class ApplicationInformationServiceTest extends TestCase
$service = new ApplicationInformationService($client, app(Cache::class), app(Logger::class));
self::assertEquals($latestVersion, $service->getLatestVersionNumber());
self::assertSame($latestVersion, cache('latestKoelVersion'));
}
}