remove unimportant assert in tests, move utils to service
This commit is contained in:
parent
8c67ed45c5
commit
efdc6e73e7
9 changed files with 65 additions and 36 deletions
|
@ -226,7 +226,9 @@ class RCrmActions
|
|||
*/
|
||||
public static function clearArr($arr)
|
||||
{
|
||||
return \Intaro\RetailCrm\Component\Utils::clearArray($arr);
|
||||
/** @var \Intaro\RetailCrm\Component\Utils $utils */
|
||||
$utils = \Intaro\RetailCrm\Component\ServiceLocator::get(\Intaro\RetailCrm\Component\Utils::class);
|
||||
return $utils->clearArray($arr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -237,7 +239,9 @@ class RCrmActions
|
|||
*/
|
||||
public static function toJSON($str)
|
||||
{
|
||||
return \Intaro\RetailCrm\Component\Utils::toUTF8($str);
|
||||
/** @var \Intaro\RetailCrm\Component\Utils $utils */
|
||||
$utils = \Intaro\RetailCrm\Component\ServiceLocator::get(\Intaro\RetailCrm\Component\Utils::class);
|
||||
return $utils->toUTF8($str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,7 +252,9 @@ class RCrmActions
|
|||
*/
|
||||
public static function fromJSON($str)
|
||||
{
|
||||
return \Intaro\RetailCrm\Component\Utils::fromUTF8($str);
|
||||
/** @var \Intaro\RetailCrm\Component\Utils $utils */
|
||||
$utils = \Intaro\RetailCrm\Component\ServiceLocator::get(\Intaro\RetailCrm\Component\Utils::class);
|
||||
return $utils->fromUTF8($str);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||
use Intaro\RetailCrm\Component\CollectorCookieExtractor;
|
||||
use Intaro\RetailCrm\Service\CollectorCookieExtractor;
|
||||
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
|
||||
|
@ -24,6 +24,7 @@ $builder->setDisableNamespaces(true)
|
|||
AnnotationRegistry::registerLoader('class_exists');
|
||||
|
||||
ServiceLocator::registerServices([
|
||||
\Intaro\RetailCrm\Service\Utils::class,
|
||||
Logger::class,
|
||||
AnnotationReader::class,
|
||||
CollectorCookieExtractor::class
|
||||
|
|
|
@ -15,7 +15,7 @@ use Bitrix\Main\Type\DateTime;
|
|||
use Bitrix\Sale\Order;
|
||||
use Intaro\RetailCrm\Component\Builder\BuilderInterface;
|
||||
use Intaro\RetailCrm\Component\Builder\Exception\BuilderException;
|
||||
use Intaro\RetailCrm\Component\CollectorCookieExtractor;
|
||||
use Intaro\RetailCrm\Service\CollectorCookieExtractor;
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
use Intaro\RetailCrm\Component\Converter\DateTimeConverter;
|
||||
use Intaro\RetailCrm\Component\Events;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Intaro\RetailCrm\Component\Builder\Api;
|
||||
|
||||
use Intaro\RetailCrm\Component\Builder\Exception\BuilderException;
|
||||
use Intaro\RetailCrm\Component\CollectorCookieExtractor;
|
||||
use Intaro\RetailCrm\Service\CollectorCookieExtractor;
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
use Intaro\RetailCrm\Component\Converter\DateTimeConverter;
|
||||
use Intaro\RetailCrm\Component\Events;
|
||||
|
|
|
@ -13,7 +13,8 @@ namespace Intaro\RetailCrm\Component\Builder;
|
|||
|
||||
use Intaro\RetailCrm\Component\Converter\DateTimeConverter;
|
||||
use Intaro\RetailCrm\Component\Events;
|
||||
use Intaro\RetailCrm\Component\Utils;
|
||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||
use Intaro\RetailCrm\Service\Utils;
|
||||
use Intaro\RetailCrm\Model\Api\Customer;
|
||||
use Intaro\RetailCrm\Model\Bitrix\User;
|
||||
|
||||
|
@ -29,6 +30,17 @@ class CustomerBuilder implements BuilderInterface
|
|||
|
||||
/** @var \Intaro\RetailCrm\Model\Api\Customer */
|
||||
protected $customer;
|
||||
|
||||
/** @var Utils */
|
||||
protected $utils;
|
||||
|
||||
/**
|
||||
* CustomerBuilder constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->utils = ServiceLocator::get($this->utils->class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Intaro\RetailCrm\Model\Bitrix\User $user
|
||||
|
@ -124,15 +136,15 @@ class CustomerBuilder implements BuilderInterface
|
|||
protected function buildNames(): void
|
||||
{
|
||||
if (!empty($this->customer->firstName)) {
|
||||
$this->user->setName(Utils::fromUTF8($this->customer->firstName));
|
||||
$this->user->setName($this->utils->fromUTF8($this->customer->firstName));
|
||||
}
|
||||
|
||||
if (!empty($this->customer->lastName)) {
|
||||
$this->user->setLastName(Utils::fromUTF8($this->customer->lastName));
|
||||
$this->user->setLastName($this->utils->fromUTF8($this->customer->lastName));
|
||||
}
|
||||
|
||||
if (!empty($this->customer->patronymic)) {
|
||||
$this->user->setSecondName(Utils::fromUTF8($this->customer->patronymic));
|
||||
$this->user->setSecondName($this->utils->fromUTF8($this->customer->patronymic));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,11 +190,11 @@ class CustomerBuilder implements BuilderInterface
|
|||
{
|
||||
if (!empty($this->customer->address)) {
|
||||
if (!empty($this->customer->address->index)) {
|
||||
$this->user->setPersonalZip(Utils::fromUTF8($this->customer->address->index));
|
||||
$this->user->setPersonalZip($this->utils->fromUTF8($this->customer->address->index));
|
||||
}
|
||||
|
||||
if (!empty($this->customer->address->city)) {
|
||||
$this->user->setPersonalCity(Utils::fromUTF8($this->customer->address->city));
|
||||
$this->user->setPersonalCity($this->utils->fromUTF8($this->customer->address->city));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,11 +209,11 @@ class CustomerBuilder implements BuilderInterface
|
|||
}
|
||||
|
||||
if (!empty($this->customer->email)) {
|
||||
$this->user->setEmail(Utils::fromUTF8($this->customer->email));
|
||||
$this->user->setEmail($this->utils->fromUTF8($this->customer->email));
|
||||
}
|
||||
|
||||
if (!empty($this->customer->sex)) {
|
||||
$this->user->setPersonalGender(Utils::fromUTF8($this->customer->sex));
|
||||
$this->user->setPersonalGender($this->utils->fromUTF8($this->customer->sex));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,11 +223,11 @@ class CustomerBuilder implements BuilderInterface
|
|||
protected function fillFieldsForHistoryClient(): void
|
||||
{
|
||||
if (empty($this->customer->externalId)) {
|
||||
$this->user->setPassword(Utils::createPlaceholderPassword());
|
||||
$this->user->setPassword($this->utils->createPlaceholderPassword());
|
||||
}
|
||||
|
||||
if (empty($this->customer->email) && empty($this->customer->externalId)) {
|
||||
$login = Utils::createPlaceholderEmail();
|
||||
$login = $this->utils->createPlaceholderEmail();
|
||||
$this->user->setLogin($login);
|
||||
$this->user->setEmail($login);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ namespace Intaro\RetailCrm\Model\Api;
|
|||
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\PostDeserialize;
|
||||
use Intaro\RetailCrm\Component\Json\Mapping\PostSerialize;
|
||||
use Intaro\RetailCrm\Component\Utils;
|
||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||
use Intaro\RetailCrm\Service\Utils;
|
||||
|
||||
/**
|
||||
* Class AbstractApiModel
|
||||
|
@ -22,6 +23,17 @@ use Intaro\RetailCrm\Component\Utils;
|
|||
*/
|
||||
class AbstractApiModel implements ApiModelInterface
|
||||
{
|
||||
/** @var Utils */
|
||||
private $utils;
|
||||
|
||||
/**
|
||||
* AbstractApiModel constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->utils = ServiceLocator::get(Utils::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @PostDeserialize()
|
||||
*/
|
||||
|
@ -53,6 +65,6 @@ class AbstractApiModel implements ApiModelInterface
|
|||
*/
|
||||
public function postSerialize(array $fields): array
|
||||
{
|
||||
return Utils::clearArray($fields);
|
||||
return $this->utils->clearArray($fields);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,18 @@
|
|||
* PHP version 7.1
|
||||
*
|
||||
* @category Integration
|
||||
* @package Intaro\RetailCrm\Component
|
||||
* @package Intaro\RetailCrm\Service
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license MIT
|
||||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component;
|
||||
namespace Intaro\RetailCrm\Service;
|
||||
|
||||
/**
|
||||
* Class CollectorCookieExtractor
|
||||
*
|
||||
* @package Intaro\RetailCrm\Component
|
||||
* @package Intaro\RetailCrm\Service
|
||||
*/
|
||||
class CollectorCookieExtractor
|
||||
{
|
|
@ -9,10 +9,9 @@
|
|||
* @link http://retailcrm.ru
|
||||
* @see http://retailcrm.ru/docs
|
||||
*/
|
||||
namespace Intaro\RetailCrm\Component;
|
||||
namespace Intaro\RetailCrm\Service;
|
||||
|
||||
use Bitrix\Main\Text\Encoding;
|
||||
use Intaro\RetailCrm\Model\Api\Order\Order;
|
||||
|
||||
/**
|
||||
* Class Utils
|
||||
|
@ -27,7 +26,7 @@ class Utils
|
|||
* @param array $arr
|
||||
* @return array
|
||||
*/
|
||||
public static function clearArray($arr): array
|
||||
public function clearArray($arr): array
|
||||
{
|
||||
if (is_array($arr) === false) {
|
||||
return $arr;
|
||||
|
@ -36,7 +35,7 @@ class Utils
|
|||
$result = array();
|
||||
|
||||
foreach ($arr as $index => $node) {
|
||||
$result[$index] = is_array($node) === true ? self::clearArray($node) : trim($node);
|
||||
$result[$index] = is_array($node) === true ? $this->clearArray($node) : trim($node);
|
||||
|
||||
if ($result[$index] == '' || $result[$index] === null || count($result[$index]) < 1) {
|
||||
unset($result[$index]);
|
||||
|
@ -52,13 +51,13 @@ class Utils
|
|||
*
|
||||
* @return array|bool|\SplFixedArray|string $str in utf-8
|
||||
*/
|
||||
public static function toUTF8($string)
|
||||
public function toUTF8($string)
|
||||
{
|
||||
if (!defined('SITE_CHARSET')) {
|
||||
throw new \RuntimeException('SITE_CHARSET must be defined.');
|
||||
}
|
||||
|
||||
return static::convertCharset($string, SITE_CHARSET, 'utf-8');
|
||||
return $this->convertCharset($string, SITE_CHARSET, 'utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,13 +66,13 @@ class Utils
|
|||
*
|
||||
* @return array|bool|\SplFixedArray|string $str in SITE_CHARSET
|
||||
*/
|
||||
public static function fromUTF8($string)
|
||||
public function fromUTF8($string)
|
||||
{
|
||||
if (!defined('SITE_CHARSET')) {
|
||||
throw new \RuntimeException('SITE_CHARSET must be defined.');
|
||||
}
|
||||
|
||||
return static::convertCharset($string, 'utf-8', SITE_CHARSET);
|
||||
return $this->convertCharset($string, 'utf-8', SITE_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +82,7 @@ class Utils
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPersonCorporate(string $personTypeId): bool
|
||||
public function isPersonCorporate(string $personTypeId): bool
|
||||
{
|
||||
return ConfigProvider::getContragentTypeForPersonType($personTypeId) === Constants::CORPORATE_CONTRAGENT_TYPE;
|
||||
}
|
||||
|
@ -91,7 +90,7 @@ class Utils
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function createPlaceholderEmail(): string
|
||||
public function createPlaceholderEmail(): string
|
||||
{
|
||||
return uniqid('user_' . time(), false) . '@example.com';
|
||||
}
|
||||
|
@ -99,7 +98,7 @@ class Utils
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function createPlaceholderPassword(): string
|
||||
public function createPlaceholderPassword(): string
|
||||
{
|
||||
return uniqid("R", false);
|
||||
}
|
||||
|
@ -111,7 +110,7 @@ class Utils
|
|||
*
|
||||
* @return array|bool|\SplFixedArray|string
|
||||
*/
|
||||
protected static function convertCharset(string $string, string $inCharset, string $outCharset)
|
||||
protected function convertCharset(string $string, string $inCharset, string $outCharset)
|
||||
{
|
||||
$error = '';
|
||||
$result = Encoding::convertEncoding($string, $inCharset, $outCharset, $error);
|
|
@ -26,7 +26,7 @@ class CustomerBuilderTest extends TestCase
|
|||
/** @var \Intaro\RetailCrm\Component\CollectorCookieExtractor */
|
||||
private $originalCookieCollector;
|
||||
|
||||
protected function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
$this->originalCookieCollector = ServiceLocator::get(CollectorCookieExtractor::class);
|
||||
|
||||
|
@ -46,7 +46,7 @@ class CustomerBuilderTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
protected function tearDown()
|
||||
{
|
||||
ServiceLocator::set(CollectorCookieExtractor::class, $this->originalCookieCollector);
|
||||
}
|
||||
|
@ -113,7 +113,6 @@ class CustomerBuilderTest extends TestCase
|
|||
|
||||
$this->assertTrue($result instanceof Customer);
|
||||
$this->assertEquals('replaced', $result->externalId);
|
||||
$this->assertEquals(static::COOKIE_DATA, $result->browserId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue