Фиксы геттеров логина и пароля для `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, EmptyLoginException,
EmptyPasswordException, EmptyPasswordException,
TooLongLoginException, TooLongLoginException,
TooLongPasswordException TooLongPasswordException};
}; use AtolOnline\TestEnvParams;
use GuzzleHttp\{ use GuzzleHttp\{
Client, Client,
Exception\GuzzleException Exception\GuzzleException};
};
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
/** /**
@ -78,8 +77,7 @@ abstract class AtolClient
?string $login = null, ?string $login = null,
?string $password = null, ?string $password = null,
array $config = [] array $config = []
) ) {
{
$this->http = new Client( $this->http = new Client(
array_merge($config, [ array_merge($config, [
'http_errors' => $config['http_errors'] ?? false, 'http_errors' => $config['http_errors'] ?? false,
@ -149,9 +147,12 @@ abstract class AtolClient
* *
* @return string|null * @return string|null
*/ */
#[Pure]
public function getLogin(): ?string 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 * @return string|null
*/ */
#[Pure]
public function getPassword(): ?string 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 $login
* @param string|null $password * @param string|null $password
@ -294,8 +298,8 @@ abstract class AtolClient
public function auth(?string $login = null, ?string $password = null): bool public function auth(?string $login = null, ?string $password = null): bool
{ {
if (empty($this->getToken())) { if (empty($this->getToken())) {
$login && $this->setLogin($login); !is_null($login) && $this->setLogin($login);
$password && $this->setPassword($password); !is_null($password) && $this->setPassword($password);
if ($token = $this->doAuth()) { if ($token = $this->doAuth()) {
$this->setToken($token); $this->setToken($token);
} }

View File

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