From 233af72b3a7d910ec73a8dff560add5ecb876d36 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Tue, 23 Jun 2020 11:07:19 +0200 Subject: [PATCH] Remove brand attribute processor as it breaks di:compile when brands module not available --- composer.json | 1 - composer.lock | 153 ++++++++------- src/AttributeProcessor/Brand.php | 144 -------------- test/AttributeProcessor/BrandTest.php | 259 -------------------------- 4 files changed, 90 insertions(+), 467 deletions(-) delete mode 100644 src/AttributeProcessor/Brand.php delete mode 100644 test/AttributeProcessor/BrandTest.php diff --git a/composer.json b/composer.json index 7868774..b96584c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,6 @@ "magento/module-configurable-product": "^100.3.5" }, "require-dev": { - "magento/module-bundle": "^100.3.5", "phpunit/phpunit": "^8.1", "squizlabs/php_codesniffer": "^3.5", "php-mock/php-mock": "^2.0", diff --git a/composer.lock b/composer.lock index 783048f..0c54ea3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "18bb8866f456cf29c84100f1978b31b5", + "content-hash": "8a4c7e73e71714779372b1383c11f3cc", "packages": [ { "name": "colinmollenhour/credis", - "version": "1.11.1", + "version": "1.11.2", "source": { "type": "git", "url": "https://github.com/colinmollenhour/credis.git", - "reference": "bd1da4698ab1918477f9e71e5ff0062b9a345008" + "reference": "b8b2bd6b87d2d4df67065f3510efb80d5f9c4e53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/colinmollenhour/credis/zipball/bd1da4698ab1918477f9e71e5ff0062b9a345008", - "reference": "bd1da4698ab1918477f9e71e5ff0062b9a345008", + "url": "https://api.github.com/repos/colinmollenhour/credis/zipball/b8b2bd6b87d2d4df67065f3510efb80d5f9c4e53", + "reference": "b8b2bd6b87d2d4df67065f3510efb80d5f9c4e53", "shasum": "" }, "require": { @@ -44,7 +44,7 @@ ], "description": "Credis is a lightweight interface to the Redis key-value store which wraps the phpredis library when available for better performance.", "homepage": "https://github.com/colinmollenhour/credis", - "time": "2019-11-26T18:09:45+00:00" + "time": "2020-06-15T19:25:47+00:00" }, { "name": "colinmollenhour/php-redis-session-abstract", @@ -457,16 +457,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "6.5.4", + "version": "6.5.5", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "a4a1b6930528a8f7ee03518e6442ec7a44155d9d" + "reference": "9d4290de1cfd701f38099ef7e183b64b4b7b0c5e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/a4a1b6930528a8f7ee03518e6442ec7a44155d9d", - "reference": "a4a1b6930528a8f7ee03518e6442ec7a44155d9d", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/9d4290de1cfd701f38099ef7e183b64b4b7b0c5e", + "reference": "9d4290de1cfd701f38099ef7e183b64b4b7b0c5e", "shasum": "" }, "require": { @@ -474,7 +474,7 @@ "guzzlehttp/promises": "^1.0", "guzzlehttp/psr7": "^1.6.1", "php": ">=5.5", - "symfony/polyfill-intl-idn": "1.17.0" + "symfony/polyfill-intl-idn": "^1.17.0" }, "require-dev": { "ext-curl": "*", @@ -520,7 +520,7 @@ "rest", "web service" ], - "time": "2020-05-25T19:35:05+00:00" + "time": "2020-06-16T21:01:06+00:00" }, { "name": "guzzlehttp/promises", @@ -1255,16 +1255,16 @@ }, { "name": "laminas/laminas-form", - "version": "2.14.5", + "version": "2.14.6", "source": { "type": "git", "url": "https://github.com/laminas/laminas-form.git", - "reference": "3e22e09751cf6ae031be87a44e092e7925ce5b7b" + "reference": "c19b62ed8394bcf2038ab3f51a49b7d0ef4e1700" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-form/zipball/3e22e09751cf6ae031be87a44e092e7925ce5b7b", - "reference": "3e22e09751cf6ae031be87a44e092e7925ce5b7b", + "url": "https://api.github.com/repos/laminas/laminas-form/zipball/c19b62ed8394bcf2038ab3f51a49b7d0ef4e1700", + "reference": "c19b62ed8394bcf2038ab3f51a49b7d0ef4e1700", "shasum": "" }, "require": { @@ -1333,7 +1333,13 @@ "form", "laminas" ], - "time": "2020-03-29T12:46:16+00:00" + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2020-06-22T20:17:02+00:00" }, { "name": "laminas/laminas-http", @@ -4867,7 +4873,7 @@ }, { "name": "symfony/console", - "version": "v4.4.9", + "version": "v4.4.10", "source": { "type": "git", "url": "https://github.com/symfony/console.git", @@ -4958,7 +4964,7 @@ }, { "name": "symfony/filesystem", - "version": "v3.4.41", + "version": "v3.4.42", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", @@ -5022,7 +5028,7 @@ }, { "name": "symfony/finder", - "version": "v5.1.0", + "version": "v5.1.2", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -5085,16 +5091,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.17.0", + "version": "v1.17.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9" + "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e94c8b1bbe2bc77507a1056cdb06451c75b427f9", - "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", + "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", "shasum": "" }, "require": { @@ -5107,6 +5113,10 @@ "extra": { "branch-alias": { "dev-master": "1.17-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -5153,20 +5163,20 @@ "type": "tidelift" } ], - "time": "2020-05-12T16:14:59+00:00" + "time": "2020-06-06T08:46:27+00:00" }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.17.0", + "version": "v1.17.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "3bff59ea7047e925be6b7f2059d60af31bb46d6a" + "reference": "a57f8161502549a742a63c09f0a604997bf47027" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/3bff59ea7047e925be6b7f2059d60af31bb46d6a", - "reference": "3bff59ea7047e925be6b7f2059d60af31bb46d6a", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/a57f8161502549a742a63c09f0a604997bf47027", + "reference": "a57f8161502549a742a63c09f0a604997bf47027", "shasum": "" }, "require": { @@ -5181,6 +5191,10 @@ "extra": { "branch-alias": { "dev-master": "1.17-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -5229,20 +5243,20 @@ "type": "tidelift" } ], - "time": "2020-05-12T16:47:27+00:00" + "time": "2020-06-06T08:46:27+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.17.0", + "version": "v1.17.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fa79b11539418b02fc5e1897267673ba2c19419c" + "reference": "7110338d81ce1cbc3e273136e4574663627037a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fa79b11539418b02fc5e1897267673ba2c19419c", - "reference": "fa79b11539418b02fc5e1897267673ba2c19419c", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7110338d81ce1cbc3e273136e4574663627037a7", + "reference": "7110338d81ce1cbc3e273136e4574663627037a7", "shasum": "" }, "require": { @@ -5255,6 +5269,10 @@ "extra": { "branch-alias": { "dev-master": "1.17-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -5302,7 +5320,7 @@ "type": "tidelift" } ], - "time": "2020-05-12T16:47:27+00:00" + "time": "2020-06-06T08:46:27+00:00" }, { "name": "symfony/polyfill-php72", @@ -5375,16 +5393,16 @@ }, { "name": "symfony/polyfill-php73", - "version": "v1.17.0", + "version": "v1.17.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "a760d8964ff79ab9bf057613a5808284ec852ccc" + "reference": "fa0837fe02d617d31fbb25f990655861bb27bd1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/a760d8964ff79ab9bf057613a5808284ec852ccc", - "reference": "a760d8964ff79ab9bf057613a5808284ec852ccc", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fa0837fe02d617d31fbb25f990655861bb27bd1a", + "reference": "fa0837fe02d617d31fbb25f990655861bb27bd1a", "shasum": "" }, "require": { @@ -5394,6 +5412,10 @@ "extra": { "branch-alias": { "dev-master": "1.17-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -5443,20 +5465,20 @@ "type": "tidelift" } ], - "time": "2020-05-12T16:47:27+00:00" + "time": "2020-06-06T08:46:27+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.17.0", + "version": "v1.17.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "5e30b2799bc1ad68f7feb62b60a73743589438dd" + "reference": "4a5b6bba3259902e386eb80dd1956181ee90b5b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/5e30b2799bc1ad68f7feb62b60a73743589438dd", - "reference": "5e30b2799bc1ad68f7feb62b60a73743589438dd", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/4a5b6bba3259902e386eb80dd1956181ee90b5b2", + "reference": "4a5b6bba3259902e386eb80dd1956181ee90b5b2", "shasum": "" }, "require": { @@ -5466,6 +5488,10 @@ "extra": { "branch-alias": { "dev-master": "1.17-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -5519,11 +5545,11 @@ "type": "tidelift" } ], - "time": "2020-05-12T16:47:27+00:00" + "time": "2020-06-06T08:46:27+00:00" }, { "name": "symfony/process", - "version": "v4.4.9", + "version": "v4.4.10", "source": { "type": "git", "url": "https://github.com/symfony/process.git", @@ -5658,7 +5684,7 @@ }, { "name": "symfony/var-dumper", - "version": "v5.1.0", + "version": "v5.1.2", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", @@ -6387,16 +6413,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "7462d5f123dfc080dfdf26897032a6513644fc95" + "reference": "30441f2752e493c639526b215ed81d54f369d693" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95", - "reference": "7462d5f123dfc080dfdf26897032a6513644fc95", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/30441f2752e493c639526b215ed81d54f369d693", + "reference": "30441f2752e493c639526b215ed81d54f369d693", "shasum": "" }, "require": { @@ -6410,7 +6436,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.x-dev" + "dev-1.x": "1.x-dev" } }, "autoload": { @@ -6429,7 +6455,7 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2020-02-18T18:59:58+00:00" + "time": "2020-06-19T20:22:09+00:00" }, { "name": "phpspec/prophecy", @@ -6748,16 +6774,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.5.5", + "version": "8.5.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "63dda3b212a0025d380a745f91bdb4d8c985adb7" + "reference": "34c18baa6a44f1d1fbf0338907139e9dce95b997" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/63dda3b212a0025d380a745f91bdb4d8c985adb7", - "reference": "63dda3b212a0025d380a745f91bdb4d8c985adb7", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/34c18baa6a44f1d1fbf0338907139e9dce95b997", + "reference": "34c18baa6a44f1d1fbf0338907139e9dce95b997", "shasum": "" }, "require": { @@ -6837,7 +6863,7 @@ "type": "github" } ], - "time": "2020-05-22T13:51:52+00:00" + "time": "2020-06-22T07:06:58+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -7586,16 +7612,16 @@ }, { "name": "webmozart/assert", - "version": "1.8.0", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" + "reference": "9dc4f203e36f2b486149058bade43c851dd97451" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", - "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "url": "https://api.github.com/repos/webmozart/assert/zipball/9dc4f203e36f2b486149058bade43c851dd97451", + "reference": "9dc4f203e36f2b486149058bade43c851dd97451", "shasum": "" }, "require": { @@ -7603,6 +7629,7 @@ "symfony/polyfill-ctype": "^1.8" }, "conflict": { + "phpstan/phpstan": "<0.12.20", "vimeo/psalm": "<3.9.1" }, "require-dev": { @@ -7630,7 +7657,7 @@ "check", "validate" ], - "time": "2020-04-18T12:12:48+00:00" + "time": "2020-06-16T10:16:42+00:00" }, { "name": "zendframework/zendframework1", diff --git a/src/AttributeProcessor/Brand.php b/src/AttributeProcessor/Brand.php deleted file mode 100644 index a150068..0000000 --- a/src/AttributeProcessor/Brand.php +++ /dev/null @@ -1,144 +0,0 @@ - - */ -class Brand implements IndividualAttributeProcessor -{ - /** - * @var Filesystem - */ - private $filesystem; - - /** - * @var File - */ - private $file; - - /** - * @var BrandFactory - */ - private $brandFactory; - - /** - * @var BrandRepository - */ - private $brandRepository; - - /** - * @var bool - */ - private $initialised = false; - - /** - * @var BrandModel[] - */ - private $brands = []; - - public function __construct( - BrandFactory $brandFactory, - BrandRepository $brandRepository, - File $file, - Filesystem $filesystem - ) { - $this->filesystem = $filesystem; - $this->file = $file; - $this->brandFactory = $brandFactory; - $this->brandRepository = $brandRepository; - } - - public function process(AttributeInterface $attribute, string $value, Record $record, ReportItem $reportItem): int - { - $this->initialise(); - - if (isset($this->brands[$value])) { - return $this->brands[$value]->getId(); - } - - $data = [ - 'name' => $value, - 'description' => $value, - ]; - - $reportItem->addDebug(sprintf('Attempting to import brand with name: "%s"', $value)); - if ($record->columnExists('brand_image') && !empty($record->getColumnValue('brand_image'))) { - try { - $data['logo'] = $this->importImage($record->getColumnValue('brand_image')); - } catch (\InvalidArgumentException $e) { - $reportItem->addWarning( - sprintf('Could not import image for brand: "%s". Error: %s', $value, $e->getMessage()) - ); - } - } - - $brand = $this->brandFactory - ->create() - ->setData($data); - - try { - $this->brandRepository->save($brand); - $reportItem->addDebug(sprintf('Created new brand: "%s". ID: "%s"', $value, $brand->getId())); - $this->brands[$value] = $brand; //cache for later usages - } catch (CouldNotSaveException $e) { - $reportItem->addWarning(sprintf('Brand: "%s" could not be saved. Error: %s', $value, $e->getMessage())); - throw new CouldNotCreateOptionException(); - } - - return $brand->getId(); - } - - private function initialise() - { - if (false === $this->initialised) { - $this->brands = collect($this->brandRepository->getList(new SearchCriteria())->getItems()) - ->keyBy(function (BrandModel $brand) { - return $brand->getName(); - }) - ->all(); - - $this->initialised = true; - } - } - - private function importImage(string $imagePath): string - { - $mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA); - if (!$this->file->isExists($imagePath)) { - throw new \InvalidArgumentException(sprintf('Image: "%s" does not exist', $imagePath)); - } - - $imageName = basename($imagePath); - $destination = $mediaDirectory->getAbsolutePath(BrandModel::MEDIA_PATH) . '/' . $imageName; - - if ($this->file->isExists($destination)) { - throw new \InvalidArgumentException( - sprintf('Image with the name: "%s" already exists in the pub folder', $imageName) - ); - } - - try { - $this->file->createDirectory(dirname($destination)); - $this->file->rename($imagePath, $destination); - } catch (FileSystemException $e) { - throw new \InvalidArgumentException(sprintf('Image could not be renamed: "%s"', $e->getMessage())); - } - - return BrandModel::MEDIA_PATH . '/' . $imageName; - } -} diff --git a/test/AttributeProcessor/BrandTest.php b/test/AttributeProcessor/BrandTest.php deleted file mode 100644 index b072e32..0000000 --- a/test/AttributeProcessor/BrandTest.php +++ /dev/null @@ -1,259 +0,0 @@ - - */ -class BrandTest extends TestCase -{ - private $brandFactory; - private $brandRepository; - - /** - * @var BrandProcessor - */ - private $brandProcessor; - private $tempDirectory; - - public function setUp(): void - { - if (!class_exists(Brand::class)) { - $this->markTestSkipped('wearejh/m2-module-brands not installed'); - } - - $this->tempDirectory = sprintf('%s/%s', sys_get_temp_dir(), $this->getName()); - @mkdir($this->tempDirectory, 0777, true); - $this->brandFactory = $this->prophesize(BrandFactory::class); - $this->brandRepository = $this->prophesize(BrandRepository::class); - $this->brandProcessor = new BrandProcessor( - $this->brandFactory->reveal(), - $this->brandRepository->reveal(), - new File(), - new Filesystem( - new DirectoryList($this->tempDirectory), - new ReadFactory(new DriverPool()), - new WriteFactory(new DriverPool()) - ) - ); - } - - public function tearDown(): void - { - (new SymfonyFilesystem())->remove($this->tempDirectory); - } - - public function testIfBrandExistsNoNewBrandIsCreated() - { - $brand = $this->prophesize(Brand::class); - $brand->getName()->willReturn('Atom'); - $brand->getId()->willReturn(12); - - $searchResult = new BrandSearchResult(); - $searchResult->setItems([$brand->reveal()]); - $this->brandRepository->getList(Argument::type(SearchCriteria::class))->willReturn($searchResult); - - $attribute = $this->prophesize(AttributeInterface::class); - - $id = $this->brandProcessor->process( - $attribute->reveal(), - 'Atom', - new Record(10), - $this->prophesize(ReportItem::class)->reveal() - ); - - self::assertSame(12, $id); - $this->brandRepository->save()->shouldNotHaveBeenCalled(); - } - - public function testBrandIsCreatedIfItDoesNotExist() - { - $brand = $this->prophesize(Brand::class); - $brand->getName()->willReturn('Atom'); - $brand->getId()->willReturn(12); - - $searchResult = new BrandSearchResult(); - $searchResult->setItems([$brand->reveal()]); - $this->brandRepository->getList(Argument::type(SearchCriteria::class))->willReturn($searchResult); - - $newBrand = $this->prophesize(Brand::class); - $newBrand->getId()->willReturn(4); - $newBrand->setData(['name' => 'Some Brand', 'description' => 'Some Brand']) - ->willReturn($newBrand->reveal()) - ->shouldBeCalled(); - - $this->brandRepository->save($newBrand->reveal())->willReturn($newBrand->reveal())->shouldBeCalled(); - $this->brandFactory->create()->willReturn($newBrand->reveal()); - - $attribute = $this->prophesize(AttributeInterface::class); - - $id = $this->brandProcessor->process( - $attribute->reveal(), - 'Some Brand', - new Record(10), - $this->prophesize(ReportItem::class)->reveal() - ); - - self::assertSame(4, $id); - } - - public function testBrandIsOnlyCreatedOnceIfItDoesNotExist() - { - $brand = $this->prophesize(Brand::class); - $brand->getName()->willReturn('Atom'); - $brand->getId()->willReturn(12); - - $searchResult = new BrandSearchResult(); - $searchResult->setItems([$brand->reveal()]); - $this->brandRepository->getList(Argument::type(SearchCriteria::class))->willReturn($searchResult); - - $newBrand = $this->prophesize(Brand::class); - $newBrand->getId()->willReturn(4); - $newBrand->setData(['name' => 'Some Brand', 'description' => 'Some Brand']) - ->willReturn($newBrand->reveal()) - ->shouldBeCalledTimes(1); - - $this->brandRepository->save($newBrand->reveal())->willReturn($newBrand->reveal())->shouldBeCalledTimes(1); - $this->brandFactory->create()->willReturn($newBrand->reveal())->shouldBeCalledTimes(1); - - $attribute = $this->prophesize(AttributeInterface::class); - - $id = $this->brandProcessor->process( - $attribute->reveal(), - 'Some Brand', - new Record(10), - $this->prophesize(ReportItem::class)->reveal() - ); - - self::assertSame(4, $id); - - $id = $this->brandProcessor->process( - $attribute->reveal(), - 'Some Brand', - new Record(10), - $this->prophesize(ReportItem::class)->reveal() - ); - - self::assertSame(4, $id); - } - - public function testBrandIsSavedWithoutImageIfImageDoesNotExist() - { - $searchResult = new BrandSearchResult(); - $searchResult->setItems([]); - $this->brandRepository->getList(Argument::type(SearchCriteria::class))->willReturn($searchResult); - - $newBrand = $this->prophesize(Brand::class); - $newBrand->getId()->willReturn(4); - $newBrand->setData(['name' => 'Some Brand', 'description' => 'Some Brand']) - ->willReturn($newBrand->reveal()) - ->shouldBeCalled(); - - $this->brandRepository->save($newBrand->reveal())->willReturn($newBrand->reveal())->shouldBeCalled(); - $this->brandFactory->create()->willReturn($newBrand->reveal()); - - $attribute = $this->prophesize(AttributeInterface::class); - $report = $this->prophesize(ReportItem::class); - $this->brandProcessor->process( - $attribute->reveal(), - 'Some Brand', - new Record(10, ['brand_image' => '/some/file/that/does/not/exist']), - $report->reveal() - ); - - $msg = 'Could not import image for brand: "Some Brand". Error: '; - $msg .= 'Image: "/some/file/that/does/not/exist" does not exist'; - $report->addWarning($msg)->shouldHaveBeenCalled(); - } - - public function testBrandIsSavedWithoutImageIfImageWithSameNameAlreadyExists() - { - touch(sprintf('%s/my-image.png', $this->tempDirectory)); - mkdir(sprintf('%s/pub/media/catalog/product/brands', $this->tempDirectory), 0777, true); - touch(sprintf('%s/pub/media/catalog/product/brands/my-image.png', $this->tempDirectory)); - - $searchResult = new BrandSearchResult(); - $searchResult->setItems([]); - $this->brandRepository->getList(Argument::type(SearchCriteria::class))->willReturn($searchResult); - - $newBrand = $this->prophesize(Brand::class); - $newBrand->getId()->willReturn(4); - $newBrand->setData(['name' => 'Some Brand', 'description' => 'Some Brand']) - ->willReturn($newBrand->reveal()) - ->shouldBeCalled(); - - $this->brandRepository->save($newBrand->reveal())->willReturn($newBrand->reveal())->shouldBeCalled(); - $this->brandFactory->create()->willReturn($newBrand->reveal()); - - $attribute = $this->prophesize(AttributeInterface::class); - $report = $this->prophesize(ReportItem::class); - $this->brandProcessor->process( - $attribute->reveal(), - 'Some Brand', - new Record(10, ['brand_image' => sprintf('%s/my-image.png', $this->tempDirectory)]), - $report->reveal() - ); - - $msg = 'Could not import image for brand: "Some Brand". Error: '; - $msg .= 'Image with the name: "my-image.png" already exists in the pub folder'; - $report->addWarning($msg)->shouldHaveBeenCalled(); - } - - public function testImageIsImportedWithBrandIfOneIsSpecified() - { - touch(sprintf('%s/my-image.png', $this->tempDirectory)); - - $brand = $this->prophesize(Brand::class); - $brand->getName()->willReturn('Atom'); - $brand->getId()->willReturn(12); - - $searchResult = new BrandSearchResult(); - $searchResult->setItems([$brand->reveal()]); - $this->brandRepository->getList(Argument::type(SearchCriteria::class))->willReturn($searchResult); - - $newBrand = $this->prophesize(Brand::class); - $newBrand->getId()->willReturn(4); - $newBrand->setData([ - 'name' => 'Some Brand', - 'description' => 'Some Brand', - 'logo' => 'catalog/product/brands/my-image.png' - ]) - ->willReturn($newBrand->reveal()) - ->shouldBeCalled(); - - $this->brandRepository->save($newBrand->reveal())->willReturn($newBrand->reveal())->shouldBeCalled(); - $this->brandFactory->create()->willReturn($newBrand->reveal()); - - $attribute = $this->prophesize(AttributeInterface::class); - $report = $this->prophesize(ReportItem::class); - $id = $this->brandProcessor->process( - $attribute->reveal(), - 'Some Brand', - new Record(10, ['brand_image' => sprintf('%s/my-image.png', $this->tempDirectory)]), - $report->reveal() - ); - - self::assertSame(4, $id); - self::assertFileExists(sprintf('%s/pub/media/catalog/product/brands/my-image.png', $this->tempDirectory)); - self::assertFileNotExists(sprintf('%s/my-image.png', $this->tempDirectory)); - } -}