Фиксы геттеров логина и пароля для `AtolClient`

pull/15/head
Anthony Axenov 2021-12-16 18:35:49 +08:00
parent 19653776c5
commit 573af15bac
2 changed files with 18 additions and 15 deletions

View File

@ -17,12 +17,11 @@ use AtolOnline\Exceptions\{
EmptyLoginException,
EmptyPasswordException,
TooLongLoginException,
TooLongPasswordException
};
TooLongPasswordException};
use AtolOnline\TestEnvParams;
use GuzzleHttp\{
Client,
Exception\GuzzleException
};
Exception\GuzzleException};
use JetBrains\PhpStorm\Pure;
/**
@ -78,8 +77,7 @@ abstract class AtolClient
?string $login = null,
?string $password = null,
array $config = []
)
{
) {
$this->http = new Client(
array_merge($config, [
'http_errors' => $config['http_errors'] ?? false,
@ -149,9 +147,12 @@ abstract class AtolClient
*
* @return string|null
*/
#[Pure]
public function getLogin(): ?string
{
return $this->login;
return $this->isTestMode()
? TestEnvParams::FFD105()['login']
: $this->login;
}
/**
@ -179,9 +180,12 @@ abstract class AtolClient
*
* @return string|null
*/
#[Pure]
public function getPassword(): ?string
{
return $this->password;
return $this->isTestMode()
? TestEnvParams::FFD105()['password']
: $this->password;
}
/**
@ -279,7 +283,7 @@ abstract class AtolClient
/**
* Выполняет авторизацию на сервере АТОЛ
*
* Авторизация выолнится только если неизвестен токен
* Авторизация выполнится только если неизвестен токен
*
* @param string|null $login
* @param string|null $password
@ -294,8 +298,8 @@ abstract class AtolClient
public function auth(?string $login = null, ?string $password = null): bool
{
if (empty($this->getToken())) {
$login && $this->setLogin($login);
$password && $this->setPassword($password);
!is_null($login) && $this->setLogin($login);
!is_null($password) && $this->setPassword($password);
if ($token = $this->doAuth()) {
$this->setToken($token);
}

View File

@ -32,7 +32,7 @@ use GuzzleHttp\Exception\GuzzleException;
class KktMonitorTest extends BasicTestCase
{
/**
* Возвращает объект клиента для тестирования с тестовым API АТОЛ
* Возвращает объект монитора для тестирования с тестовым API АТОЛ
*
* @return KktMonitor
* @throws EmptyLoginException
@ -42,10 +42,9 @@ class KktMonitorTest extends BasicTestCase
*/
private function newTestClient(): KktMonitor
{
$credentials = TestEnvParams::FFD105();
return (new KktMonitor(true))
->setLogin($credentials['login'])
->setPassword($credentials['password']);
->setLogin(TestEnvParams::FFD105()['login'])
->setPassword(TestEnvParams::FFD105()['password']);
}
/**