Skip to content

Commit

Permalink
fix: fix PSR-16 client testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed Oct 16, 2023
1 parent 74d7ba4 commit 2b9ac13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Cache/CacheClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function deleteCache(string $cacheName): DeleteCacheResponse
/**
* Flush a cache.
*
* @param string $cacheName Name of the cache to delete.
* @param string $cacheName Name of the cache to flush.
* @return FlushCacheResponse Represents the result of the flush cache operation. This result is
* resolved to a type-safe object of one of the following types:<br>
* * FlushCacheSuccess<br>
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Psr16CacheClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
ICredentialProvider $authProvider,
?int $defaultTtlSeconds,
?bool $throwExceptions = null,
?string $cacheName = null
?string $cacheName = null
)
{
$ttlSeconds = $defaultTtlSeconds ?? self::DEFAULT_TTL_SECONDS;
Expand Down
22 changes: 18 additions & 4 deletions tests/Cache/Psr16ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Momento\Tests\Cache;

use DateTime;
use Momento\Auth\CredentialProvider;
use Momento\Auth\EnvMomentoTokenProvider;
use Momento\Cache\Errors\InvalidArgumentError;
use Momento\Cache\Errors\InvalidArgumentException;
Expand All @@ -23,16 +24,29 @@
class Psr16ClientTest extends TestCase
{
private int $DEFAULT_TTL_SECONDS = 10;
private Configuration $configuration;
private CredentialProvider $authProvider;
private Psr16CacheClient $client;
private string $cacheName;

public function setUp(): void
{
$this->cacheName = uniqid("php-psr16-test-");
$loggerFactory = new NullLoggerFactory();
$grpcConfiguration = new StaticGrpcConfiguration(5000);
$transportStrategy = new StaticTransportStrategy($grpcConfiguration);
$configuration = new Configuration($loggerFactory, $transportStrategy);
$authProvider = new EnvMomentoTokenProvider("TEST_AUTH_TOKEN");
$this->client = new Psr16CacheClient($configuration, $authProvider, $this->DEFAULT_TTL_SECONDS);
$this->configuration = new Configuration($loggerFactory, $transportStrategy);
$this->authProvider = new EnvMomentoTokenProvider("TEST_AUTH_TOKEN");
$this->client = new Psr16CacheClient(
$configuration, $authProvider, $this->DEFAULT_TTL_SECONDS, $this->cacheName
);
}

public function tearDown(): void
{
parent::tearDown();
$momento = new CacheClient($this->configuration, $this->authProvider, $this->DEFAULT_TTL_SECONDS);
$momento->deleteCache($this->cacheName);
}

public function testDateIntervalToSeconds()
Expand Down Expand Up @@ -93,7 +107,7 @@ public function dataTypeProvider(): array

public function testOverrideDefaultCacheName()
{
$testCacheName = "PSR16-test-cache";
$testCacheName = uniqid("php-PSR16-name-test");
$configuration = Laptop::latest();
$authProvider = new EnvMomentoTokenProvider("TEST_AUTH_TOKEN");
$client = new CacheClient(
Expand Down

0 comments on commit 2b9ac13

Please sign in to comment.