CheckRefreshTokenRatioTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace YdbPlatform\Ydb\Test;
  3. use PHPUnit\Framework\TestCase;
  4. use YdbPlatform\Ydb\Exception;
  5. use YdbPlatform\Ydb\Ydb;
  6. use YdbPlatform\Ydb\YdbTable;
  7. class CheckRefreshTokenRatioTest extends TestCase
  8. {
  9. public function testRefreshTokenRatio()
  10. {
  11. $awaitException = [0, 1];
  12. $awaitNormal = [0.05, 0.9];
  13. $config = [
  14. // Database path
  15. 'database' => '/local',
  16. // Database endpoint
  17. 'endpoint' => 'localhost:2136',
  18. // Auto discovery (dedicated server only)
  19. 'discovery' => false,
  20. // IAM config
  21. 'iam_config' => [
  22. 'anonymous' => true,
  23. 'insecure' => true
  24. ],
  25. ];
  26. $ydb = new Ydb($config);
  27. self::assertEquals(0.1,
  28. $ydb->iam()->config('credentials')->getRefreshTokenRatio()
  29. );
  30. foreach ($awaitNormal as $ratio){
  31. $config['iam_config']['refresh_token_ratio'] = $ratio;
  32. $ydb = new Ydb($config);
  33. self::assertEquals($ratio,
  34. $ydb->iam()->config('credentials')->getRefreshTokenRatio()
  35. );
  36. }
  37. foreach ($awaitException as $ratio) {
  38. $config['iam_config']['refresh_token_ratio'] = $ratio;
  39. $this->expectExceptionObject(new \Exception("Refresh token ratio. Expected number between 0 and 1."));
  40. $ydb = new Ydb($config);
  41. $ydb->iam()->config('credentials')->getRefreshTokenRatio();
  42. }
  43. }
  44. }