From 573af15bac0ad0da9ec7a0e2ee4aede125f52c1d Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Thu, 16 Dec 2021 18:35:49 +0800 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B=20=D0=B3=D0=B5?= =?UTF-8?q?=D1=82=D1=82=D0=B5=D1=80=D0=BE=D0=B2=20=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B8=20=D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20`AtolClient`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Api/AtolClient.php | 26 +++++++++++-------- tests/AtolOnline/Tests/Api/KktMonitorTest.php | 7 +++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Api/AtolClient.php b/src/Api/AtolClient.php index 9b63445..6bae018 100644 --- a/src/Api/AtolClient.php +++ b/src/Api/AtolClient.php @@ -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); } diff --git a/tests/AtolOnline/Tests/Api/KktMonitorTest.php b/tests/AtolOnline/Tests/Api/KktMonitorTest.php index 34ccb7f..af0836b 100644 --- a/tests/AtolOnline/Tests/Api/KktMonitorTest.php +++ b/tests/AtolOnline/Tests/Api/KktMonitorTest.php @@ -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']); } /**