diff --git a/examples/exchange1c.php b/examples/exchange1c.php index 28c741e..9d4c8dd 100644 --- a/examples/exchange1c.php +++ b/examples/exchange1c.php @@ -1,57 +1,56 @@ - '1c_exchange', - 'login' => 'admin', - 'password' => 'admin', - 'use_zip' => false, - 'file_part' => 0, - 'models' => [ - \Bigperson\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class, - \Bigperson\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class, - \Bigperson\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class, - ], -]; -$config = new \Bigperson\Exchange1C\Config($configValues); -$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); -$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); -$modelBuilder = new \Bigperson\Exchange1C\ModelBuilder(); -$loaderService = new \Bigperson\Exchange1C\Services\FileLoaderService($request, $config); -$authService = new \Bigperson\Exchange1C\Services\AuthService($request, $config); -$categoryService = new \Bigperson\Exchange1C\Services\CategoryService($request, $config, $dispatcher, $modelBuilder); -$offerService = new \Bigperson\Exchange1C\Services\OfferService($request, $config, $dispatcher, $modelBuilder); -$catalogService = new \Bigperson\Exchange1C\Services\CatalogService($request, $config, $authService, $loaderService, $categoryService, $offerService); - - -$mode = $request->get('mode'); -$type = $request->get('type'); - -try { - if ($type == 'catalog') { - if (!method_exists($catalogService, $mode)) { - throw new Exception('not correct request, mode=' . $mode); - } - $body = $catalogService->$mode(); - $response = new \Symfony\Component\HttpFoundation\Response($body, 200, ['Content-Type', 'text/plain']); - $response->send(); - } else { - throw new \LogicException(sprintf('Logic for method %s not released', $type)); - } -} catch (\Exception $e) { - $body = "failure\n"; - $body .= $e->getMessage() . "\n"; - $body .= $e->getFile() . "\n"; - $body .= $e->getLine() . "\n"; - - $response = new \Symfony\Component\HttpFoundation\Response($body, 500, ['Content-Type', 'text/plain']); - $response->send(); -} + '1c_exchange', + 'login' => 'admin', + 'password' => 'admin', + 'use_zip' => false, + 'file_part' => 0, + 'models' => [ + \Bigperson\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class, + \Bigperson\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class, + \Bigperson\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class, + ], +]; +$config = new \Bigperson\Exchange1C\Config($configValues); +$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); +$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); +$modelBuilder = new \Bigperson\Exchange1C\ModelBuilder(); +$loaderService = new \Bigperson\Exchange1C\Services\FileLoaderService($request, $config); +$authService = new \Bigperson\Exchange1C\Services\AuthService($request, $config); +$categoryService = new \Bigperson\Exchange1C\Services\CategoryService($request, $config, $dispatcher, $modelBuilder); +$offerService = new \Bigperson\Exchange1C\Services\OfferService($request, $config, $dispatcher, $modelBuilder); +$catalogService = new \Bigperson\Exchange1C\Services\CatalogService($request, $config, $authService, $loaderService, $categoryService, $offerService); + +$mode = $request->get('mode'); +$type = $request->get('type'); + +try { + if ($type == 'catalog') { + if (!method_exists($catalogService, $mode)) { + throw new Exception('not correct request, mode='.$mode); + } + $body = $catalogService->$mode(); + $response = new \Symfony\Component\HttpFoundation\Response($body, 200, ['Content-Type', 'text/plain']); + $response->send(); + } else { + throw new \LogicException(sprintf('Logic for method %s not released', $type)); + } +} catch (\Exception $e) { + $body = "failure\n"; + $body .= $e->getMessage()."\n"; + $body .= $e->getFile()."\n"; + $body .= $e->getLine()."\n"; + + $response = new \Symfony\Component\HttpFoundation\Response($body, 500, ['Content-Type', 'text/plain']); + $response->send(); +} diff --git a/src/Config.php b/src/Config.php index b5da2a3..5fdd316 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1,158 +1,163 @@ - null, - \Bigperson\Exchange1C\Interfaces\ProductInterface::class => null, - \Bigperson\Exchange1C\Interfaces\OfferInterface::class => null, - ]; - - /** - * Config constructor. - * @param array $config - */ - public function __construct(array $config = []) - { - $this->configure($config); - } - - /** - * Overrides default configuration settings - * - * @param array $config - */ - private function configure(array $config = []): void - { - foreach ($config as $param => $value) { - $property = $this->toCamelCase($param); - if (property_exists(self::class, $property)) { - $this->$property = $value; - } - } - } - - /** - * @return string - */ - public function getImportDir(): string - { - return $this->importDir; - } - - /** - * @return string - */ - public function getLogin(): string - { - return $this->login; - } - - /** - * @return string - */ - public function getPassword(): string - { - return $this->password; - } - - /** - * @return bool - */ - public function isUseZip(): bool - { - return $this->useZip; - } - - /** - * @return int - */ - public function getFilePart(): int - { - return $this->filePart; - } - - /** - * @return array - */ - public function getModels(): array - { - return $this->models; - } - - /** - * @param string $modelName - * @return null|string - */ - public function getModelClass(string $modelName): ?string - { - if (isset($this->models[$modelName])) { - return $this->models[$modelName]; - } - - return null; - } - - /** - * @param string $filename - * @return string - */ - public function getFullPath(string $filename): string - { - return $this->getImportDir().DIRECTORY_SEPARATOR.$filename; - } - - /** - * Translates a string with underscores into camel case (e.g. first_name -> firstName) - * @param string $str String in underscore format - * @return string $str translated into camel caps - */ - private function toCamelCase($str): string - { - $func = function ($c) { - return strtoupper($c[1]); - }; - - return preg_replace_callback('/_([a-z])/', $func, $str); - } -} + null, + \Bigperson\Exchange1C\Interfaces\ProductInterface::class => null, + \Bigperson\Exchange1C\Interfaces\OfferInterface::class => null, + ]; + + /** + * Config constructor. + * + * @param array $config + */ + public function __construct(array $config = []) + { + $this->configure($config); + } + + /** + * Overrides default configuration settings. + * + * @param array $config + */ + private function configure(array $config = []): void + { + foreach ($config as $param => $value) { + $property = $this->toCamelCase($param); + if (property_exists(self::class, $property)) { + $this->$property = $value; + } + } + } + + /** + * @return string + */ + public function getImportDir(): string + { + return $this->importDir; + } + + /** + * @return string + */ + public function getLogin(): string + { + return $this->login; + } + + /** + * @return string + */ + public function getPassword(): string + { + return $this->password; + } + + /** + * @return bool + */ + public function isUseZip(): bool + { + return $this->useZip; + } + + /** + * @return int + */ + public function getFilePart(): int + { + return $this->filePart; + } + + /** + * @return array + */ + public function getModels(): array + { + return $this->models; + } + + /** + * @param string $modelName + * + * @return null|string + */ + public function getModelClass(string $modelName): ?string + { + if (isset($this->models[$modelName])) { + return $this->models[$modelName]; + } + + return null; + } + + /** + * @param string $filename + * + * @return string + */ + public function getFullPath(string $filename): string + { + return $this->getImportDir().DIRECTORY_SEPARATOR.$filename; + } + + /** + * Translates a string with underscores into camel case (e.g. first_name -> firstName). + * + * @param string $str String in underscore format + * + * @return string $str translated into camel caps + */ + private function toCamelCase($str): string + { + $func = function ($c) { + return strtoupper($c[1]); + }; + + return preg_replace_callback('/_([a-z])/', $func, $str); + } +} diff --git a/src/Events/AfterOffersSync.php b/src/Events/AfterOffersSync.php index 2a6dc28..ad6d190 100644 --- a/src/Events/AfterOffersSync.php +++ b/src/Events/AfterOffersSync.php @@ -22,6 +22,7 @@ class AfterOffersSync extends Event /** * AfterOffersSync constructor. + * * @param array $ids */ public function __construct(array $ids = []) diff --git a/src/Events/AfterProductsSync.php b/src/Events/AfterProductsSync.php index 5db0c8b..72c22c7 100644 --- a/src/Events/AfterProductsSync.php +++ b/src/Events/AfterProductsSync.php @@ -22,6 +22,7 @@ class AfterProductsSync extends Event /** * AfterProductsSync constructor. + * * @param array $ids */ public function __construct(array $ids = []) diff --git a/src/Events/AfterUpdateOffer.php b/src/Events/AfterUpdateOffer.php index f06bf23..69e3dad 100644 --- a/src/Events/AfterUpdateOffer.php +++ b/src/Events/AfterUpdateOffer.php @@ -29,8 +29,9 @@ class AfterUpdateOffer extends Event /** * AfterUpdateOffer constructor. + * * @param OfferInterface $model - * @param Offer $offer + * @param Offer $offer */ public function __construct(OfferInterface $model, Offer $offer) { diff --git a/src/Events/AfterUpdateProduct.php b/src/Events/AfterUpdateProduct.php index 503656a..a041589 100644 --- a/src/Events/AfterUpdateProduct.php +++ b/src/Events/AfterUpdateProduct.php @@ -23,6 +23,7 @@ class AfterUpdateProduct extends Event /** * BeforeUpdateProduct constructor. + * * @param ProductInterface $product */ public function __construct(ProductInterface $product) diff --git a/src/Events/BeforeUpdateOffer.php b/src/Events/BeforeUpdateOffer.php index af247e8..d42ce4a 100644 --- a/src/Events/BeforeUpdateOffer.php +++ b/src/Events/BeforeUpdateOffer.php @@ -29,8 +29,9 @@ class BeforeUpdateOffer extends Event /** * BeforeUpdateOffer constructor. + * * @param OfferInterface $model - * @param Offer $offer + * @param Offer $offer */ public function __construct(OfferInterface $model, Offer $offer) { diff --git a/src/Events/BeforeUpdateProduct.php b/src/Events/BeforeUpdateProduct.php index 7df9e1d..40ccfa0 100644 --- a/src/Events/BeforeUpdateProduct.php +++ b/src/Events/BeforeUpdateProduct.php @@ -9,8 +9,8 @@ namespace Bigperson\Exchange1C\Events; -use Symfony\Component\EventDispatcher\Event; use Bigperson\Exchange1C\Interfaces\ProductInterface; +use Symfony\Component\EventDispatcher\Event; class BeforeUpdateProduct extends Event { @@ -23,6 +23,7 @@ class BeforeUpdateProduct extends Event /** * BeforeUpdateProduct constructor. + * * @param ProductInterface $product */ public function __construct(ProductInterface $product) diff --git a/src/Exceptions/Exchange1CException.php b/src/Exceptions/Exchange1CException.php index cf4079f..419ae42 100644 --- a/src/Exceptions/Exchange1CException.php +++ b/src/Exceptions/Exchange1CException.php @@ -1,18 +1,17 @@ - Классификатор > Группы) * $groups[0]->parent - родительская группа - * $groups[0]->children - дочерние группы + * $groups[0]->children - дочерние группы. * * @param \Zenwalker\CommerceML\Model\Group[] $groups + * * @return void */ public static function createTree1c($groups); diff --git a/src/Interfaces/IdentifierInterface.php b/src/Interfaces/IdentifierInterface.php index 46bbc85..631c7eb 100644 --- a/src/Interfaces/IdentifierInterface.php +++ b/src/Interfaces/IdentifierInterface.php @@ -9,7 +9,6 @@ namespace Bigperson\Exchange1C\Interfaces; - interface IdentifierInterface { /** @@ -20,7 +19,7 @@ interface IdentifierInterface public static function getIdFieldName1c(); /** - * Возвращаем id сущности + * Возвращаем id сущности. * * @return int|string */ diff --git a/src/Interfaces/ModelBuilderInterface.php b/src/Interfaces/ModelBuilderInterface.php index 9614bbf..ad46e9d 100644 --- a/src/Interfaces/ModelBuilderInterface.php +++ b/src/Interfaces/ModelBuilderInterface.php @@ -1,27 +1,28 @@ - ПакетПредложений > Предложения > Предложение > Цены + * offers.xml > ПакетПредложений > Предложения > Предложение > Цены. * * Цена товара, * К $price можно обратиться как к массиву, чтобы получить список цен (Цены > Цена) * $price->type - тип цены (offers.xml > ПакетПредложений > ТипыЦен > ТипЦены) * * @param \Zenwalker\CommerceML\Model\Price $price + * * @return void */ public function setPrice1c($price); /** * @param $types + * * @return void */ public static function createPriceTypes1c($types); /** - * offers.xml > ПакетПредложений > Предложения > Предложение > ХарактеристикиТовара > ХарактеристикаТовара + * offers.xml > ПакетПредложений > Предложения > Предложение > ХарактеристикиТовара > ХарактеристикаТовара. * * Характеристики товара * $name - Наименование * $value - Значение * * @param \Zenwalker\CommerceML\Model\Simple $specification + * * @return void */ public function setSpecification1c($specification); diff --git a/src/Interfaces/PartnerInterface.php b/src/Interfaces/PartnerInterface.php index 6befc97..e30f661 100644 --- a/src/Interfaces/PartnerInterface.php +++ b/src/Interfaces/PartnerInterface.php @@ -9,7 +9,6 @@ namespace Bigperson\Exchange1C\Interfaces; - interface PartnerInterface extends ExportFieldsInterface { } diff --git a/src/Interfaces/ProductInterface.php b/src/Interfaces/ProductInterface.php index 4bea7c9..acbd036 100644 --- a/src/Interfaces/ProductInterface.php +++ b/src/Interfaces/ProductInterface.php @@ -12,14 +12,13 @@ use Zenwalker\CommerceML\Model\PropertyCollection; /** - * Interface ProductInterface - * - * @package carono\exchange1c\interfaces + * Interface ProductInterface. */ interface ProductInterface extends IdentifierInterface { /** - * Получение уникального идентификатора продукта в рамках БД сайта + * Получение уникального идентификатора продукта в рамках БД сайта. + * * @return int|string */ public function getPrimaryKey(); @@ -27,10 +26,11 @@ public function getPrimaryKey(); /** * Если по каким то причинам файлы import.xml или offers.xml были модифицированы и какие то данные * не попадают в парсер, в самом конце вызывается данный метод, в $product и $cml можно получить все - * возможные данные для ручного парсинга + * возможные данные для ручного парсинга. * - * @param \Zenwalker\CommerceML\CommerceML $cml + * @param \Zenwalker\CommerceML\CommerceML $cml * @param \Zenwalker\CommerceML\Model\Product $product + * * @return void */ public function setRaw1cData($cml, $product); @@ -38,25 +38,27 @@ public function setRaw1cData($cml, $product); /** * Установка реквизитов, (import.xml > Каталог > Товары > Товар > ЗначенияРеквизитов > ЗначениеРеквизита) * $name - Наименование - * $value - Значение + * $value - Значение. * * @param string $name * @param string $value + * * @return void */ public function setRequisite1c($name, $value); /** - * Предпологается, что дерево групп у Вас уже создано (\carono\exchange1c\interfaces\GroupInterface::createTree1c) + * Предпологается, что дерево групп у Вас уже создано (\carono\exchange1c\interfaces\GroupInterface::createTree1c). * * @param \Zenwalker\CommerceML\Model\Group $group + * * @return mixed */ public function setGroup1c($group); /** * import.xml > Классификатор > Свойства > Свойство - * $property - Свойство товара + * $property - Свойство товара. * * import.xml > Классификатор > Свойства > Свойство > Значение * $property->value - Разыменованное значение (string) @@ -65,6 +67,7 @@ public function setGroup1c($group); * $property->getValueModel() - Данные по значению, Ид значения, и т.д * * @param \Zenwalker\CommerceML\Model\Property $property + * * @return void */ public function setProperty1c($property); @@ -72,6 +75,7 @@ public function setProperty1c($property); /** * @param string $path * @param string $caption + * * @return void */ public function addImage1c($path, $caption); @@ -83,31 +87,35 @@ public function getGroup1c(); /** * Создание всех свойств продутка - * import.xml > Классификатор > Свойства + * import.xml > Классификатор > Свойства. * * $properties[]->availableValues - список доступных значений, для этого свойства * import.xml > Классификатор > Свойства > Свойство > ВариантыЗначений > Справочник * * @param PropertyCollection $properties + * * @return mixed */ public static function createProperties1c($properties); /** * @param \Zenwalker\CommerceML\Model\Offer $offer + * * @return OfferInterface */ public function getOffer1c($offer); /** * @param \Zenwalker\CommerceML\Model\Product $product + * * @return self */ public static function createModel1c($product); /** * @param string $id + * * @return ProductInterface|null */ - public static function findProductBy1c(string $id): ?ProductInterface; + public static function findProductBy1c(string $id): ?self; } diff --git a/src/Interfaces/RawInterface.php b/src/Interfaces/RawInterface.php index 20c4f8a..85089e4 100644 --- a/src/Interfaces/RawInterface.php +++ b/src/Interfaces/RawInterface.php @@ -9,12 +9,12 @@ namespace Bigperson\Exchange1C\Interfaces; - interface RawInterface { /** - * @param \Zenwalker\CommerceML\CommerceML $cml + * @param \Zenwalker\CommerceML\CommerceML $cml * @param \Zenwalker\CommerceML\Model\Simple $object + * * @return mixed */ public function setRaw1cData($cml, $object); diff --git a/src/Interfaces/WarehouseInterface.php b/src/Interfaces/WarehouseInterface.php index f188e41..e1559ab 100644 --- a/src/Interfaces/WarehouseInterface.php +++ b/src/Interfaces/WarehouseInterface.php @@ -11,5 +11,4 @@ interface WarehouseInterface extends IdentifierInterface { - } diff --git a/src/ModelBuilder.php b/src/ModelBuilder.php index 628f130..0ea4deb 100644 --- a/src/ModelBuilder.php +++ b/src/ModelBuilder.php @@ -1,40 +1,42 @@ -getModelClass($interface); - if ($model) { - $modelInstance = new $model; - if($modelInstance instanceof $interface) { - return $modelInstance; - } - } - - throw new Exchange1CException(sprintf('Model %s not instantiable interface %s', $config->getModelClass($interface), $interface)); - } -} +getModelClass($interface); + if ($model) { + $modelInstance = new $model(); + if ($modelInstance instanceof $interface) { + return $modelInstance; + } + } + + throw new Exchange1CException(sprintf('Model %s not instantiable interface %s', $config->getModelClass($interface), $interface)); + } +} diff --git a/src/Services/AbstractService.php b/src/Services/AbstractService.php index 8c345e3..35a54e8 100644 --- a/src/Services/AbstractService.php +++ b/src/Services/AbstractService.php @@ -1,76 +1,75 @@ -request = $request; - $this->config = $config; - $this->authService = $authService; - $this->loaderService = $loaderService; - $this->categoryService = $categoryService; - $this->offerService = $offerService; - } -} +request = $request; + $this->config = $config; + $this->authService = $authService; + $this->loaderService = $loaderService; + $this->categoryService = $categoryService; + $this->offerService = $offerService; + } +} diff --git a/src/Services/AuthService.php b/src/Services/AuthService.php index 09ed288..d4e6d39 100644 --- a/src/Services/AuthService.php +++ b/src/Services/AuthService.php @@ -1,105 +1,105 @@ -request = $request; - $this->setSession(); - $this->config = $config; - } - - /** - * @return string - * @throws Exchange1CException - */ - public function checkAuth() - { - if ( - $this->request->server->get('PHP_AUTH_USER') === $this->config->getLogin() && - $this->request->server->get('PHP_AUTH_PW') === $this->config->getPassword() - ) { - $this->session->save(); - $response = "success\n"; - $response .= "laravel_session\n"; - $response .= $this->session->getId() . "\n"; - $response .= "timestamp=" . time(); - if ($this->session instanceof SessionInterface) { - $this->session->set(self::SESSION_KEY . '_auth', $this->config->getLogin()); - } elseif ($this->session instanceof Session) { - $this->session->put(self::SESSION_KEY . '_auth', $this->config->getLogin()); - } else { - throw new Exchange1CException(sprintf('Session is not insatiable interface %s or %s', SessionInterface::class, Session::class)); - } - } else { - $response = "failure\n"; - } - - return $response; - } - - - /** - * @throws Exchange1CException - */ - public function auth(): void - { - $login = $this->config->getLogin(); - $user = $this->session->get(self::SESSION_KEY . '_auth', null); - - if (!$user || $user != $login) { - throw new Exchange1CException('auth error'); - } - } - - private function setSession(): void - { - if (!$this->request->getSession()) { - $session = new \Symfony\Component\HttpFoundation\Session\Session(); - $session->start(); - $this->request->setSession($session); - } - - $this->session = $this->request->getSession(); - } -} +request = $request; + $this->setSession(); + $this->config = $config; + } + + /** + * @throws Exchange1CException + * + * @return string + */ + public function checkAuth() + { + if ( + $this->request->server->get('PHP_AUTH_USER') === $this->config->getLogin() && + $this->request->server->get('PHP_AUTH_PW') === $this->config->getPassword() + ) { + $this->session->save(); + $response = "success\n"; + $response .= "laravel_session\n"; + $response .= $this->session->getId()."\n"; + $response .= 'timestamp='.time(); + if ($this->session instanceof SessionInterface) { + $this->session->set(self::SESSION_KEY.'_auth', $this->config->getLogin()); + } elseif ($this->session instanceof Session) { + $this->session->put(self::SESSION_KEY.'_auth', $this->config->getLogin()); + } else { + throw new Exchange1CException(sprintf('Session is not insatiable interface %s or %s', SessionInterface::class, Session::class)); + } + } else { + $response = "failure\n"; + } + + return $response; + } + + /** + * @throws Exchange1CException + */ + public function auth(): void + { + $login = $this->config->getLogin(); + $user = $this->session->get(self::SESSION_KEY.'_auth', null); + + if (!$user || $user != $login) { + throw new Exchange1CException('auth error'); + } + } + + private function setSession(): void + { + if (!$this->request->getSession()) { + $session = new \Symfony\Component\HttpFoundation\Session\Session(); + $session->start(); + $this->request->setSession($session); + } + + $this->session = $this->request->getSession(); + } +} diff --git a/src/Services/CatalogService.php b/src/Services/CatalogService.php index ff030fb..8337b3a 100644 --- a/src/Services/CatalogService.php +++ b/src/Services/CatalogService.php @@ -13,7 +13,7 @@ * Class Catalog * Class for implementing CommerceML protocol * http://v8.1c.ru/edi/edi_stnd/90/92.htm - * http://v8.1c.ru/edi/edi_stnd/131/ + * http://v8.1c.ru/edi/edi_stnd/131/. */ class CatalogService extends AbstractService { @@ -26,6 +26,7 @@ class CatalogService extends AbstractService * - имя Cookie; * - значение Cookie. * Примечание. Все последующие запросы к системе управления сайтом со стороны "1С:Предприятия" содержат в заголовке запроса имя и значение Cookie. + * * @return string */ public function checkauth(): string @@ -43,21 +44,23 @@ public function checkauth(): string * или zip=no - в этом случае на следующем шаге файлы не упаковываются и передаются каждый по отдельности. * 2. file_limit=<число>, где <число> - максимально допустимый размер файла в байтах для передачи за один запрос. * Если системе "1С:Предприятие" понадобится передать файл большего размера, его следует разделить на фрагменты. + * * @return string */ public function init(): string { $this->authService->auth(); $this->loaderService->clearImportDirectory(); - $zipEnable = function_exists("zip_open") && $this->config->isUseZip(); - $response = "zip=" . ($zipEnable ? "yes" : "no") . "\n"; - $response .= "file_limit=" . $this->config->getFilePart(); + $zipEnable = function_exists('zip_open') && $this->config->isUseZip(); + $response = 'zip='.($zipEnable ? 'yes' : 'no')."\n"; + $response .= 'file_limit='.$this->config->getFilePart(); return $response; } /** * Загрузка и сохранение файлов на сервер + * * @return string */ public function file(): string @@ -79,6 +82,7 @@ public function file(): string * сайтом будет содержаться слово "failure", а в следующих строках - описание ошибки, произошедшей в процессе * обработки запроса. * Если произошла необрабатываемая ошибка уровня ядра продукта или sql-запроса, то будет возвращен html-код. + * * @return string */ public function import(): string @@ -100,8 +104,8 @@ public function import(): string $response = "success\n"; $response .= "laravel_session\n"; - $response .= $this->request->getSession()->getId() . "\n"; - $response .= "timestamp=" . time(); + $response .= $this->request->getSession()->getId()."\n"; + $response .= 'timestamp='.time(); return $response; } diff --git a/src/Services/CategoryService.php b/src/Services/CategoryService.php index 7a76686..46823f1 100644 --- a/src/Services/CategoryService.php +++ b/src/Services/CategoryService.php @@ -1,218 +1,219 @@ -request = $request; - $this->config = $config; - $this->dispatcher = $dispatcher; - $this->modelBuilder = $modelBuilder; - } - - /** - * Базовый метод запуска импорта - * @throws Exchange1CException - */ - public function import(): void - { - $filename = basename($this->request->get('filename')); - $commerce = new CommerceML(); - $commerce->loadImportXml($this->config->getFullPath($filename)); - $classifierFile = $this->config->getFullPath('classifier.xml'); - if ($commerce->classifier->xml) { - $commerce->classifier->xml->saveXML($classifierFile); - } else { - $commerce->classifier->xml = simplexml_load_string(file_get_contents($classifierFile)); - } - $this->beforeProductsSync(); - - if ($groupClass = $this->getGroupClass()) { - $groupClass::createTree1c($commerce->classifier->getGroups()); - } - - $productClass = $this->getProductClass(); - $productClass::createProperties1c($commerce->classifier->getProperties()); - foreach ($commerce->catalog->getProducts() as $product) { - if (!$model = $productClass::createModel1c($product)) { - throw new Exchange1CException("Модель продукта не найдена, проверьте реализацию $productClass::createModel1c"); - } - $this->parseProduct($model, $product); - $this->_ids[] = $model->getPrimaryKey(); - $model = null; - unset($model, $product); - gc_collect_cycles(); - } - $this->afterProductsSync(); - } - - /** - * @return GroupInterface|null - */ - protected function getGroupClass(): ?GroupInterface - { - return $this->modelBuilder->getInterfaceClass($this->config, GroupInterface::class); - } - - /** - * @return ProductInterface|null - */ - protected function getProductClass(): ?ProductInterface - { - return $this->modelBuilder->getInterfaceClass($this->config, ProductInterface::class); - } - - /** - * @param ProductInterface $model - * @param \Zenwalker\CommerceML\Model\Product $product - */ - protected function parseProduct(ProductInterface $model, Product $product): void - { - $this->beforeUpdateProduct($model); - $model->setRaw1cData($product->owner, $product); - $this->parseGroups($model, $product); - $this->parseProperties($model, $product); - $this->parseRequisites($model, $product); - $this->parseImage($model, $product); - $this->afterUpdateProduct($model); - - unset($group); - } - - /** - * @param ProductInterface $model - * @param Product $product - */ - protected function parseGroups(ProductInterface $model, Product $product): void - { - $group = $product->getGroup(); - $model->setGroup1c($group); - } - - /** - * @param ProductInterface $model - * @param Product $product - */ - protected function parseProperties(ProductInterface $model, Product $product): void - { - foreach ($product->getProperties() as $property) { - $model->setProperty1c($property); - } - } - - /** - * @param ProductInterface $model - * @param Product $product - */ - protected function parseRequisites(ProductInterface $model, Product $product): void - { - $requisites = $product->getRequisites(); - foreach ($requisites as $requisite) { - $model->setRequisite1c($requisite->name, $requisite->value); - } - } - - /** - * @param ProductInterface $model - * @param Product $product - */ - protected function parseImage(ProductInterface $model, Product $product) - { - $images = $product->getImages(); - foreach ($images as $image) { - $path = $this->config->getFullPath(basename($image->path)); - if (file_exists($path)) { - $model->addImage1c($path, $image->caption); - } - } - } - - protected function beforeProductsSync(): void - { - $event = new BeforeProductsSync(); - $this->dispatcher->dispatch($event::NAME, $event); - } - - protected function afterProductsSync(): void - { - $event = new AfterProductsSync($this->_ids); - $this->dispatcher->dispatch($event::NAME, $event); - } - - /** - * @param ProductInterface $model - */ - protected function beforeUpdateProduct(ProductInterface $model): void - { - $event = new BeforeUpdateProduct($model); - $this->dispatcher->dispatch($event::NAME, $event); - } - - /** - * @param ProductInterface $model - */ - protected function afterUpdateProduct(ProductInterface $model): void - { - $event = new AfterUpdateProduct($model); - $this->dispatcher->dispatch($event::NAME, $event); - } -} +request = $request; + $this->config = $config; + $this->dispatcher = $dispatcher; + $this->modelBuilder = $modelBuilder; + } + + /** + * Базовый метод запуска импорта. + * + * @throws Exchange1CException + */ + public function import(): void + { + $filename = basename($this->request->get('filename')); + $commerce = new CommerceML(); + $commerce->loadImportXml($this->config->getFullPath($filename)); + $classifierFile = $this->config->getFullPath('classifier.xml'); + if ($commerce->classifier->xml) { + $commerce->classifier->xml->saveXML($classifierFile); + } else { + $commerce->classifier->xml = simplexml_load_string(file_get_contents($classifierFile)); + } + $this->beforeProductsSync(); + + if ($groupClass = $this->getGroupClass()) { + $groupClass::createTree1c($commerce->classifier->getGroups()); + } + + $productClass = $this->getProductClass(); + $productClass::createProperties1c($commerce->classifier->getProperties()); + foreach ($commerce->catalog->getProducts() as $product) { + if (!$model = $productClass::createModel1c($product)) { + throw new Exchange1CException("Модель продукта не найдена, проверьте реализацию $productClass::createModel1c"); + } + $this->parseProduct($model, $product); + $this->_ids[] = $model->getPrimaryKey(); + $model = null; + unset($model, $product); + gc_collect_cycles(); + } + $this->afterProductsSync(); + } + + /** + * @return GroupInterface|null + */ + protected function getGroupClass(): ?GroupInterface + { + return $this->modelBuilder->getInterfaceClass($this->config, GroupInterface::class); + } + + /** + * @return ProductInterface|null + */ + protected function getProductClass(): ?ProductInterface + { + return $this->modelBuilder->getInterfaceClass($this->config, ProductInterface::class); + } + + /** + * @param ProductInterface $model + * @param \Zenwalker\CommerceML\Model\Product $product + */ + protected function parseProduct(ProductInterface $model, Product $product): void + { + $this->beforeUpdateProduct($model); + $model->setRaw1cData($product->owner, $product); + $this->parseGroups($model, $product); + $this->parseProperties($model, $product); + $this->parseRequisites($model, $product); + $this->parseImage($model, $product); + $this->afterUpdateProduct($model); + + unset($group); + } + + /** + * @param ProductInterface $model + * @param Product $product + */ + protected function parseGroups(ProductInterface $model, Product $product): void + { + $group = $product->getGroup(); + $model->setGroup1c($group); + } + + /** + * @param ProductInterface $model + * @param Product $product + */ + protected function parseProperties(ProductInterface $model, Product $product): void + { + foreach ($product->getProperties() as $property) { + $model->setProperty1c($property); + } + } + + /** + * @param ProductInterface $model + * @param Product $product + */ + protected function parseRequisites(ProductInterface $model, Product $product): void + { + $requisites = $product->getRequisites(); + foreach ($requisites as $requisite) { + $model->setRequisite1c($requisite->name, $requisite->value); + } + } + + /** + * @param ProductInterface $model + * @param Product $product + */ + protected function parseImage(ProductInterface $model, Product $product) + { + $images = $product->getImages(); + foreach ($images as $image) { + $path = $this->config->getFullPath(basename($image->path)); + if (file_exists($path)) { + $model->addImage1c($path, $image->caption); + } + } + } + + protected function beforeProductsSync(): void + { + $event = new BeforeProductsSync(); + $this->dispatcher->dispatch($event::NAME, $event); + } + + protected function afterProductsSync(): void + { + $event = new AfterProductsSync($this->_ids); + $this->dispatcher->dispatch($event::NAME, $event); + } + + /** + * @param ProductInterface $model + */ + protected function beforeUpdateProduct(ProductInterface $model): void + { + $event = new BeforeUpdateProduct($model); + $this->dispatcher->dispatch($event::NAME, $event); + } + + /** + * @param ProductInterface $model + */ + protected function afterUpdateProduct(ProductInterface $model): void + { + $event = new AfterUpdateProduct($model); + $this->dispatcher->dispatch($event::NAME, $event); + } +} diff --git a/src/Services/FileLoaderService.php b/src/Services/FileLoaderService.php index 472cf75..0b2266c 100644 --- a/src/Services/FileLoaderService.php +++ b/src/Services/FileLoaderService.php @@ -1,81 +1,82 @@ -request = $request; - $this->config = $config; - } - - /** - * @return string - */ - public function load(): string - { - $filename = basename($this->request->get('filename')); - $filePath = $this->config->getFullPath($filename); - if ($filename === "orders.xml") { - throw new \LogicException('This method is not released'); - } else { - $directory = dirname($filePath); - if (!is_dir($directory)) { - mkdir($directory, 0755, true); - } - $f = fopen($filePath, 'w+'); - fwrite($f, file_get_contents('php://input')); - fclose($f); - if ($this->config->isUseZip()) { - $zip = new \ZipArchive; - $zip->open($filePath); - $zip->extractTo($this->config->getImportDir()); - $zip->close(); - unlink($filePath); - } - - return "success\n"; - } - } - - /** - * Delete all files from tmp directory - */ - public function clearImportDirectory(): void - { - $tmp_files = glob($this->config->getImportDir() .DIRECTORY_SEPARATOR. '*.*'); - if (is_array($tmp_files)) { - foreach ($tmp_files as $v) { - unlink($v); - } - } - } -} +request = $request; + $this->config = $config; + } + + /** + * @return string + */ + public function load(): string + { + $filename = basename($this->request->get('filename')); + $filePath = $this->config->getFullPath($filename); + if ($filename === 'orders.xml') { + throw new \LogicException('This method is not released'); + } else { + $directory = dirname($filePath); + if (!is_dir($directory)) { + mkdir($directory, 0755, true); + } + $f = fopen($filePath, 'w+'); + fwrite($f, file_get_contents('php://input')); + fclose($f); + if ($this->config->isUseZip()) { + $zip = new \ZipArchive(); + $zip->open($filePath); + $zip->extractTo($this->config->getImportDir()); + $zip->close(); + unlink($filePath); + } + + return "success\n"; + } + } + + /** + * Delete all files from tmp directory. + */ + public function clearImportDirectory(): void + { + $tmp_files = glob($this->config->getImportDir().DIRECTORY_SEPARATOR.'*.*'); + if (is_array($tmp_files)) { + foreach ($tmp_files as $v) { + unlink($v); + } + } + } +} diff --git a/src/Services/OfferService.php b/src/Services/OfferService.php index 3556c7b..d8128c7 100644 --- a/src/Services/OfferService.php +++ b/src/Services/OfferService.php @@ -1,183 +1,183 @@ -request = $request; - $this->config = $config; - $this->dispatcher = $dispatcher; - $this->modelBuilder = $modelBuilder; - } - - /** - * @throws Exchange1CException - */ - public function import() - { - $filename = basename($this->request->get('filename')); - $this->_ids = []; - $commerce = new CommerceML(); - $commerce->loadOffersXml($this->config->getFullPath($filename)); - if ($offerClass = $this->getOfferClass()) { - $offerClass::createPriceTypes1c($commerce->offerPackage->getPriceTypes()); - } - $this->beforeOfferSync(); - foreach ($commerce->offerPackage->getOffers() as $offer) { - $productId = $offer->getClearId(); - if ($product = $this->findProductModelById($productId)) { - $model = $product->getOffer1c($offer); - $this->parseProductOffer($model, $offer); - $this->_ids[] = $model->getPrimaryKey(); - } else { - throw new Exchange1CException("Продукт $productId не найден в базе"); - } - unset($model); - } - $this->afterOfferSync(); - } - - /** - * @return OfferInterface|null - */ - private function getOfferClass(): ?OfferInterface - { - return $this->modelBuilder->getInterfaceClass($this->config, OfferInterface::class); - } - - /** - * @param string $id - * - * @return ProductInterface|null - */ - protected function findProductModelById(string $id): ?ProductInterface - { - /** - * @var $class ProductInterface - */ - $class = $this->modelBuilder->getInterfaceClass($this->config, ProductInterface::class); - - return $class::findProductBy1c($id); - } - - /** - * @param OfferInterface $model - * @param Offer $offer - */ - protected function parseProductOffer(OfferInterface $model, Offer $offer): void - { - $this->beforeUpdateOffer($model, $offer); - $this->parseSpecifications($model, $offer); - $this->parsePrice($model, $offer); - $this->afterUpdateOffer($model, $offer); - } - - /** - * @param OfferInterface $model - * @param Offer $offer - */ - protected function parseSpecifications(OfferInterface $model, Offer $offer) - { - foreach ($offer->getSpecifications() as $specification) { - $model->setSpecification1c($specification); - } - } - - /** - * @param OfferInterface $model - * @param Offer $offer - */ - protected function parsePrice(OfferInterface $model, Offer $offer) - { - foreach ($offer->getPrices() as $price) { - $model->setPrice1c($price); - } - } - - public function beforeOfferSync(): void - { - $event = new BeforeOffersSync(); - $this->dispatcher->dispatch($event::NAME, $event); - } - - public function afterOfferSync(): void - { - $event = new AfterOffersSync($this->_ids); - $this->dispatcher->dispatch($event::NAME, $event); - } - - /** - * @param OfferInterface $model - * @param Offer $offer - */ - public function beforeUpdateOffer(OfferInterface $model, Offer $offer) - { - $event = new BeforeUpdateOffer($model, $offer); - $this->dispatcher->dispatch($event::NAME, $event); - } - - /** - * @param OfferInterface $model - * @param Offer $offer - */ - public function afterUpdateOffer(OfferInterface $model, Offer $offer) - { - $event = new AfterUpdateOffer($model, $offer); - $this->dispatcher->dispatch($event::NAME, $event); - } -} +request = $request; + $this->config = $config; + $this->dispatcher = $dispatcher; + $this->modelBuilder = $modelBuilder; + } + + /** + * @throws Exchange1CException + */ + public function import() + { + $filename = basename($this->request->get('filename')); + $this->_ids = []; + $commerce = new CommerceML(); + $commerce->loadOffersXml($this->config->getFullPath($filename)); + if ($offerClass = $this->getOfferClass()) { + $offerClass::createPriceTypes1c($commerce->offerPackage->getPriceTypes()); + } + $this->beforeOfferSync(); + foreach ($commerce->offerPackage->getOffers() as $offer) { + $productId = $offer->getClearId(); + if ($product = $this->findProductModelById($productId)) { + $model = $product->getOffer1c($offer); + $this->parseProductOffer($model, $offer); + $this->_ids[] = $model->getPrimaryKey(); + } else { + throw new Exchange1CException("Продукт $productId не найден в базе"); + } + unset($model); + } + $this->afterOfferSync(); + } + + /** + * @return OfferInterface|null + */ + private function getOfferClass(): ?OfferInterface + { + return $this->modelBuilder->getInterfaceClass($this->config, OfferInterface::class); + } + + /** + * @param string $id + * + * @return ProductInterface|null + */ + protected function findProductModelById(string $id): ?ProductInterface + { + /** + * @var ProductInterface + */ + $class = $this->modelBuilder->getInterfaceClass($this->config, ProductInterface::class); + + return $class::findProductBy1c($id); + } + + /** + * @param OfferInterface $model + * @param Offer $offer + */ + protected function parseProductOffer(OfferInterface $model, Offer $offer): void + { + $this->beforeUpdateOffer($model, $offer); + $this->parseSpecifications($model, $offer); + $this->parsePrice($model, $offer); + $this->afterUpdateOffer($model, $offer); + } + + /** + * @param OfferInterface $model + * @param Offer $offer + */ + protected function parseSpecifications(OfferInterface $model, Offer $offer) + { + foreach ($offer->getSpecifications() as $specification) { + $model->setSpecification1c($specification); + } + } + + /** + * @param OfferInterface $model + * @param Offer $offer + */ + protected function parsePrice(OfferInterface $model, Offer $offer) + { + foreach ($offer->getPrices() as $price) { + $model->setPrice1c($price); + } + } + + public function beforeOfferSync(): void + { + $event = new BeforeOffersSync(); + $this->dispatcher->dispatch($event::NAME, $event); + } + + public function afterOfferSync(): void + { + $event = new AfterOffersSync($this->_ids); + $this->dispatcher->dispatch($event::NAME, $event); + } + + /** + * @param OfferInterface $model + * @param Offer $offer + */ + public function beforeUpdateOffer(OfferInterface $model, Offer $offer) + { + $event = new BeforeUpdateOffer($model, $offer); + $this->dispatcher->dispatch($event::NAME, $event); + } + + /** + * @param OfferInterface $model + * @param Offer $offer + */ + public function afterUpdateOffer(OfferInterface $model, Offer $offer) + { + $event = new AfterUpdateOffer($model, $offer); + $this->dispatcher->dispatch($event::NAME, $event); + } +} diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index c904ca4..4227255 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -1,48 +1,47 @@ - '1c_exchange', - 'login' => 'logintest', - 'password' => 'passwordtest', - 'use_zip' => true, - 'file_part' => 500, - 'models' => [ - GroupInterface::class => 'CategoryTestClass', - ProductInterface::class => 'ProductTestClass', - OfferInterface::class => 'OfferTestClass', - ], - ]; - $config = new Config($values); - - $this->assertEquals($values['import_dir'], $config->getImportDir()); - $this->assertEquals($values['login'], $config->getLogin()); - $this->assertEquals($values['password'], $config->getPassword()); - $this->assertEquals($values['use_zip'], $config->isUseZip()); - $this->assertEquals($values['file_part'], $config->getFilePart()); - $this->assertEquals($values['models'][GroupInterface::class], $config->getModelClass(GroupInterface::class)); - $this->assertEquals($values['models'][ProductInterface::class], $config->getModelClass(ProductInterface::class)); - $this->assertEquals($values['models'][OfferInterface::class], $config->getModelClass(OfferInterface::class)); - $this->assertEquals($values['models'], $config->getModels()); - $this->assertNull($config->getModelClass(self::class)); - $this->assertEquals($values['import_dir'].DIRECTORY_SEPARATOR.'test.xml', $config->getFullPath('test.xml')); - } -} + '1c_exchange', + 'login' => 'logintest', + 'password' => 'passwordtest', + 'use_zip' => true, + 'file_part' => 500, + 'models' => [ + GroupInterface::class => 'CategoryTestClass', + ProductInterface::class => 'ProductTestClass', + OfferInterface::class => 'OfferTestClass', + ], + ]; + $config = new Config($values); + + $this->assertEquals($values['import_dir'], $config->getImportDir()); + $this->assertEquals($values['login'], $config->getLogin()); + $this->assertEquals($values['password'], $config->getPassword()); + $this->assertEquals($values['use_zip'], $config->isUseZip()); + $this->assertEquals($values['file_part'], $config->getFilePart()); + $this->assertEquals($values['models'][GroupInterface::class], $config->getModelClass(GroupInterface::class)); + $this->assertEquals($values['models'][ProductInterface::class], $config->getModelClass(ProductInterface::class)); + $this->assertEquals($values['models'][OfferInterface::class], $config->getModelClass(OfferInterface::class)); + $this->assertEquals($values['models'], $config->getModels()); + $this->assertNull($config->getModelClass(self::class)); + $this->assertEquals($values['import_dir'].DIRECTORY_SEPARATOR.'test.xml', $config->getFullPath('test.xml')); + } +} diff --git a/tests/ModelBuilderTest.php b/tests/ModelBuilderTest.php index f0c2590..ba7cf53 100644 --- a/tests/ModelBuilderTest.php +++ b/tests/ModelBuilderTest.php @@ -1,48 +1,47 @@ - [ - GroupInterface::class => GroupTestModel::class, - ], - ]; - $config = new Config($values); - $builder = new ModelBuilder(); - $model = $builder->getInterfaceClass($config, GroupInterface::class); - $this->assertTrue($model instanceof GroupInterface); - $this->assertTrue($model instanceof GroupTestModel); - } - - public function testGetInterfaceClassException(): void - { - $this->expectException(Exchange1CException::class); - $values = [ - 'models' => [ - GroupInterface::class => ProductTestModel::class, - ], - ]; - $config = new Config($values); - $builder = new ModelBuilder(); - $builder->getInterfaceClass($config, GroupInterface::class); - } -} + [ + GroupInterface::class => GroupTestModel::class, + ], + ]; + $config = new Config($values); + $builder = new ModelBuilder(); + $model = $builder->getInterfaceClass($config, GroupInterface::class); + $this->assertTrue($model instanceof GroupInterface); + $this->assertTrue($model instanceof GroupTestModel); + } + + public function testGetInterfaceClassException(): void + { + $this->expectException(Exchange1CException::class); + $values = [ + 'models' => [ + GroupInterface::class => ProductTestModel::class, + ], + ]; + $config = new Config($values); + $builder = new ModelBuilder(); + $builder->getInterfaceClass($config, GroupInterface::class); + } +} diff --git a/tests/Models/GroupTestModel.php b/tests/Models/GroupTestModel.php index 58a78ec..4d2c782 100644 --- a/tests/Models/GroupTestModel.php +++ b/tests/Models/GroupTestModel.php @@ -1,53 +1,53 @@ - Классификатор > Группы) - * $groups[0]->parent - родительская группа - * $groups[0]->children - дочерние группы - * - * @param \Zenwalker\CommerceML\Model\Group[] $groups - * @return void - */ - public static function createTree1c($groups) - { - // TODO: Implement createTree1c() method. - } - - /** - * Возвращаем имя поля в базе данных, в котором хранится ID из 1с - * - * @return string - */ - public static function getIdFieldName1c() - { - // TODO: Implement getIdFieldName1c() method. - } - - /** - * Возвращаем id сущности - * - * @return int|string - */ - public function getPrimaryKey() - { - // TODO: Implement getPrimaryKey() method. - } -} + Классификатор > Группы) + * $groups[0]->parent - родительская группа + * $groups[0]->children - дочерние группы. + * + * @param \Zenwalker\CommerceML\Model\Group[] $groups + * + * @return void + */ + public static function createTree1c($groups) + { + // TODO: Implement createTree1c() method. + } + + /** + * Возвращаем имя поля в базе данных, в котором хранится ID из 1с + * + * @return string + */ + public static function getIdFieldName1c() + { + // TODO: Implement getIdFieldName1c() method. + } + + /** + * Возвращаем id сущности. + * + * @return int|string + */ + public function getPrimaryKey() + { + // TODO: Implement getPrimaryKey() method. + } +} diff --git a/tests/Models/OfferTestModel.php b/tests/Models/OfferTestModel.php index dddadb5..e92f97e 100644 --- a/tests/Models/OfferTestModel.php +++ b/tests/Models/OfferTestModel.php @@ -1,95 +1,99 @@ - ПакетПредложений > Предложения > Предложение > Цены - * - * Цена товара, - * К $price можно обратиться как к массиву, чтобы получить список цен (Цены > Цена) - * $price->type - тип цены (offers.xml > ПакетПредложений > ТипыЦен > ТипЦены) - * - * @param \Zenwalker\CommerceML\Model\Price $price - * @return void - */ - public function setPrice1c($price) - { - // TODO: Implement setPrice1c() method. - } - - /** - * @param $types - * @return void - */ - public static function createPriceTypes1c($types) - { - // TODO: Implement createPriceTypes1c() method. - } - - /** - * offers.xml > ПакетПредложений > Предложения > Предложение > ХарактеристикиТовара > ХарактеристикаТовара - * - * Характеристики товара - * $name - Наименование - * $value - Значение - * - * @param \Zenwalker\CommerceML\Model\Simple $specification - * @return void - */ - public function setSpecification1c($specification) - { - // TODO: Implement setSpecification1c() method. - } -} + ПакетПредложений > Предложения > Предложение > Цены. + * + * Цена товара, + * К $price можно обратиться как к массиву, чтобы получить список цен (Цены > Цена) + * $price->type - тип цены (offers.xml > ПакетПредложений > ТипыЦен > ТипЦены) + * + * @param \Zenwalker\CommerceML\Model\Price $price + * + * @return void + */ + public function setPrice1c($price) + { + // TODO: Implement setPrice1c() method. + } + + /** + * @param $types + * + * @return void + */ + public static function createPriceTypes1c($types) + { + // TODO: Implement createPriceTypes1c() method. + } + + /** + * offers.xml > ПакетПредложений > Предложения > Предложение > ХарактеристикиТовара > ХарактеристикаТовара. + * + * Характеристики товара + * $name - Наименование + * $value - Значение + * + * @param \Zenwalker\CommerceML\Model\Simple $specification + * + * @return void + */ + public function setSpecification1c($specification) + { + // TODO: Implement setSpecification1c() method. + } +} diff --git a/tests/Models/ProductTestModel.php b/tests/Models/ProductTestModel.php index 33856da..73abab5 100644 --- a/tests/Models/ProductTestModel.php +++ b/tests/Models/ProductTestModel.php @@ -1,157 +1,167 @@ - Каталог > Товары > Товар > ЗначенияРеквизитов > ЗначениеРеквизита) - * $name - Наименование - * $value - Значение - * - * @param string $name - * @param string $value - * @return void - */ - public function setRequisite1c($name, $value) - { - // TODO: Implement setRequisite1c() method. - } - - /** - * Предпологается, что дерево групп у Вас уже создано (\carono\exchange1c\interfaces\GroupInterface::createTree1c) - * - * @param \Zenwalker\CommerceML\Model\Group $group - * @return mixed - */ - public function setGroup1c($group) - { - // TODO: Implement setGroup1c() method. - } - - /** - * import.xml > Классификатор > Свойства > Свойство - * $property - Свойство товара - * - * import.xml > Классификатор > Свойства > Свойство > Значение - * $property->value - Разыменованное значение (string) - * - * import.xml > Классификатор > Свойства > Свойство > ВариантыЗначений > Справочник - * $property->getValueModel() - Данные по значению, Ид значения, и т.д - * - * @param \Zenwalker\CommerceML\Model\Property $property - * @return void - */ - public function setProperty1c($property) - { - // TODO: Implement setProperty1c() method. - } - - /** - * @param string $path - * @param string $caption - * @return void - */ - public function addImage1c($path, $caption) - { - // TODO: Implement addImage1c() method. - } - - /** - * @return GroupInterface - */ - public function getGroup1c() - { - // TODO: Implement getGroup1c() method. - } - - /** - * Создание всех свойств продутка - * import.xml > Классификатор > Свойства - * - * $properties[]->availableValues - список доступных значений, для этого свойства - * import.xml > Классификатор > Свойства > Свойство > ВариантыЗначений > Справочник - * - * @param PropertyCollection $properties - * @return mixed - */ - public static function createProperties1c($properties) - { - // TODO: Implement createProperties1c() method. - } - - /** - * @param \Zenwalker\CommerceML\Model\Offer $offer - * @return OfferInterface - */ - public function getOffer1c($offer) - { - return new OfferTestModel(); - } - - /** - * @param \Zenwalker\CommerceML\Model\Product $product - * @return self - */ - public static function createModel1c($product) - { - return new self(); - } - - /** - * @param string $id - * @return ProductInterface|null - */ - public static function findProductBy1c(string $id): ?ProductInterface - { - return new self(); - } -} + Каталог > Товары > Товар > ЗначенияРеквизитов > ЗначениеРеквизита) + * $name - Наименование + * $value - Значение. + * + * @param string $name + * @param string $value + * + * @return void + */ + public function setRequisite1c($name, $value) + { + // TODO: Implement setRequisite1c() method. + } + + /** + * Предпологается, что дерево групп у Вас уже создано (\carono\exchange1c\interfaces\GroupInterface::createTree1c). + * + * @param \Zenwalker\CommerceML\Model\Group $group + * + * @return mixed + */ + public function setGroup1c($group) + { + // TODO: Implement setGroup1c() method. + } + + /** + * import.xml > Классификатор > Свойства > Свойство + * $property - Свойство товара. + * + * import.xml > Классификатор > Свойства > Свойство > Значение + * $property->value - Разыменованное значение (string) + * + * import.xml > Классификатор > Свойства > Свойство > ВариантыЗначений > Справочник + * $property->getValueModel() - Данные по значению, Ид значения, и т.д + * + * @param \Zenwalker\CommerceML\Model\Property $property + * + * @return void + */ + public function setProperty1c($property) + { + // TODO: Implement setProperty1c() method. + } + + /** + * @param string $path + * @param string $caption + * + * @return void + */ + public function addImage1c($path, $caption) + { + // TODO: Implement addImage1c() method. + } + + /** + * @return GroupInterface + */ + public function getGroup1c() + { + // TODO: Implement getGroup1c() method. + } + + /** + * Создание всех свойств продутка + * import.xml > Классификатор > Свойства. + * + * $properties[]->availableValues - список доступных значений, для этого свойства + * import.xml > Классификатор > Свойства > Свойство > ВариантыЗначений > Справочник + * + * @param PropertyCollection $properties + * + * @return mixed + */ + public static function createProperties1c($properties) + { + // TODO: Implement createProperties1c() method. + } + + /** + * @param \Zenwalker\CommerceML\Model\Offer $offer + * + * @return OfferInterface + */ + public function getOffer1c($offer) + { + return new OfferTestModel(); + } + + /** + * @param \Zenwalker\CommerceML\Model\Product $product + * + * @return self + */ + public static function createModel1c($product) + { + return new self(); + } + + /** + * @param string $id + * + * @return ProductInterface|null + */ + public static function findProductBy1c(string $id): ?ProductInterface + { + return new self(); + } +} diff --git a/tests/Services/AuthServiceTest.php b/tests/Services/AuthServiceTest.php index c755389..f183bae 100644 --- a/tests/Services/AuthServiceTest.php +++ b/tests/Services/AuthServiceTest.php @@ -1,128 +1,128 @@ - 'logintest', - 'password' => 'passwordtest' - ]; - $config = new Config($values); - $request = $this->createMock(Request::class); - $request->server = $this->createMock(ServerBag::class); - $request->server - ->expects($this->exactly(2)) - ->method('get') - ->withConsecutive(['PHP_AUTH_USER'], ['PHP_AUTH_PW']) - ->willReturnOnConsecutiveCalls('logintest', 'passwordtest'); - $session = $this->createMock(SessionInterface::class); - $request->method('getSession') - ->willReturn($session); - - $authService = new AuthService($request, $config); - $response = $authService->checkAuth(); - $this->assertTrue(strpos($response, 'success') === 0); - } - - public function testCheckAuthIlluminate(): void - { - $values = [ - 'login' => 'logintest', - 'password' => 'passwordtest' - ]; - $config = new Config($values); - $request = $this->createMock(Request::class); - $request->server = $this->createMock(ServerBag::class); - $request->server - ->expects($this->exactly(2)) - ->method('get') - ->withConsecutive(['PHP_AUTH_USER'], ['PHP_AUTH_PW']) - ->willReturnOnConsecutiveCalls('logintest', 'passwordtest'); - $session = $this->createMock(Session::class); - $request->method('getSession') - ->willReturn($session); - - $authService = new AuthService($request, $config); - $response = $authService->checkAuth(); - $this->assertTrue(strpos($response, 'success') === 0); - } - - public function testCheckAuthFail(): void - { - $values = [ - 'login' => 'logintest', - 'password' => 'passwordtest' - ]; - $config = new Config($values); - $request = $this->createMock(Request::class); - $request->server = $this->createMock(ServerBag::class); - $request->server - ->expects($this->exactly(2)) - ->method('get') - ->withConsecutive(['PHP_AUTH_USER'], ['PHP_AUTH_PW']) - ->willReturnOnConsecutiveCalls('logintest', 'falledpassword'); - $session = $this->createMock(SessionInterface::class); - $request->method('getSession') - ->willReturn($session); - - $authService = new AuthService($request, $config); - $response = $authService->checkAuth(); - $this->assertTrue(strpos($response, 'failure') === 0); - } - - public function testAuth(): void - { - $values = [ - 'login' => 'logintest', - 'password' => 'passwordtest' - ]; - $config = new Config($values); - $request = $this->createMock(Request::class); - $session = $this->createMock(SessionInterface::class); - $session->method('get') - ->willReturn('logintest'); - $request->method('getSession') - ->willReturn($session); - - $authService = new AuthService($request, $config); - $this->assertNull($authService->auth()); - } - - public function testAuthException(): void - { - $this->expectException(Exchange1CException::class); - $values = [ - 'login' => 'logintest', - 'password' => 'passwordtest' - ]; - $config = new Config($values); - $request = $this->createMock(Request::class); - $session = $this->createMock(SessionInterface::class); - $session->method('get') - ->willReturn(null); - $request->method('getSession') - ->willReturn($session); - - $authService = new AuthService($request, $config); - $authService->auth(); - } -} + 'logintest', + 'password' => 'passwordtest', + ]; + $config = new Config($values); + $request = $this->createMock(Request::class); + $request->server = $this->createMock(ServerBag::class); + $request->server + ->expects($this->exactly(2)) + ->method('get') + ->withConsecutive(['PHP_AUTH_USER'], ['PHP_AUTH_PW']) + ->willReturnOnConsecutiveCalls('logintest', 'passwordtest'); + $session = $this->createMock(SessionInterface::class); + $request->method('getSession') + ->willReturn($session); + + $authService = new AuthService($request, $config); + $response = $authService->checkAuth(); + $this->assertTrue(strpos($response, 'success') === 0); + } + + public function testCheckAuthIlluminate(): void + { + $values = [ + 'login' => 'logintest', + 'password' => 'passwordtest', + ]; + $config = new Config($values); + $request = $this->createMock(Request::class); + $request->server = $this->createMock(ServerBag::class); + $request->server + ->expects($this->exactly(2)) + ->method('get') + ->withConsecutive(['PHP_AUTH_USER'], ['PHP_AUTH_PW']) + ->willReturnOnConsecutiveCalls('logintest', 'passwordtest'); + $session = $this->createMock(Session::class); + $request->method('getSession') + ->willReturn($session); + + $authService = new AuthService($request, $config); + $response = $authService->checkAuth(); + $this->assertTrue(strpos($response, 'success') === 0); + } + + public function testCheckAuthFail(): void + { + $values = [ + 'login' => 'logintest', + 'password' => 'passwordtest', + ]; + $config = new Config($values); + $request = $this->createMock(Request::class); + $request->server = $this->createMock(ServerBag::class); + $request->server + ->expects($this->exactly(2)) + ->method('get') + ->withConsecutive(['PHP_AUTH_USER'], ['PHP_AUTH_PW']) + ->willReturnOnConsecutiveCalls('logintest', 'falledpassword'); + $session = $this->createMock(SessionInterface::class); + $request->method('getSession') + ->willReturn($session); + + $authService = new AuthService($request, $config); + $response = $authService->checkAuth(); + $this->assertTrue(strpos($response, 'failure') === 0); + } + + public function testAuth(): void + { + $values = [ + 'login' => 'logintest', + 'password' => 'passwordtest', + ]; + $config = new Config($values); + $request = $this->createMock(Request::class); + $session = $this->createMock(SessionInterface::class); + $session->method('get') + ->willReturn('logintest'); + $request->method('getSession') + ->willReturn($session); + + $authService = new AuthService($request, $config); + $this->assertNull($authService->auth()); + } + + public function testAuthException(): void + { + $this->expectException(Exchange1CException::class); + $values = [ + 'login' => 'logintest', + 'password' => 'passwordtest', + ]; + $config = new Config($values); + $request = $this->createMock(Request::class); + $session = $this->createMock(SessionInterface::class); + $session->method('get') + ->willReturn(null); + $request->method('getSession') + ->willReturn($session); + + $authService = new AuthService($request, $config); + $authService->auth(); + } +} diff --git a/tests/Services/CatalogServiceTest.php b/tests/Services/CatalogServiceTest.php index 541ab5b..df79d46 100644 --- a/tests/Services/CatalogServiceTest.php +++ b/tests/Services/CatalogServiceTest.php @@ -1,116 +1,116 @@ -createMock(Config::class); - $request = $this->createMock(Request::class); - $loader = $this->createMock(FileLoaderService::class); - $auth = $this->createMock(AuthService::class); - $auth->method('checkAuth') - ->willReturn('success'); - $category = $this->createMock(CategoryService::class); - $offer = $this->createMock(OfferService::class); - $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); - - $this->assertEquals('success', $service->checkauth()); - } - - public function testInit(): void - { - $config = $this->createMock(Config::class); - $request = $this->createMock(Request::class); - $loader = $this->createMock(FileLoaderService::class); - $auth = $this->createMock(AuthService::class); - $auth->method('auth'); - $category = $this->createMock(CategoryService::class); - $offer = $this->createMock(OfferService::class); - $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); - - $this->assertTrue(is_string($service->init())); - } - - public function testFile(): void - { - $config = $this->createMock(Config::class); - $request = $this->createMock(Request::class); - $loader = $this->createMock(FileLoaderService::class); - $auth = $this->createMock(AuthService::class); - $auth->method('auth'); - $category = $this->createMock(CategoryService::class); - $offer = $this->createMock(OfferService::class); - $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); - $loader->method('load') - ->willReturn('success'); - - $this->assertEquals('success', $service->file()); - } - - public function testImportImport(): void - { - $config = $this->createMock(Config::class); - $request = $this->createMock(Request::class); - $request->method('get') - ->with('filename') - ->willReturn('import.xml'); - $session = $this->createMock(SessionInterface::class); - $session->method('getId') - ->willReturn('1231243'); - $request->method('getSession') - ->willReturn($session); - $loader = $this->createMock(FileLoaderService::class); - $auth = $this->createMock(AuthService::class); - $auth->method('auth'); - $category = $this->createMock(CategoryService::class); - $category->method('import') - ->willReturn('success'); - $offer = $this->createMock(OfferService::class); - $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); - - $this->assertTrue(is_string($service->import())); - } - - public function testImportOffers(): void - { - $config = $this->createMock(Config::class); - $request = $this->createMock(Request::class); - $request->method('get') - ->with('filename') - ->willReturn('offers.xml'); - $session = $this->createMock(SessionInterface::class); - $session->method('getId') - ->willReturn('1231243'); - $request->method('getSession') - ->willReturn($session); - $loader = $this->createMock(FileLoaderService::class); - $auth = $this->createMock(AuthService::class); - $auth->method('auth'); - $category = $this->createMock(CategoryService::class); - $offer = $this->createMock(OfferService::class); - $offer->method('import') - ->willReturn('success'); - $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); - - $this->assertTrue(is_string($service->import())); - } -} +createMock(Config::class); + $request = $this->createMock(Request::class); + $loader = $this->createMock(FileLoaderService::class); + $auth = $this->createMock(AuthService::class); + $auth->method('checkAuth') + ->willReturn('success'); + $category = $this->createMock(CategoryService::class); + $offer = $this->createMock(OfferService::class); + $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); + + $this->assertEquals('success', $service->checkauth()); + } + + public function testInit(): void + { + $config = $this->createMock(Config::class); + $request = $this->createMock(Request::class); + $loader = $this->createMock(FileLoaderService::class); + $auth = $this->createMock(AuthService::class); + $auth->method('auth'); + $category = $this->createMock(CategoryService::class); + $offer = $this->createMock(OfferService::class); + $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); + + $this->assertTrue(is_string($service->init())); + } + + public function testFile(): void + { + $config = $this->createMock(Config::class); + $request = $this->createMock(Request::class); + $loader = $this->createMock(FileLoaderService::class); + $auth = $this->createMock(AuthService::class); + $auth->method('auth'); + $category = $this->createMock(CategoryService::class); + $offer = $this->createMock(OfferService::class); + $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); + $loader->method('load') + ->willReturn('success'); + + $this->assertEquals('success', $service->file()); + } + + public function testImportImport(): void + { + $config = $this->createMock(Config::class); + $request = $this->createMock(Request::class); + $request->method('get') + ->with('filename') + ->willReturn('import.xml'); + $session = $this->createMock(SessionInterface::class); + $session->method('getId') + ->willReturn('1231243'); + $request->method('getSession') + ->willReturn($session); + $loader = $this->createMock(FileLoaderService::class); + $auth = $this->createMock(AuthService::class); + $auth->method('auth'); + $category = $this->createMock(CategoryService::class); + $category->method('import') + ->willReturn('success'); + $offer = $this->createMock(OfferService::class); + $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); + + $this->assertTrue(is_string($service->import())); + } + + public function testImportOffers(): void + { + $config = $this->createMock(Config::class); + $request = $this->createMock(Request::class); + $request->method('get') + ->with('filename') + ->willReturn('offers.xml'); + $session = $this->createMock(SessionInterface::class); + $session->method('getId') + ->willReturn('1231243'); + $request->method('getSession') + ->willReturn($session); + $loader = $this->createMock(FileLoaderService::class); + $auth = $this->createMock(AuthService::class); + $auth->method('auth'); + $category = $this->createMock(CategoryService::class); + $offer = $this->createMock(OfferService::class); + $offer->method('import') + ->willReturn('success'); + $service = new CatalogService($request, $config, $auth, $loader, $category, $offer); + + $this->assertTrue(is_string($service->import())); + } +} diff --git a/tests/Services/CategoryServiceTest.php b/tests/Services/CategoryServiceTest.php index af9f1f9..d24aebb 100644 --- a/tests/Services/CategoryServiceTest.php +++ b/tests/Services/CategoryServiceTest.php @@ -1,43 +1,43 @@ - __DIR__.'/../xml', - 'models' => [ - \Bigperson\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class, - \Bigperson\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class, - \Bigperson\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class, - ], - ]; - - $config = new Config($configValues); - $request = $this->createMock(Request::class); - $dispatcher = $this->createMock(EventDispatcherInterface::class); - $builder = new ModelBuilder(); - $request->method('get') - ->with('filename') - ->willReturn('import.xml'); - - $service = new CategoryService($request, $config, $dispatcher, $builder); - $this->assertNull($service->import()); - } -} + __DIR__.'/../xml', + 'models' => [ + \Bigperson\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class, + \Bigperson\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class, + \Bigperson\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class, + ], + ]; + + $config = new Config($configValues); + $request = $this->createMock(Request::class); + $dispatcher = $this->createMock(EventDispatcherInterface::class); + $builder = new ModelBuilder(); + $request->method('get') + ->with('filename') + ->willReturn('import.xml'); + + $service = new CategoryService($request, $config, $dispatcher, $builder); + $this->assertNull($service->import()); + } +} diff --git a/tests/Services/FileLoaderServiceTest.php b/tests/Services/FileLoaderServiceTest.php index 9e47197..0a41608 100644 --- a/tests/Services/FileLoaderServiceTest.php +++ b/tests/Services/FileLoaderServiceTest.php @@ -1,99 +1,100 @@ - __DIR__ . DIRECTORY_SEPARATOR . '1c_exchangetest', - ]; - $config = new Config($configValues); - - $request = new Request(); - $request->query->set('filename', 'test.xml'); - $fileLoader = new FileLoaderService($request, $config); - if (is_dir($config->getImportDir())) { - $this->recurseRmdir($config->getImportDir()); - } - - $fileLoader->load(); - $this->assertTrue(file_exists($config->getFullPath('test.xml'))); - $this->recurseRmdir($config->getImportDir()); - } - - public function testLoadZip(): void - { - $configValues = [ - 'import_dir' => __DIR__ . DIRECTORY_SEPARATOR . '1c_exchangetest', - 'use_zip' => true, - ]; - $config = new Config($configValues); - - $request = new Request(); - $request->query->set('filename', 'test.zip'); - $fileLoader = new FileLoaderService($request, $config); - if (is_dir($config->getImportDir())) { - $this->recurseRmdir($config->getImportDir()); - } - - $fileLoader->load(); - $this->assertFalse(file_exists($config->getFullPath('test.zip'))); - $this->recurseRmdir($config->getImportDir()); - } - - public function testClearImportDirectory(): void - { - $configValues = [ - 'import_dir' => __DIR__ . DIRECTORY_SEPARATOR . '1c_exchangetest', - ]; - $config = new Config($configValues); - $request = new Request(); - $request->query->set('filename', 'test.xml'); - $fileLoader = new FileLoaderService($request, $config); - $fileLoader->load(); - $fileLoader->clearImportDirectory(); - $this->assertFalse(file_exists($config->getFullPath('test.xml'))); - $this->recurseRmdir($config->getImportDir()); - } - - public function testException(): void - { - $configValues = []; - $config = new Config($configValues); - $this->expectException(\LogicException::class); - - $request = new Request(); - $request->query->set('filename', 'orders.xml'); - $fileLoader = new FileLoaderService($request, $config); - $fileLoader->load(); - } - - /** - * @param $dir - * @return bool - */ - private function recurseRmdir($dir): bool - { - $files = array_diff(scandir($dir), array('.', '..')); - - foreach ($files as $file) { - (is_dir("$dir/$file")) ? $this->recurseRmdir("$dir/$file") : unlink("$dir/$file"); - } - - return rmdir($dir); - } -} + __DIR__.DIRECTORY_SEPARATOR.'1c_exchangetest', + ]; + $config = new Config($configValues); + + $request = new Request(); + $request->query->set('filename', 'test.xml'); + $fileLoader = new FileLoaderService($request, $config); + if (is_dir($config->getImportDir())) { + $this->recurseRmdir($config->getImportDir()); + } + + $fileLoader->load(); + $this->assertTrue(file_exists($config->getFullPath('test.xml'))); + $this->recurseRmdir($config->getImportDir()); + } + + public function testLoadZip(): void + { + $configValues = [ + 'import_dir' => __DIR__.DIRECTORY_SEPARATOR.'1c_exchangetest', + 'use_zip' => true, + ]; + $config = new Config($configValues); + + $request = new Request(); + $request->query->set('filename', 'test.zip'); + $fileLoader = new FileLoaderService($request, $config); + if (is_dir($config->getImportDir())) { + $this->recurseRmdir($config->getImportDir()); + } + + $fileLoader->load(); + $this->assertFalse(file_exists($config->getFullPath('test.zip'))); + $this->recurseRmdir($config->getImportDir()); + } + + public function testClearImportDirectory(): void + { + $configValues = [ + 'import_dir' => __DIR__.DIRECTORY_SEPARATOR.'1c_exchangetest', + ]; + $config = new Config($configValues); + $request = new Request(); + $request->query->set('filename', 'test.xml'); + $fileLoader = new FileLoaderService($request, $config); + $fileLoader->load(); + $fileLoader->clearImportDirectory(); + $this->assertFalse(file_exists($config->getFullPath('test.xml'))); + $this->recurseRmdir($config->getImportDir()); + } + + public function testException(): void + { + $configValues = []; + $config = new Config($configValues); + $this->expectException(\LogicException::class); + + $request = new Request(); + $request->query->set('filename', 'orders.xml'); + $fileLoader = new FileLoaderService($request, $config); + $fileLoader->load(); + } + + /** + * @param $dir + * + * @return bool + */ + private function recurseRmdir($dir): bool + { + $files = array_diff(scandir($dir), ['.', '..']); + + foreach ($files as $file) { + (is_dir("$dir/$file")) ? $this->recurseRmdir("$dir/$file") : unlink("$dir/$file"); + } + + return rmdir($dir); + } +} diff --git a/tests/Services/OfferServiceTest.php b/tests/Services/OfferServiceTest.php index a2770f7..30d8db3 100644 --- a/tests/Services/OfferServiceTest.php +++ b/tests/Services/OfferServiceTest.php @@ -1,43 +1,43 @@ - __DIR__.'/../xml', - 'models' => [ - \Bigperson\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class, - \Bigperson\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class, - \Bigperson\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class, - ], - ]; - - $config = new Config($configValues); - $request = $this->createMock(Request::class); - $dispatcher = $this->createMock(EventDispatcherInterface::class); - $builder = new ModelBuilder(); - $request->method('get') - ->with('filename') - ->willReturn('offers.xml'); - - $service = new OfferService($request, $config, $dispatcher, $builder); - $this->assertNull($service->import()); - } -} + __DIR__.'/../xml', + 'models' => [ + \Bigperson\Exchange1C\Interfaces\GroupInterface::class => \Tests\Models\GroupTestModel::class, + \Bigperson\Exchange1C\Interfaces\ProductInterface::class => \Tests\Models\ProductTestModel::class, + \Bigperson\Exchange1C\Interfaces\OfferInterface::class => \Tests\Models\OfferTestModel::class, + ], + ]; + + $config = new Config($configValues); + $request = $this->createMock(Request::class); + $dispatcher = $this->createMock(EventDispatcherInterface::class); + $builder = new ModelBuilder(); + $request->method('get') + ->with('filename') + ->willReturn('offers.xml'); + + $service = new OfferService($request, $config, $dispatcher, $builder); + $this->assertNull($service->import()); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 771a8b6..e95e265 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,15 +1,14 @@ -