1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

better structure + service locator, cookie extraction should be testable now

This commit is contained in:
Pavel 2020-07-30 16:27:44 +03:00
parent e51af8a5ed
commit 1eb88a6c8b
30 changed files with 223 additions and 74 deletions

View file

@ -44,7 +44,7 @@ class Logger
* @param string $logPath
* @param int $files
*/
private function __construct($logPath = '/bitrix/modules/intaro.retailcrm/log', $files = 3)
public function __construct($logPath = '/bitrix/modules/intaro.retailcrm/log', $files = 3)
{
$this->logPath = $logPath;
$this->files = $files;

View file

@ -1,5 +1,10 @@
<?php
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Component\CollectorCookieExtractor;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationReader;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationRegistry;
require_once __DIR__ . '/RetailcrmClasspathBuilder.php';
$retailcrmModuleId = 'intaro.retailcrm';
@ -16,4 +21,10 @@ $builder->setDisableNamespaces(true)
\Bitrix\Main\Loader::switchAutoLoad(true);
\Bitrix\Main\Loader::registerAutoLoadClasses('intaro.retailcrm', $builder->getResult());
\Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
AnnotationRegistry::registerLoader('class_exists');
ServiceLocator::registerServices([
Logger::class,
AnnotationReader::class,
CollectorCookieExtractor::class
]);

View file

@ -19,6 +19,7 @@ use Intaro\RetailCrm\Component\CollectorCookieExtractor;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Converter\DateTimeConverter;
use Intaro\RetailCrm\Component\Events;
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Model\Api\Address;
use Intaro\RetailCrm\Model\Api\Company;
use Intaro\RetailCrm\Model\Api\Contragent;
@ -47,6 +48,9 @@ class CorporateCustomerBuilder implements BuilderInterface
/** @var \Bitrix\Sale\Order $order */
private $order;
/** @var CollectorCookieExtractor */
private $cookieExtractor;
/** @var array */
private $sites;
@ -79,6 +83,7 @@ class CorporateCustomerBuilder implements BuilderInterface
*/
public function __construct()
{
$this->cookieExtractor = ServiceLocator::get(CollectorCookieExtractor::class);
$this->sites = ConfigProvider::getSitesList();
$this->legalDetails = ConfigProvider::getLegalDetails();
$this->contragentTypes = ConfigProvider::getContragentTypes();
@ -336,8 +341,8 @@ class CorporateCustomerBuilder implements BuilderInterface
*/
protected function buildDaemonCollectorId(): void
{
if (CollectorCookieExtractor::extractCookie()) {
$this->customer->browserId = CollectorCookieExtractor::extractCookie();
if ($this->cookieExtractor->extractCookie()) {
$this->customer->browserId = $this->cookieExtractor->extractCookie();
}
}
}

View file

@ -16,6 +16,7 @@ use Intaro\RetailCrm\Component\CollectorCookieExtractor;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Converter\DateTimeConverter;
use Intaro\RetailCrm\Component\Events;
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Model\Api\Address;
use Intaro\RetailCrm\Model\Api\Contragent;
use Intaro\RetailCrm\Model\Api\Customer;
@ -36,12 +37,23 @@ class CustomerBuilder implements BuilderInterface
/** @var \Intaro\RetailCrm\Model\Api\Customer $customer */
private $customer;
/** @var CollectorCookieExtractor */
private $cookieExtractor;
/** @var string $personTypeId */
private $personTypeId;
/** @var bool */
private $attachDaemonCollectorId = false;
/**
* CustomerBuilder constructor.
*/
public function __construct()
{
$this->cookieExtractor = ServiceLocator::get(CollectorCookieExtractor::class);
}
/**
* @inheritDoc
*/
@ -193,8 +205,8 @@ class CustomerBuilder implements BuilderInterface
*/
protected function buildDaemonCollectorId(): void
{
if (CollectorCookieExtractor::extractCookie()) {
$this->customer->browserId = CollectorCookieExtractor::extractCookie();
if ($this->cookieExtractor->extractCookie()) {
$this->customer->browserId = $this->cookieExtractor->extractCookie();
}
}

View file

@ -23,7 +23,7 @@ class CollectorCookieExtractor
*
* @return string|null
*/
public static function extractCookie(): ?string
public function extractCookie(): ?string
{
global $_COOKIE;

View file

@ -11,10 +11,10 @@
*/
namespace Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attributes;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attribute;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attributes;
/**
* Class Accessor

View file

@ -11,8 +11,8 @@
*/
namespace Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target;
/**
* Class PostDeserialize

View file

@ -11,8 +11,8 @@
*/
namespace Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target;
/**
* Class PostDeserialize

View file

@ -11,10 +11,10 @@
*/
namespace Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attributes;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attribute;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attributes;
/**
* Class SerializedName

View file

@ -11,10 +11,10 @@
*/
namespace Intaro\RetailCrm\Component\Json\Mapping;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attributes;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attribute;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attributes;
/**
* Class Type

View file

@ -11,7 +11,8 @@
*/
namespace Intaro\RetailCrm\Component\Json\Strategy;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader;
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationReader;
/**
* Trait AnnotationReaderTrait
@ -20,18 +21,11 @@ use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader;
*/
trait AnnotationReaderTrait
{
/** @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader */
private static $_annotationReader;
/**
* @return \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader
* @return \Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationReader
*/
private static function annotationReader(): AnnotationReader
private static function annotationReader()
{
if (empty(static::$_annotationReader)) {
static::$_annotationReader = new AnnotationReader();
}
return static::$_annotationReader;
return ServiceLocator::get(AnnotationReader::class);
}
}

View file

@ -11,7 +11,7 @@
*/
namespace Intaro\RetailCrm\Component\Json\Strategy\Serialize;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\AnnotationReader;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationReader;
use Intaro\RetailCrm\Component\Json\Mapping\Accessor;
use Intaro\RetailCrm\Component\Json\Mapping\SerializedName;
use Intaro\RetailCrm\Component\Json\Mapping\Type;

View file

@ -0,0 +1,99 @@
<?php
/**
* PHP version 7.1
*
* @category Integration
* @package Intaro\RetailCrm\Component
* @author retailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
namespace Intaro\RetailCrm\Component;
/**
* Class ServiceLocator
*
* @package Intaro\RetailCrm\Component
*/
class ServiceLocator
{
/**
* @var array<string, object>
*/
private static $services = [];
/**
* Register passed services
*
* @param array $services
*/
public static function registerServices(array $services = []): void
{
foreach ($services as $name => $service) {
static::registerService($name, $service);
}
}
/**
* Register passed service
*
* @param string $name
* @param mixed $service
*/
public static function registerService(string $name, $service): void
{
if (is_string($service)) {
if (class_exists($service)) {
if (is_numeric($name)) {
$name = $service;
}
static::set($name, new $service());
} else {
throw new \RuntimeException(
sprintf('Cannot find class "%s" for service "%s"', $service, $name)
);
}
} elseif (is_object($service)) {
static::set($name, $service);
} elseif (is_callable($service)) {
$instance = $service();
if (empty($instance)) {
throw new \RuntimeException(
sprintf('Cannot register service "%s": callable didn\'t return anything.', $name)
);
}
static::set($name, $instance);
} else {
throw new \RuntimeException(
sprintf('Cannot register service "%s": use class FQN, instance, or factory method.', $name)
);
}
}
/**
* Get service (returns null if service doesn't registered)
*
* @param string $name
*
* @return mixed
*/
public static function get(string $name)
{
return static::$services[$name] ?? null;
}
/**
* Sets service into ServiceContainer.
*
* @param string $name
* @param mixed $instance
*/
public static function set(string $name, $instance): void
{
static::$services[$name] = $instance;
}
}

View file

@ -17,7 +17,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
/**
* Annotations class.

View file

@ -18,7 +18,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
/**
* Annotation that can be used to signal to the parser

View file

@ -18,7 +18,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
/**
* Annotation that can be used to signal to the parser

View file

@ -18,7 +18,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
/**
* Annotation that can be used to signal to the parser

View file

@ -17,7 +17,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
/**
* Annotation that can be used to signal to the parser to ignore specific

View file

@ -18,7 +18,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
/**
* Annotation that can be used to signal to the parser

View file

@ -18,7 +18,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation;
/**
* Annotation that can be used to signal to the parser

View file

@ -17,7 +17,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
/**
* Description of AnnotationException

View file

@ -17,10 +17,10 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
@ -42,7 +42,7 @@ class AnnotationReader implements Reader
* @var array
*/
private static $globalImports = [
'ignoreannotation' => 'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\IgnoreAnnotation',
'ignoreannotation' => 'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\IgnoreAnnotation',
];
/**
@ -143,21 +143,21 @@ class AnnotationReader implements Reader
/**
* Annotations parser.
*
* @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\DocParser
* @var \Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\DocParser
*/
private $parser;
/**
* Annotations parser used to collect parsing metadata.
*
* @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\DocParser
* @var \Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\DocParser
*/
private $preParser;
/**
* PHP parser used to collect imports.
*
* @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\PhpParser
* @var \Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\PhpParser
*/
private $phpParser;

View file

@ -17,7 +17,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
final class AnnotationRegistry
{

View file

@ -17,9 +17,9 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
use Intaro\RetailCrm\Component\Doctrine\Common\Lexer\AbstractLexer;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Lexer\AbstractLexer;
/**
* Simple lexer for docblock annotations.

View file

@ -17,13 +17,13 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attribute;
use ReflectionClass;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Enum;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attributes;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Enum;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target;
use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attributes;
/**
* A parser for docblock annotations.
@ -54,7 +54,7 @@ final class DocParser
/**
* The lexer.
*
* @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\DocLexer
* @var \Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\DocLexer
*/
private $lexer;
@ -68,7 +68,7 @@ final class DocParser
/**
* Doc parser used to collect annotation target.
*
* @var \Intaro\RetailCrm\Component\Doctrine\Common\Annotations\DocParser
* @var \Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\DocParser
*/
private static $metadataParser;
@ -138,7 +138,7 @@ final class DocParser
* @var array
*/
private static $annotationMetadata = [
'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target' => [
'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target' => [
'is_annotation' => true,
'has_constructor' => true,
'properties' => [],
@ -154,7 +154,7 @@ final class DocParser
]
],
],
'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute' => [
'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attribute' => [
'is_annotation' => true,
'has_constructor' => false,
'targets_literal' => 'ANNOTATION_ANNOTATION',
@ -183,7 +183,7 @@ final class DocParser
]
],
],
'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attributes' => [
'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attributes' => [
'is_annotation' => true,
'has_constructor' => false,
'targets_literal' => 'ANNOTATION_CLASS',
@ -196,12 +196,12 @@ final class DocParser
'value' => [
'type' =>'array',
'required' =>true,
'array_type'=>'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute',
'value' =>'array<Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute>'
'array_type'=>'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attribute',
'value' =>'array<Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attribute>'
]
],
],
'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Enum' => [
'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Enum' => [
'is_annotation' => true,
'has_constructor' => true,
'targets_literal' => 'ANNOTATION_PROPERTY',
@ -484,10 +484,10 @@ final class DocParser
self::$metadataParser->setIgnoreNotImportedAnnotations(true);
self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames);
self::$metadataParser->setImports([
'enum' => 'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Enum',
'target' => 'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Target',
'attribute' => 'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attribute',
'attributes' => 'Intaro\RetailCrm\Component\Doctrine\Common\Annotations\Annotation\Attributes'
'enum' => 'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Enum',
'target' => 'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Target',
'attribute' => 'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attribute',
'attributes' => 'Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\Annotation\Attributes'
]);
// Make sure that annotations from metadata are loaded

View file

@ -17,7 +17,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
use SplFileObject;

View file

@ -17,7 +17,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
/**
* Interface for annotation readers.

View file

@ -17,7 +17,7 @@
* <http://www.doctrine-project.org>.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Annotations;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations;
/**
* Parses a file for namespaces/use/class declarations.

View file

@ -23,7 +23,7 @@ declare(strict_types=1);
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Intaro\RetailCrm\Component\Doctrine\Common\Lexer;
namespace Intaro\RetailCrm\Vendor\Doctrine\Common\Lexer;
use ReflectionClass;
use function implode;

View file

@ -6,10 +6,12 @@ use Bitrix\Main\Event;
use Bitrix\Main\EventManager;
use Bitrix\Main\Type\DateTime;
use Intaro\RetailCrm\Component\Builder\Api\CustomerBuilder;
use Intaro\RetailCrm\Component\CollectorCookieExtractor;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Component\Converter\DateTimeConverter;
use Intaro\RetailCrm\Component\Events;
use Intaro\RetailCrm\Component\ServiceLocator;
use Intaro\RetailCrm\Model\Api\Address;
use Intaro\RetailCrm\Model\Api\Customer;
use Intaro\RetailCrm\Model\Bitrix\User;
@ -19,13 +21,36 @@ use Tests\Intaro\RetailCrm\Helpers;
class CustomerBuilderTest extends TestCase
{
private const COOKIE_DATA = 'rcCookie';
/** @var \Intaro\RetailCrm\Component\CollectorCookieExtractor */
private $originalCookieCollector;
protected function setUp(): void
{
$this->originalCookieCollector = ServiceLocator::get(CollectorCookieExtractor::class);
$cookieExtractorMock = $this->getMockBuilder(CollectorCookieExtractor::class)
->setMethods(['extractCookie'])
->getMock();
$cookieExtractorMock
->method('extractCookie')
->withAnyParameters()
->willReturn(static::COOKIE_DATA);
ServiceLocator::set(CollectorCookieExtractor::class, $cookieExtractorMock);
Helpers::setConfigProperty('contragentTypes', [
'individual' => 'individual'
]);
}
protected function tearDown(): void
{
ServiceLocator::set(CollectorCookieExtractor::class, $this->originalCookieCollector);
}
/**
* @throws \Intaro\RetailCrm\Component\Builder\Exception\BuilderException
* @var User $entity
@ -57,6 +82,8 @@ class CustomerBuilderTest extends TestCase
$this->assertEquals($entity->getPersonalCity(), $result->address->city);
$this->assertEquals($entity->getPersonalStreet(), $result->address->text);
$this->assertEquals($entity->getPersonalZip(), $result->address->index);
$this->assertEquals(static::COOKIE_DATA, $result->browserId);
}
/**
@ -85,6 +112,7 @@ class CustomerBuilderTest extends TestCase
$this->assertTrue($result instanceof Customer);
$this->assertEquals('replaced', $result->externalId);
$this->assertEquals(static::COOKIE_DATA, $result->browserId);
}
/**