Skip to content

Commit e505b5c

Browse files
author
Илья
committed
Fix tests
1 parent c54a319 commit e505b5c

File tree

8 files changed

+51
-39
lines changed

8 files changed

+51
-39
lines changed

src/Auth/ReadFromFileCredentials.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Auth/ReadFromJsonCredentials.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace YdbPlatform\Ydb\Auth;
4+
5+
class ReadFromJsonCredentials extends Auth
6+
{
7+
8+
protected $fileName;
9+
protected $readInterval;
10+
11+
/**
12+
* @param string $fileName
13+
* @param int $readInterval
14+
*/
15+
public function __construct(string $fileName = "token.json", int $readInterval = 600)
16+
{
17+
if(!file_exists($fileName)){
18+
throw new \Exception("File $fileName is not exists");
19+
}
20+
$this->fileName = $fileName;
21+
$this->readInterval = $readInterval;
22+
}
23+
24+
public function getTokenInfo(): TokenInfo
25+
{
26+
if(!file_exists($this->fileName)){
27+
throw new \Exception("File $this->fileName is not exists");
28+
}
29+
$data = json_decode(file_get_contents($this->fileName), true);
30+
if(!isset($data["token"])){
31+
throw new \Exception("File $this->fileName does not contain a token");
32+
}
33+
return new TokenInfo($data["token"], $this->readInterval, 1);
34+
}
35+
36+
public function getName(): string
37+
{
38+
return "from file";
39+
}
40+
}

src/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public function retrySession(Closure $userFunc, bool $idempotent = false, RetryP
481481

482482
}
483483

484-
public function retryTransaction(Closure $userFunc, bool $idempotent = null, RetryParams $params = null, array $options){
484+
public function retryTransaction(Closure $userFunc, bool $idempotent = null, RetryParams $params = null, array $options = null){
485485
if ($options == null) {
486486
$options = [];
487487
}

tests/CheckReadTokenFile.php renamed to tests/CheckReadTokenFileTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
namespace YdbPlatform\Ydb\Test;
33

44
use PHPUnit\Framework\TestCase;
5-
use YdbPlatform\Ydb\Auth\ReadFromFileCredentials;
5+
use YdbPlatform\Ydb\Auth\ReadFromJsonCredentials;
66
use YdbPlatform\Ydb\Ydb;
77
use YdbPlatform\Ydb\YdbTable;
88

9-
class CheckReadTokenFile extends TestCase{
10-
public function testRead(){
9+
class CheckReadTokenFileTest extends TestCase{
10+
public function testReadTokenFile(){
1111
$config = [
1212

1313
// Database path
@@ -19,7 +19,7 @@ public function testRead(){
1919
// Auto discovery (dedicated server only)
2020
'discovery' => false,
2121

22-
'credentials' => new ReadFromFileCredentials("./token.txt")
22+
'credentials' => new ReadFromJsonCredentials("./tests/token.json")
2323
];
2424

2525
$ydb = new Ydb($config);

tests/RetryParamsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use YdbPlatform\Ydb\Retry\Retry;
3131

3232
class RetrySubclass extends Retry{
33-
public function canRetry(Exception $e, bool $idempotent)
33+
public function canRetry(\Exception $e, bool $idempotent)
3434
{
3535
return parent::canRetry($e, $idempotent);
3636
}

tests/TestEnvTypes.php renamed to tests/TestEnvTypesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
use YdbPlatform\Ydb\Ydb;
77
use YdbPlatform\Ydb\YdbTable;
88

9-
class TestEnvTypes extends TestCase{
9+
class TestEnvTypesTest extends TestCase{
1010

1111
public function testEnvTypes(){
1212

1313
$dataset = [
1414
[
1515
"env" => [
1616
"name" => "YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS",
17-
"value" => "./some.json"
17+
"value" => "./tests/some.json"
1818
],
1919
"wait" => "SA JSON key"
2020
],

tests/token.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"token": "test-example-token"
3+
}

tests/token.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)