diff --git a/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminClickLogoActionGroup.xml b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminClickLogoActionGroup.xml new file mode 100644 index 0000000000000..5fe89c3b8f6f4 --- /dev/null +++ b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminClickLogoActionGroup.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminNavigateToSetupWizardPageActionGroup.xml b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminNavigateToSetupWizardPageActionGroup.xml new file mode 100644 index 0000000000000..5d5a233186c1f --- /dev/null +++ b/app/code/Magento/Backend/Test/Mftf/ActionGroup/AdminNavigateToSetupWizardPageActionGroup.xml @@ -0,0 +1,18 @@ + + + + + + + Open Setup Wizard Page. + + + + + diff --git a/app/code/Magento/Backend/Test/Mftf/Page/AdminSetupWizardPage.xml b/app/code/Magento/Backend/Test/Mftf/Page/AdminSetupWizardPage.xml new file mode 100644 index 0000000000000..40076ccd42b3a --- /dev/null +++ b/app/code/Magento/Backend/Test/Mftf/Page/AdminSetupWizardPage.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/app/code/Magento/Backend/Test/Mftf/Section/AdminMenuSection.xml b/app/code/Magento/Backend/Test/Mftf/Section/AdminMenuSection.xml index 8498ad8c52e41..e6782dca897d7 100644 --- a/app/code/Magento/Backend/Test/Mftf/Section/AdminMenuSection.xml +++ b/app/code/Magento/Backend/Test/Mftf/Section/AdminMenuSection.xml @@ -9,6 +9,7 @@
+ diff --git a/app/code/Magento/Backend/Test/Mftf/Test/AdminRedirectToAdminPanelOnLogoClickFromWizardPageTest.xml b/app/code/Magento/Backend/Test/Mftf/Test/AdminRedirectToAdminPanelOnLogoClickFromWizardPageTest.xml new file mode 100644 index 0000000000000..bf74674a2c9c8 --- /dev/null +++ b/app/code/Magento/Backend/Test/Mftf/Test/AdminRedirectToAdminPanelOnLogoClickFromWizardPageTest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + <description value="Check navigate to dashboard after click on logo on Setup Wizard Page"/> + </annotations> + <before> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminPanel"/> + </before> + <after> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/> + </after> + + <actionGroup ref="AdminNavigateToSetupWizardPageActionGroup" stepKey="navigateToSetupWizardPage"/> + <actionGroup ref="AdminClickLogoActionGroup" stepKey="clickOnLogo"/> + <actionGroup ref="AssertAdminDashboardPageIsVisibleActionGroup" stepKey="checkTheDashboardPage"/> + </test> +</tests> diff --git a/app/code/Magento/Braintree/Test/Unit/Gateway/Response/PayPal/VaultDetailsHandlerTest.php b/app/code/Magento/Braintree/Test/Unit/Gateway/Response/PayPal/VaultDetailsHandlerTest.php index b3a7f8b9ee76a..657aa930a841f 100644 --- a/app/code/Magento/Braintree/Test/Unit/Gateway/Response/PayPal/VaultDetailsHandlerTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Gateway/Response/PayPal/VaultDetailsHandlerTest.php @@ -8,8 +8,8 @@ use Braintree\Result\Successful; use Braintree\Transaction; use Braintree\Transaction\PayPalDetails; -use Magento\Braintree\Gateway\SubjectReader; use Magento\Braintree\Gateway\Response\PayPal\VaultDetailsHandler; +use Magento\Braintree\Gateway\SubjectReader; use Magento\Framework\Intl\DateTimeFactory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; @@ -99,7 +99,12 @@ protected function setUp() ->getMock(); $this->paymentExtensionMock = $this->getMockBuilder(OrderPaymentExtensionInterface::class) - ->setMethods(['setVaultPaymentToken', 'getVaultPaymentToken']) + ->setMethods([ + 'setVaultPaymentToken', + 'getVaultPaymentToken', + 'setNotificationMessage', + 'getNotificationMessage' + ]) ->disableOriginalConstructor() ->getMock(); $this->paymentExtensionFactoryMock = $this->getMockBuilder(OrderPaymentExtensionInterfaceFactory::class) @@ -119,7 +124,7 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - + $this->handler = new VaultDetailsHandler( $this->paymentTokenFactoryMock, $this->paymentExtensionFactoryMock, @@ -139,7 +144,7 @@ public function testHandle() ->with($this->paymentTokenMock); $this->paymentExtensionMock->method('getVaultPaymentToken') ->willReturn($this->paymentTokenMock); - + $this->paymentDataObjectMock->method('getPayment') ->willReturn($this->paymentInfoMock); @@ -154,7 +159,7 @@ public function testHandle() $expirationDate = '2017-07-05 00:00:00'; $this->dateTimeFactoryMock->method('create') ->willReturn($dateTime); - + $this->handler->handle($this->subject, $response); $extensionAttributes = $this->paymentInfoMock->getExtensionAttributes(); diff --git a/app/code/Magento/Braintree/Test/Unit/Gateway/Response/VaultDetailsHandlerTest.php b/app/code/Magento/Braintree/Test/Unit/Gateway/Response/VaultDetailsHandlerTest.php index c8ec52560be29..131d94f3206c8 100644 --- a/app/code/Magento/Braintree/Test/Unit/Gateway/Response/VaultDetailsHandlerTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Gateway/Response/VaultDetailsHandlerTest.php @@ -25,7 +25,7 @@ use PHPUnit_Framework_MockObject_MockObject as MockObject; /** - * VaultDetailsHandler Test + * Verify class VaultDetailsHandler * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -216,7 +216,12 @@ private function getConfigMock(): Config private function initPaymentExtensionAttributesMock() { $this->paymentExtension = $this->getMockBuilder(OrderPaymentExtensionInterface::class) - ->setMethods(['setVaultPaymentToken', 'getVaultPaymentToken']) + ->setMethods([ + 'setVaultPaymentToken', + 'getVaultPaymentToken', + 'setNotificationMessage', + 'getNotificationMessage' + ]) ->disableOriginalConstructor() ->getMock(); diff --git a/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php b/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php index fa488b073f515..2e9b8ba413af3 100644 --- a/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php +++ b/app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php @@ -6,20 +6,30 @@ namespace Magento\Bundle\Block\Catalog\Product\View\Type; use Magento\Bundle\Model\Option; +use Magento\Bundle\Model\Product\Price; +use Magento\Bundle\Model\Product\PriceFactory; +use Magento\Bundle\Model\Product\Type; +use Magento\Catalog\Block\Product\Context; +use Magento\Catalog\Block\Product\View\AbstractView; use Magento\Catalog\Model\Product; +use Magento\Catalog\Pricing\Price\FinalPrice; +use Magento\Catalog\Pricing\Price\RegularPrice; +use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor; +use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject; +use Magento\Framework\Json\EncoderInterface; +use Magento\Framework\Locale\FormatInterface; +use Magento\Framework\Stdlib\ArrayUtils; /** * Catalog bundle product info block * * @api - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @api * @since 100.0.2 + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView +class Bundle extends AbstractView { - /** * @var array */ @@ -33,17 +43,17 @@ class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView protected $catalogProduct; /** - * @var \Magento\Bundle\Model\Product\PriceFactory + * @var PriceFactory */ protected $productPriceFactory; /** - * @var \Magento\Framework\Json\EncoderInterface + * @var EncoderInterface */ protected $jsonEncoder; /** - * @var \Magento\Framework\Locale\FormatInterface + * @var FormatInterface */ protected $localeFormat; @@ -63,22 +73,24 @@ class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView private $optionsPosition = []; /** - * @param \Magento\Catalog\Block\Product\Context $context - * @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils + * @param Context $context + * @param ArrayUtils $arrayUtils * @param \Magento\Catalog\Helper\Product $catalogProduct - * @param \Magento\Bundle\Model\Product\PriceFactory $productPrice - * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder - * @param \Magento\Framework\Locale\FormatInterface $localeFormat + * @param PriceFactory $productPrice + * @param EncoderInterface $jsonEncoder + * @param FormatInterface $localeFormat * @param array $data + * @param CollectionProcessor|null $catalogRuleProcessor */ public function __construct( - \Magento\Catalog\Block\Product\Context $context, - \Magento\Framework\Stdlib\ArrayUtils $arrayUtils, + Context $context, + ArrayUtils $arrayUtils, \Magento\Catalog\Helper\Product $catalogProduct, - \Magento\Bundle\Model\Product\PriceFactory $productPrice, - \Magento\Framework\Json\EncoderInterface $jsonEncoder, - \Magento\Framework\Locale\FormatInterface $localeFormat, - array $data = [] + PriceFactory $productPrice, + EncoderInterface $jsonEncoder, + FormatInterface $localeFormat, + array $data = [], + ?CollectionProcessor $catalogRuleProcessor = null ) { $this->catalogProduct = $catalogProduct; $this->productPriceFactory = $productPrice; @@ -89,22 +101,8 @@ public function __construct( $arrayUtils, $data ); - } - - /** - * Return catalog rule processor or creates processor if it does not exist - * - * @deprecated 100.2.0 - * @return \Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor - */ - private function getCatalogRuleProcessor() - { - if ($this->catalogRuleProcessor === null) { - $this->catalogRuleProcessor = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor::class); - } - - return $this->catalogRuleProcessor; + $this->catalogRuleProcessor = $catalogRuleProcessor ?? ObjectManager::getInstance() + ->get(CollectionProcessor::class); } /** @@ -120,7 +118,7 @@ public function getOptions($stripSelection = false) { if (!$this->options) { $product = $this->getProduct(); - /** @var \Magento\Bundle\Model\Product\Type $typeInstance */ + /** @var Type $typeInstance */ $typeInstance = $product->getTypeInstance(); $typeInstance->setStoreFilter($product->getStoreId(), $product); @@ -130,7 +128,7 @@ public function getOptions($stripSelection = false) $typeInstance->getOptionsIds($product), $product ); - $this->getCatalogRuleProcessor()->addPriceData($selectionCollection); + $this->catalogRuleProcessor->addPriceData($selectionCollection); $selectionCollection->addTierPriceData(); $this->options = $optionCollection->appendSelections( @@ -151,10 +149,7 @@ public function getOptions($stripSelection = false) public function hasOptions() { $this->getOptions(); - if (empty($this->options) || !$this->getProduct()->isSalable()) { - return false; - } - return true; + return !(empty($this->options) || !$this->getProduct()->isSalable()); } /** @@ -255,7 +250,7 @@ private function getSelectionItemData(Product $product, Product $selection) ->getOptionSelectionAmount($selection) ->getValue(); - $selection = [ + return [ 'qty' => $qty, 'customQty' => $selection->getSelectionCanChangeQty(), 'optionId' => $selection->getId(), @@ -275,8 +270,6 @@ private function getSelectionItemData(Product $product, Product $selection) 'name' => $selection->getName(), 'canApplyMsrp' => false, ]; - - return $selection; } /** @@ -371,16 +364,16 @@ private function getOptionItemData(Option $option, Product $product, $position) */ private function getConfigData(Product $product, array $options) { - $isFixedPrice = $this->getProduct()->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED; + $isFixedPrice = $this->getProduct()->getPriceType() == Price::PRICE_TYPE_FIXED; $productAmount = $product ->getPriceInfo() - ->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE) + ->getPrice(FinalPrice::PRICE_CODE) ->getPriceWithoutOption(); $baseProductAmount = $product ->getPriceInfo() - ->getPrice(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE) + ->getPrice(RegularPrice::PRICE_CODE) ->getAmount(); $config = [ diff --git a/app/code/Magento/Bundle/Model/LinkManagement.php b/app/code/Magento/Bundle/Model/LinkManagement.php index 8c85c06c7342d..43a6532a16b2d 100644 --- a/app/code/Magento/Bundle/Model/LinkManagement.php +++ b/app/code/Magento/Bundle/Model/LinkManagement.php @@ -1,36 +1,49 @@ <?php /** - * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Bundle\Model; +use Magento\Bundle\Api\Data\LinkInterface; +use Magento\Bundle\Api\Data\LinkInterfaceFactory; +use Magento\Bundle\Api\Data\OptionInterface; +use Magento\Bundle\Api\ProductLinkManagementInterface; +use Magento\Bundle\Model\Product\Type; +use Magento\Bundle\Model\ResourceModel\Bundle; +use Magento\Bundle\Model\ResourceModel\BundleFactory; +use Magento\Bundle\Model\ResourceModel\Option\CollectionFactory; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\Framework\App\ObjectManager; +use Magento\Catalog\Model\Product; +use Magento\Framework\Api\DataObjectHelper; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Framework\Exception\InputException; use Magento\Framework\EntityManager\MetadataPool; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Store\Model\StoreManagerInterface; /** + * Class used to manage bundle products links. + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterface +class LinkManagement implements ProductLinkManagementInterface { /** - * @var \Magento\Catalog\Api\ProductRepositoryInterface + * @var ProductRepositoryInterface */ protected $productRepository; /** - * @var \Magento\Bundle\Api\Data\LinkInterfaceFactory + * @var LinkInterfaceFactory */ protected $linkFactory; /** - * @var \Magento\Bundle\Model\ResourceModel\BundleFactory + * @var BundleFactory */ protected $bundleFactory; @@ -40,12 +53,17 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa protected $bundleSelection; /** - * @var \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory + * @var CollectionFactory */ protected $optionCollection; /** - * @var \Magento\Framework\Api\DataObjectHelper + * @var StoreManagerInterface + */ + private $storeManager; + + /** + * @var DataObjectHelper */ protected $dataObjectHelper; @@ -56,21 +74,23 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa /** * @param ProductRepositoryInterface $productRepository - * @param \Magento\Bundle\Api\Data\LinkInterfaceFactory $linkFactory - * @param \Magento\Bundle\Model\SelectionFactory $bundleSelection - * @param \Magento\Bundle\Model\ResourceModel\BundleFactory $bundleFactory - * @param \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper + * @param LinkInterfaceFactory $linkFactory + * @param SelectionFactory $bundleSelection + * @param BundleFactory $bundleFactory + * @param CollectionFactory $optionCollection + * @param StoreManagerInterface $storeManager + * @param DataObjectHelper $dataObjectHelper + * @param MetadataPool $metadataPool */ public function __construct( ProductRepositoryInterface $productRepository, - \Magento\Bundle\Api\Data\LinkInterfaceFactory $linkFactory, - \Magento\Bundle\Model\SelectionFactory $bundleSelection, - \Magento\Bundle\Model\ResourceModel\BundleFactory $bundleFactory, - \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Api\DataObjectHelper $dataObjectHelper + LinkInterfaceFactory $linkFactory, + SelectionFactory $bundleSelection, + BundleFactory $bundleFactory, + CollectionFactory $optionCollection, + StoreManagerInterface $storeManager, + DataObjectHelper $dataObjectHelper, + MetadataPool $metadataPool ) { $this->productRepository = $productRepository; $this->linkFactory = $linkFactory; @@ -79,15 +99,16 @@ public function __construct( $this->optionCollection = $optionCollection; $this->storeManager = $storeManager; $this->dataObjectHelper = $dataObjectHelper; + $this->metadataPool = $metadataPool; } /** - * {@inheritdoc} + * @inheritDoc */ public function getChildren($productSku, $optionId = null) { $product = $this->productRepository->get($productSku, true); - if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { + if ($product->getTypeId() != Product\Type::TYPE_BUNDLE) { throw new InputException(__('This is implemented for bundle products only.')); } @@ -96,7 +117,7 @@ public function getChildren($productSku, $optionId = null) if (!$option->getSelections() || ($optionId !== null && $option->getOptionId() != $optionId)) { continue; } - /** @var \Magento\Catalog\Model\Product $selection */ + /** @var Product $selection */ foreach ($option->getSelections() as $selection) { $childrenList[] = $this->buildLink($selection, $product); } @@ -105,32 +126,33 @@ public function getChildren($productSku, $optionId = null) } /** - * {@inheritdoc} + * @inheritDoc */ - public function addChildByProductSku($sku, $optionId, \Magento\Bundle\Api\Data\LinkInterface $linkedProduct) + public function addChildByProductSku($sku, $optionId, LinkInterface $linkedProduct) { - /** @var \Magento\Catalog\Model\Product $product */ + /** @var Product $product */ $product = $this->productRepository->get($sku, true); return $this->addChild($product, $optionId, $linkedProduct); } /** - * {@inheritdoc} + * @inheritDoc + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function saveChild( $sku, - \Magento\Bundle\Api\Data\LinkInterface $linkedProduct + LinkInterface $linkedProduct ) { $product = $this->productRepository->get($sku, true); - if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { + if ($product->getTypeId() != Product\Type::TYPE_BUNDLE) { throw new InputException( __('The product with the "%1" SKU isn\'t a bundle product.', [$product->getSku()]) ); } - /** @var \Magento\Catalog\Model\Product $linkProductModel */ + /** @var Product $linkProductModel */ $linkProductModel = $this->productRepository->get($linkedProduct->getSku()); if ($linkProductModel->isComposite()) { throw new InputException(__('The bundle product can\'t contain another composite product.')); @@ -140,7 +162,7 @@ public function saveChild( throw new InputException(__('The product link needs an ID field entered. Enter and try again.')); } - /** @var \Magento\Bundle\Model\Selection $selectionModel */ + /** @var Selection $selectionModel */ $selectionModel = $this->bundleSelection->create(); $selectionModel->load($linkedProduct->getId()); if (!$selectionModel->getId()) { @@ -151,7 +173,7 @@ public function saveChild( ) ); } - $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField(); + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $selectionModel = $this->mapProductLinkToSelectionModel( $selectionModel, $linkedProduct, @@ -169,17 +191,21 @@ public function saveChild( } /** - * @param \Magento\Bundle\Model\Selection $selectionModel - * @param \Magento\Bundle\Api\Data\LinkInterface $productLink + * Fill selection model with product link data + * + * @param Selection $selectionModel + * @param LinkInterface $productLink * @param string $linkedProductId * @param string $parentProductId - * @return \Magento\Bundle\Model\Selection + * + * @return Selection + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function mapProductLinkToSelectionModel( - \Magento\Bundle\Model\Selection $selectionModel, - \Magento\Bundle\Api\Data\LinkInterface $productLink, + Selection $selectionModel, + LinkInterface $productLink, $linkedProductId, $parentProductId ) { @@ -214,21 +240,22 @@ protected function mapProductLinkToSelectionModel( } /** - * {@inheritdoc} + * @inheritDoc + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function addChild( - \Magento\Catalog\Api\Data\ProductInterface $product, + ProductInterface $product, $optionId, - \Magento\Bundle\Api\Data\LinkInterface $linkedProduct + LinkInterface $linkedProduct ) { - if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { + if ($product->getTypeId() != Product\Type::TYPE_BUNDLE) { throw new InputException( __('The product with the "%1" SKU isn\'t a bundle product.', $product->getSku()) ); } - $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField(); + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $options = $this->optionCollection->create(); @@ -246,10 +273,10 @@ public function addChild( ); } - /* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */ + /* @var $resource Bundle */ $resource = $this->bundleFactory->create(); $selections = $resource->getSelectionsData($product->getData($linkField)); - /** @var \Magento\Catalog\Model\Product $linkProductModel */ + /** @var Product $linkProductModel */ $linkProductModel = $this->productRepository->get($linkedProduct->getSku()); if ($linkProductModel->isComposite()) { throw new InputException(__('The bundle product can\'t contain another composite product.')); @@ -267,9 +294,9 @@ public function addChild( [$linkedProduct->getSku(), $product->getSku()] ) ); - } else { - return $this->bundleSelection->create()->load($linkProductModel->getEntityId()); } + + return $this->bundleSelection->create()->load($linkProductModel->getEntityId()); } } } @@ -294,13 +321,13 @@ public function addChild( } /** - * {@inheritdoc} + * @inheritDoc */ public function removeChild($sku, $optionId, $childSku) { $product = $this->productRepository->get($sku, true); - if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) { + if ($product->getTypeId() != Product\Type::TYPE_BUNDLE) { throw new InputException(__('The product with the "%1" SKU isn\'t a bundle product.', $sku)); } @@ -308,7 +335,7 @@ public function removeChild($sku, $optionId, $childSku) $usedProductIds = []; $removeSelectionIds = []; foreach ($this->getOptions($product) as $option) { - /** @var \Magento\Bundle\Model\Selection $selection */ + /** @var Selection $selection */ foreach ($option->getSelections() as $selection) { if ((strcasecmp($selection->getSku(), $childSku) == 0) && ($selection->getOptionId() == $optionId)) { $removeSelectionIds[] = $selection->getSelectionId(); @@ -319,12 +346,12 @@ public function removeChild($sku, $optionId, $childSku) } } if (empty($removeSelectionIds)) { - throw new \Magento\Framework\Exception\NoSuchEntityException( + throw new NoSuchEntityException( __("The bundle product doesn't exist. Review your request and try again.") ); } - $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField(); - /* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */ + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + /* @var $resource Bundle */ $resource = $this->bundleFactory->create(); $resource->dropAllUnneededSelections($product->getData($linkField), $excludeSelectionIds); $resource->removeProductRelations($product->getData($linkField), array_unique($usedProductIds)); @@ -333,26 +360,29 @@ public function removeChild($sku, $optionId, $childSku) } /** - * @param \Magento\Catalog\Model\Product $selection - * @param \Magento\Catalog\Model\Product $product - * @return \Magento\Bundle\Api\Data\LinkInterface + * Build bundle link between two products + * + * @param Product $selection + * @param Product $product + * + * @return LinkInterface */ - private function buildLink(\Magento\Catalog\Model\Product $selection, \Magento\Catalog\Model\Product $product) + private function buildLink(Product $selection, Product $product) { $selectionPriceType = $selectionPrice = null; - /** @var \Magento\Bundle\Model\Selection $product */ + /** @var Selection $product */ if ($product->getPriceType()) { $selectionPriceType = $selection->getSelectionPriceType(); $selectionPrice = $selection->getSelectionPriceValue(); } - /** @var \Magento\Bundle\Api\Data\LinkInterface $link */ + /** @var LinkInterface $link */ $link = $this->linkFactory->create(); $this->dataObjectHelper->populateWithArray( $link, $selection->getData(), - \Magento\Bundle\Api\Data\LinkInterface::class + LinkInterface::class ); $link->setIsDefault($selection->getIsDefault()) ->setId($selection->getSelectionId()) @@ -364,12 +394,15 @@ private function buildLink(\Magento\Catalog\Model\Product $selection, \Magento\C } /** - * @param \Magento\Catalog\Api\Data\ProductInterface $product - * @return \Magento\Bundle\Api\Data\OptionInterface[] + * Get bundle product options + * + * @param ProductInterface $product + * + * @return OptionInterface[] */ - private function getOptions(\Magento\Catalog\Api\Data\ProductInterface $product) + private function getOptions(ProductInterface $product) { - /** @var \Magento\Bundle\Model\Product\Type $productTypeInstance */ + /** @var Type $productTypeInstance */ $productTypeInstance = $product->getTypeInstance(); $productTypeInstance->setStoreFilter( $product->getStoreId(), @@ -383,19 +416,6 @@ private function getOptions(\Magento\Catalog\Api\Data\ProductInterface $product) $product ); - $options = $optionCollection->appendSelections($selectionCollection, true); - return $options; - } - - /** - * Get MetadataPool instance - * @return MetadataPool - */ - private function getMetadataPool() - { - if (!$this->metadataPool) { - $this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class); - } - return $this->metadataPool; + return $optionCollection->appendSelections($selectionCollection, true); } } diff --git a/app/code/Magento/Bundle/Model/Product/SaveHandler.php b/app/code/Magento/Bundle/Model/Product/SaveHandler.php index 99e8188146bbb..8c2727a71aac1 100644 --- a/app/code/Magento/Bundle/Model/Product/SaveHandler.php +++ b/app/code/Magento/Bundle/Model/Product/SaveHandler.php @@ -3,58 +3,59 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Bundle\Model\Product; +use Magento\Bundle\Api\Data\OptionInterface; use Magento\Bundle\Model\Option\SaveAction; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Bundle\Api\ProductOptionRepositoryInterface as OptionRepository; use Magento\Bundle\Api\ProductLinkManagementInterface; -use Magento\Framework\App\ObjectManager; use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\EntityManager\Operation\ExtensionInterface; /** - * Class SaveHandler + * Bundle product save handler */ class SaveHandler implements ExtensionInterface { /** * @var OptionRepository */ - protected $optionRepository; + private $optionRepository; /** * @var ProductLinkManagementInterface */ - protected $productLinkManagement; + private $productLinkManagement; /** - * @var MetadataPool + * @var SaveAction */ - private $metadataPool; + private $optionSave; /** - * @var SaveAction + * @var MetadataPool */ - private $optionSave; + private $metadataPool; /** * @param OptionRepository $optionRepository * @param ProductLinkManagementInterface $productLinkManagement * @param SaveAction $optionSave - * @param MetadataPool|null $metadataPool + * @param MetadataPool $metadataPool */ public function __construct( OptionRepository $optionRepository, ProductLinkManagementInterface $productLinkManagement, SaveAction $optionSave, - MetadataPool $metadataPool = null + MetadataPool $metadataPool ) { $this->optionRepository = $optionRepository; $this->productLinkManagement = $productLinkManagement; $this->optionSave = $optionSave; - $this->metadataPool = $metadataPool - ?: ObjectManager::getInstance()->get(MetadataPool::class); + $this->metadataPool = $metadataPool; } /** @@ -69,7 +70,7 @@ public function __construct( */ public function execute($entity, $arguments = []) { - /** @var \Magento\Bundle\Api\Data\OptionInterface[] $bundleProductOptions */ + /** @var OptionInterface[] $bundleProductOptions */ $bundleProductOptions = $entity->getExtensionAttributes()->getBundleProductOptions() ?: []; //Only processing bundle products. if ($entity->getTypeId() !== Type::TYPE_CODE || empty($bundleProductOptions)) { @@ -101,7 +102,8 @@ public function execute($entity, $arguments = []) * Remove option product links * * @param string $entitySku - * @param \Magento\Bundle\Api\Data\OptionInterface $option + * @param OptionInterface $option + * * @return void */ protected function removeOptionLinks($entitySku, $option) @@ -120,6 +122,7 @@ protected function removeOptionLinks($entitySku, $option) * @param object $entity * @param array $options * @param array $newOptionsIds + * * @return void */ private function saveOptions($entity, array $options, array $newOptionsIds = []): void @@ -137,6 +140,7 @@ private function saveOptions($entity, array $options, array $newOptionsIds = []) * Get options ids from array of the options entities. * * @param array $options + * * @return array */ private function getOptionIds(array $options): array @@ -144,7 +148,7 @@ private function getOptionIds(array $options): array $optionIds = []; if (!empty($options)) { - /** @var \Magento\Bundle\Api\Data\OptionInterface $option */ + /** @var OptionInterface $option */ foreach ($options as $option) { if ($option->getOptionId()) { $optionIds[] = $option->getOptionId(); @@ -161,6 +165,7 @@ private function getOptionIds(array $options): array * @param ProductInterface $entity * @param array $existingOptionsIds * @param array $optionIds + * * @return void */ private function processRemovedOptions(ProductInterface $entity, array $existingOptionsIds, array $optionIds): void diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php index 803fbae067e9d..6808081506dd7 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php @@ -3,65 +3,65 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Bundle\Model\ResourceModel\Indexer; +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full; -use Magento\Framework\App\ObjectManager; +use Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock; +use Magento\Eav\Model\Config; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Indexer\Table\StrategyInterface; +use Magento\Framework\Model\ResourceModel\Db\Context; /** * Bundle Stock Status Indexer Resource Model * - * @author Magento Core Team <core@magentocommerce.com> + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Stock extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock +class Stock extends DefaultStock { /** - * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher + * @var ActiveTableSwitcher */ private $activeTableSwitcher; /** - * @var \Magento\Bundle\Model\ResourceModel\Indexer\StockStatusSelectBuilder + * @var StockStatusSelectBuilder */ private $stockStatusSelectBuilder; /** - * @var \Magento\Bundle\Model\ResourceModel\Indexer\BundleOptionStockDataSelectBuilder + * @var BundleOptionStockDataSelectBuilder */ private $bundleOptionStockDataSelectBuilder; /** - * Class constructor - * - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy - * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param null $connectionName - * @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher - * @param StockStatusSelectBuilder|null $stockStatusSelectBuilder - * @param BundleOptionStockDataSelectBuilder|null $bundleOptionStockDataSelectBuilder + * @param Context $context + * @param StrategyInterface $tableStrategy + * @param Config $eavConfig + * @param ScopeConfigInterface $scopeConfig + * @param ActiveTableSwitcher $activeTableSwitcher + * @param StockStatusSelectBuilder $stockStatusSelectBuilder + * @param BundleOptionStockDataSelectBuilder $bundleOptionStockDataSelectBuilder + * @param string $connectionName */ public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, - \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - $connectionName = null, - \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null, - StockStatusSelectBuilder $stockStatusSelectBuilder = null, - BundleOptionStockDataSelectBuilder $bundleOptionStockDataSelectBuilder = null + Context $context, + StrategyInterface $tableStrategy, + Config $eavConfig, + ScopeConfigInterface $scopeConfig, + ActiveTableSwitcher $activeTableSwitcher, + StockStatusSelectBuilder $stockStatusSelectBuilder, + BundleOptionStockDataSelectBuilder $bundleOptionStockDataSelectBuilder, + $connectionName = null ) { parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName); - $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class); - - $this->stockStatusSelectBuilder = $stockStatusSelectBuilder ?: ObjectManager::getInstance() - ->get(StockStatusSelectBuilder::class); - - $this->bundleOptionStockDataSelectBuilder = $bundleOptionStockDataSelectBuilder ?: ObjectManager::getInstance() - ->get(BundleOptionStockDataSelectBuilder::class); + $this->activeTableSwitcher = $activeTableSwitcher; + $this->stockStatusSelectBuilder = $stockStatusSelectBuilder; + $this->bundleOptionStockDataSelectBuilder = $bundleOptionStockDataSelectBuilder; } /** @@ -79,6 +79,7 @@ protected function _getBundleOptionTable() * * @param int|array $entityIds * @param bool $usePrimaryTable use primary or temporary index table + * * @return $this */ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryTable = false) @@ -122,6 +123,7 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT * * @param int|array $entityIds * @param bool $usePrimaryTable use primary or temporary index table + * * @return \Magento\Framework\DB\Select */ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false) @@ -171,6 +173,7 @@ protected function _prepareIndexTable($entityIds = null) * Update Stock status index by product ids * * @param array|int $entityIds + * * @return $this */ protected function _updateIndex($entityIds) diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Option.php b/app/code/Magento/Bundle/Model/ResourceModel/Option.php index 7babd0b349f02..1260233b5bcb3 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Option.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Option.php @@ -3,20 +3,26 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Bundle\Model\ResourceModel; +use Magento\Bundle\Model\Option\Validator; use Magento\Catalog\Api\Data\ProductInterface; -use Magento\Framework\EntityManager\MetadataPool; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\DataObject; use Magento\Framework\EntityManager\EntityManager; +use Magento\Framework\EntityManager\MetadataPool; +use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Context; /** * Bundle Option Resource Model */ -class Option extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Option extends AbstractDb { /** - * @var \Magento\Bundle\Model\Option\Validator + * @var Validator */ private $validator; @@ -31,22 +37,23 @@ class Option extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb private $entityManager; /** - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Bundle\Model\Option\Validator $validator + * @param Context $context + * @param Validator $validator + * @param MetadataPool $metadataPool + * @param EntityManager $entityManager * @param string $connectionName - * @param EntityManager|null $entityManager */ public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - \Magento\Bundle\Model\Option\Validator $validator, - $connectionName = null, - EntityManager $entityManager = null + Context $context, + Validator $validator, + MetadataPool $metadataPool, + EntityManager $entityManager, + $connectionName = null ) { parent::__construct($context, $connectionName); $this->validator = $validator; - - $this->entityManager = $entityManager - ?: ObjectManager::getInstance()->get(EntityManager::class); + $this->metadataPool = $metadataPool; + $this->entityManager = $entityManager; } /** @@ -60,7 +67,10 @@ protected function _construct() } /** + * Remove selections by option id + * * @param int $optionId + * * @return int */ public function removeOptionSelections($optionId) @@ -74,10 +84,11 @@ public function removeOptionSelections($optionId) /** * After save process * - * @param \Magento\Framework\Model\AbstractModel $object + * @param AbstractModel $object + * * @return $this */ - protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) + protected function _afterSave(AbstractModel $object) { parent::_afterSave($object); @@ -90,7 +101,7 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) $connection = $this->getConnection(); $connection->delete($this->getTable('catalog_product_bundle_option_value'), $condition); - $data = new \Magento\Framework\DataObject(); + $data = new DataObject(); $data->setOptionId($object->getId()) ->setStoreId($object->getStoreId()) ->setParentProductId($object->getParentId()) @@ -112,10 +123,10 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) /** * After delete process * - * @param \Magento\Framework\Model\AbstractModel $object + * @param AbstractModel $object * @return $this */ - protected function _afterDelete(\Magento\Framework\Model\AbstractModel $object) + protected function _afterDelete(AbstractModel $object) { parent::_afterDelete($object); @@ -136,6 +147,7 @@ protected function _afterDelete(\Magento\Framework\Model\AbstractModel $object) * * @param int $productId * @param int $storeId + * * @return array */ public function getSearchableData($productId, $storeId) @@ -148,7 +160,7 @@ public function getSearchableData($productId, $storeId) 'option_title_default.title' ); $bind = ['store_id' => $storeId, 'product_id' => $productId]; - $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField(); + $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $select = $connection->select() ->from( ['opt' => $this->getMainTable()], @@ -180,7 +192,7 @@ public function getSearchableData($productId, $storeId) } /** - * {@inheritdoc} + * @inheritDoc */ public function getValidationRulesBeforeSave() { @@ -188,21 +200,9 @@ public function getValidationRulesBeforeSave() } /** - * Get MetadataPool instance - * @return MetadataPool - */ - private function getMetadataPool() - { - if (!$this->metadataPool) { - $this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class); - } - return $this->metadataPool; - } - - /** - * {@inheritdoc} + * @inheritDoc */ - public function save(\Magento\Framework\Model\AbstractModel $object) + public function save(AbstractModel $object) { $this->entityManager->save($object); diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php index 30e37e54a21db..441bc0dd9de89 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php @@ -6,8 +6,14 @@ namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; use Magento\Catalog\Model\Product\Type\AbstractType; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Filesystem; +use Magento\Framework\Filter\FilterManager; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; use Magento\Framework\Serialize\Serializer\Json; +use Magento\Tax\Helper\Data; /** * Order pdf items renderer @@ -24,30 +30,28 @@ abstract class AbstractItems extends \Magento\Sales\Model\Order\Pdf\Items\Abstra private $serializer; /** - * Constructor - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Tax\Helper\Data $taxData - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\Filter\FilterManager $filterManager - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param Data $taxData + * @param Filesystem $filesystem + * @param FilterManager $filterManager + * @param Json $serializer + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json $serializer */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Tax\Helper\Data $taxData, - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\Filter\FilterManager $filterManager, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [], - Json $serializer = null + Context $context, + Registry $registry, + Data $taxData, + Filesystem $filesystem, + FilterManager $filterManager, + Json $serializer, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, + array $data = [] ) { - $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class); + $this->serializer = $serializer; parent::__construct( $context, $registry, diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index 3d7d05396e0fc..1ed3fc76ddee0 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -3,10 +3,19 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Filesystem; +use Magento\Framework\Filter\FilterManager; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\Stdlib\StringUtils; +use Magento\Tax\Helper\Data; /** * Order creditmemo pdf default items renderer @@ -16,36 +25,34 @@ class Creditmemo extends AbstractItems /** * Core string * - * @var \Magento\Framework\Stdlib\StringUtils + * @var StringUtils */ protected $string; /** - * Constructor - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Tax\Helper\Data $taxData - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\Filter\FilterManager $filterManager - * @param \Magento\Framework\Stdlib\StringUtils $string - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param Data $taxData + * @param Filesystem $filesystem + * @param FilterManager $filterManager + * @param Json $serializer + * @param StringUtils $string + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Tax\Helper\Data $taxData, - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\Filter\FilterManager $filterManager, - \Magento\Framework\Stdlib\StringUtils $string, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [], - Json $serializer = null + Context $context, + Registry $registry, + Data $taxData, + Filesystem $filesystem, + FilterManager $filterManager, + Json $serializer, + StringUtils $string, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, + array $data = [] ) { $this->string = $string; parent::__construct( @@ -54,10 +61,10 @@ public function __construct( $taxData, $filesystem, $filterManager, + $serializer, $resource, $resourceCollection, - $data, - $serializer + $data ); } @@ -98,19 +105,17 @@ public function draw() } // draw selection attributes - if ($childItem->getOrderItem()->getParentItem()) { - if ($prevOptionId != $attributes['option_id']) { - $line[0] = [ - 'font' => 'italic', - 'text' => $this->string->split($attributes['option_label'], 38, true, true), - 'feed' => $x, - ]; + if ($childItem->getOrderItem()->getParentItem() && $prevOptionId != $attributes['option_id']) { + $line[0] = [ + 'font' => 'italic', + 'text' => $this->string->split($attributes['option_label'], 38, true, true), + 'feed' => $x, + ]; - $drawItems[$optionId] = ['lines' => [$line], 'height' => 15]; + $drawItems[$optionId] = ['lines' => [$line], 'height' => 15]; - $line = []; - $prevOptionId = $attributes['option_id']; - } + $line = []; + $prevOptionId = $attributes['option_id']; } // draw product titles @@ -152,7 +157,7 @@ public function draw() // draw QTY $text = $childItem->getQty() * 1; $line[] = [ - 'text' => $childItem->getQty() * 1, + 'text' => $text, 'feed' => $x, 'font' => 'bold', 'align' => 'center', @@ -177,40 +182,34 @@ public function draw() // custom options $options = $item->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['options'])) { - foreach ($options['options'] as $option) { - $lines = []; - $lines[][] = [ - 'text' => $this->string->split( - $this->filterManager->stripTags($option['label']), - 40, - true, - true - ), - 'font' => 'italic', - 'feed' => $leftBound, - ]; - - if ($option['value']) { - $text = []; - $printValue = isset( - $option['print_value'] - ) ? $option['print_value'] : $this->filterManager->stripTags( - $option['value'] - ); - $values = explode(', ', $printValue); - foreach ($values as $value) { - foreach ($this->string->split($value, 30, true, true) as $subValue) { - $text[] = $subValue; - } - } + if ($options && isset($options['options'])) { + foreach ($options['options'] as $option) { + $lines = []; + $lines[][] = [ + 'text' => $this->string->split( + $this->filterManager->stripTags($option['label']), + 40, + true, + true + ), + 'font' => 'italic', + 'feed' => $leftBound, + ]; - $lines[][] = ['text' => $text, 'feed' => $leftBound + 5]; + if ($option['value']) { + $text = []; + $printValue = $option['print_value'] ?? $this->filterManager->stripTags($option['value']); + $values = explode(', ', $printValue); + foreach ($values as $value) { + foreach ($this->string->split($value, 30, true, true) as $subValue) { + $text[] = $subValue; + } } - $drawItems[] = ['lines' => $lines, 'height' => 15]; + $lines[][] = ['text' => $text, 'feed' => $leftBound + 5]; } + + $drawItems[] = ['lines' => $lines, 'height' => 15]; } } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index 1827c2249dda3..64e9f56dd65bc 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -3,10 +3,19 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Filesystem; +use Magento\Framework\Filter\FilterManager; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\Stdlib\StringUtils; +use Magento\Tax\Helper\Data; /** * Order invoice pdf default items renderer @@ -14,36 +23,36 @@ class Invoice extends AbstractItems { /** - * @var \Magento\Framework\Stdlib\StringUtils + * @var StringUtils */ protected $string; /** * Constructor * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Tax\Helper\Data $taxData - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\Filter\FilterManager $filterManager - * @param \Magento\Framework\Stdlib\StringUtils $coreString - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param Data $taxData + * @param Filesystem $filesystem + * @param FilterManager $filterManager + * @param StringUtils $coreString + * @param Json $serializer + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Tax\Helper\Data $taxData, - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\Filter\FilterManager $filterManager, - \Magento\Framework\Stdlib\StringUtils $coreString, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [], - Json $serializer = null + Context $context, + Registry $registry, + Data $taxData, + Filesystem $filesystem, + FilterManager $filterManager, + StringUtils $coreString, + Json $serializer, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, + array $data = [] ) { $this->string = $coreString; parent::__construct( @@ -52,10 +61,10 @@ public function __construct( $taxData, $filesystem, $filterManager, + $serializer, $resource, $resourceCollection, - $data, - $serializer + $data ); } @@ -94,19 +103,17 @@ public function draw() $drawItems[$optionId] = ['lines' => [], 'height' => 15]; } - if ($childItem->getOrderItem()->getParentItem()) { - if ($prevOptionId != $attributes['option_id']) { - $line[0] = [ - 'font' => 'italic', - 'text' => $this->string->split($attributes['option_label'], 45, true, true), - 'feed' => 35, - ]; + if ($childItem->getOrderItem()->getParentItem() && $prevOptionId != $attributes['option_id']) { + $line[0] = [ + 'font' => 'italic', + 'text' => $this->string->split($attributes['option_label'], 45, true, true), + 'feed' => 35, + ]; - $drawItems[$optionId] = ['lines' => [$line], 'height' => 15]; + $drawItems[$optionId] = ['lines' => [$line], 'height' => 15]; - $line = []; - $prevOptionId = $attributes['option_id']; - } + $line = []; + $prevOptionId = $attributes['option_id']; } /* in case Product name is longer than 80 chars - it is written in a few lines */ @@ -146,40 +153,34 @@ public function draw() // custom options $options = $item->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['options'])) { - foreach ($options['options'] as $option) { - $lines = []; - $lines[][] = [ - 'text' => $this->string->split( - $this->filterManager->stripTags($option['label']), - 40, - true, - true - ), - 'font' => 'italic', - 'feed' => 35, - ]; - - if ($option['value']) { - $text = []; - $printValue = isset( - $option['print_value'] - ) ? $option['print_value'] : $this->filterManager->stripTags( - $option['value'] - ); - $values = explode(', ', $printValue); - foreach ($values as $value) { - foreach ($this->string->split($value, 30, true, true) as $subValue) { - $text[] = $subValue; - } + if ($options && isset($options['options'])) { + foreach ($options['options'] as $option) { + $lines = []; + $lines[][] = [ + 'text' => $this->string->split( + $this->filterManager->stripTags($option['label']), + 40, + true, + true + ), + 'font' => 'italic', + 'feed' => 35, + ]; + + if ($option['value']) { + $text = []; + $printValue = $option['print_value'] ?? $this->filterManager->stripTags($option['value']); + $values = explode(', ', $printValue); + foreach ($values as $value) { + foreach ($this->string->split($value, 30, true, true) as $subValue) { + $text[] = $subValue; } - - $lines[][] = ['text' => $text, 'feed' => 40]; } - $drawItems[] = ['lines' => $lines, 'height' => 15]; + $lines[][] = ['text' => $text, 'feed' => 40]; } + + $drawItems[] = ['lines' => $lines, 'height' => 15]; } } diff --git a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index 08ccf0618d03e..8a293b63541a2 100644 --- a/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -3,10 +3,19 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Bundle\Model\Sales\Order\Pdf\Items; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Filesystem; +use Magento\Framework\Filter\FilterManager; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\Stdlib\StringUtils; +use Magento\Tax\Helper\Data; /** * Order shipment pdf items renderer @@ -14,36 +23,34 @@ class Shipment extends AbstractItems { /** - * @var \Magento\Framework\Stdlib\StringUtils + * @var StringUtils */ protected $string; /** - * Constructor - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Tax\Helper\Data $taxData - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\Filter\FilterManager $filterManager - * @param \Magento\Framework\Stdlib\StringUtils $string - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param Data $taxData + * @param Filesystem $filesystem + * @param FilterManager $filterManager + * @param StringUtils $string + * @param Json $serializer + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data - * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Tax\Helper\Data $taxData, - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\Filter\FilterManager $filterManager, - \Magento\Framework\Stdlib\StringUtils $string, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [], - Json $serializer = null + Context $context, + Registry $registry, + Data $taxData, + Filesystem $filesystem, + FilterManager $filterManager, + StringUtils $string, + Json $serializer, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, + array $data = [] ) { $this->string = $string; parent::__construct( @@ -52,10 +59,10 @@ public function __construct( $taxData, $filesystem, $filterManager, + $serializer, $resource, $resourceCollection, - $data, - $serializer + $data ); } @@ -95,24 +102,22 @@ public function draw() $drawItems[$optionId] = ['lines' => [], 'height' => 15]; } - if ($childItem->getParentItem()) { - if ($prevOptionId != $attributes['option_id']) { - $line[0] = [ - 'font' => 'italic', - 'text' => $this->string->split($attributes['option_label'], 60, true, true), - 'feed' => 60, - ]; + if ($childItem->getParentItem() && $prevOptionId != $attributes['option_id']) { + $line[0] = [ + 'font' => 'italic', + 'text' => $this->string->split($attributes['option_label'], 60, true, true), + 'feed' => 60, + ]; - $drawItems[$optionId] = ['lines' => [$line], 'height' => 15]; + $drawItems[$optionId] = ['lines' => [$line], 'height' => 15]; - $line = []; + $line = []; - $prevOptionId = $attributes['option_id']; - } + $prevOptionId = $attributes['option_id']; } - if ($this->isShipmentSeparately() && $childItem->getParentItem() || - !$this->isShipmentSeparately() && !$childItem->getParentItem() + if (($this->isShipmentSeparately() && $childItem->getParentItem()) || + (!$this->isShipmentSeparately() && !$childItem->getParentItem()) ) { if (isset($shipItems[$childItem->getId()])) { $qty = $shipItems[$childItem->getId()]->getQty() * 1; @@ -153,40 +158,34 @@ public function draw() // custom options $options = $item->getOrderItem()->getProductOptions(); - if ($options) { - if (isset($options['options'])) { - foreach ($options['options'] as $option) { - $lines = []; - $lines[][] = [ - 'text' => $this->string->split( - $this->filterManager->stripTags($option['label']), - 70, - true, - true - ), - 'font' => 'italic', - 'feed' => 60, - ]; - - if ($option['value']) { - $text = []; - $printValue = isset( - $option['print_value'] - ) ? $option['print_value'] : $this->filterManager->stripTags( - $option['value'] - ); - $values = explode(', ', $printValue); - foreach ($values as $value) { - foreach ($this->string->split($value, 50, true, true) as $subValue) { - $text[] = $subValue; - } + if ($options && isset($options['options'])) { + foreach ($options['options'] as $option) { + $lines = []; + $lines[][] = [ + 'text' => $this->string->split( + $this->filterManager->stripTags($option['label']), + 70, + true, + true + ), + 'font' => 'italic', + 'feed' => 60, + ]; + + if ($option['value']) { + $text = []; + $printValue = $option['print_value'] ?? $this->filterManager->stripTags($option['value']); + $values = explode(', ', $printValue); + foreach ($values as $value) { + foreach ($this->string->split($value, 50, true, true) as $subValue) { + $text[] = $subValue; } - - $lines[][] = ['text' => $text, 'feed' => 65]; } - $drawItems[] = ['lines' => $lines, 'height' => 15]; + $lines[][] = ['text' => $text, 'feed' => 65]; } + + $drawItems[] = ['lines' => $lines, 'height' => 15]; } } diff --git a/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php b/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php index 04a6ee0bd459b..3051394eaf512 100644 --- a/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php +++ b/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php @@ -3,14 +3,18 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Bundle\Pricing\Adjustment; +use Magento\Bundle\Model\Option; use Magento\Bundle\Model\Product\Price; use Magento\Bundle\Pricing\Price\BundleSelectionFactory; +use Magento\Bundle\Pricing\Price\BundleSelectionPrice; use Magento\Catalog\Model\Product; use Magento\Framework\Pricing\Adjustment\Calculator as CalculatorBase; use Magento\Framework\Pricing\Amount\AmountFactory; +use Magento\Framework\Pricing\Amount\AmountInterface; use Magento\Framework\Pricing\SaleableInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Store\Model\Store; @@ -51,7 +55,7 @@ class Calculator implements BundleCalculatorInterface protected $priceCurrency; /** - * @var \Magento\Framework\Pricing\Amount\AmountInterface[] + * @var AmountInterface[] */ private $optionAmount = []; @@ -66,7 +70,7 @@ class Calculator implements BundleCalculatorInterface * @param BundleSelectionFactory $bundleSelectionFactory * @param TaxHelper $taxHelper * @param PriceCurrencyInterface $priceCurrency - * @param SelectionPriceListProviderInterface|null $selectionPriceListProvider + * @param SelectionPriceListProviderInterface $selectionPriceListProvider */ public function __construct( CalculatorBase $calculator, @@ -74,7 +78,7 @@ public function __construct( BundleSelectionFactory $bundleSelectionFactory, TaxHelper $taxHelper, PriceCurrencyInterface $priceCurrency, - SelectionPriceListProviderInterface $selectionPriceListProvider = null + SelectionPriceListProviderInterface $selectionPriceListProvider ) { $this->calculator = $calculator; $this->amountFactory = $amountFactory; @@ -91,7 +95,9 @@ public function __construct( * @param SaleableInterface $saleableItem * @param null|bool|string|array $exclude * @param null|array $context - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * + * @return AmountInterface + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getAmount($amount, SaleableInterface $saleableItem, $exclude = null, $context = []) @@ -105,7 +111,8 @@ public function getAmount($amount, SaleableInterface $saleableItem, $exclude = n * @param float $amount * @param Product $saleableItem * @param null|bool|string|array $exclude - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * + * @return AmountInterface */ public function getMinRegularAmount($amount, Product $saleableItem, $exclude = null) { @@ -118,7 +125,8 @@ public function getMinRegularAmount($amount, Product $saleableItem, $exclude = n * @param float $amount * @param Product $saleableItem * @param null|bool|string|array $exclude - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * + * @return AmountInterface */ public function getMaxAmount($amount, Product $saleableItem, $exclude = null) { @@ -131,7 +139,8 @@ public function getMaxAmount($amount, Product $saleableItem, $exclude = null) * @param float $amount * @param Product $saleableItem * @param null|bool|string|array $exclude - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * + * @return AmountInterface */ public function getMaxRegularAmount($amount, Product $saleableItem, $exclude = null) { @@ -146,7 +155,8 @@ public function getMaxRegularAmount($amount, Product $saleableItem, $exclude = n * @param bool $searchMin * @param float $baseAmount * @param bool $useRegularPrice - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * + * @return AmountInterface */ public function getOptionsAmount( Product $saleableItem, @@ -173,7 +183,8 @@ public function getOptionsAmount( * * @param float $amount * @param Product $saleableItem - * @return \Magento\Framework\Pricing\Amount\AmountInterface|void + * + * @return AmountInterface|void */ public function getAmountWithoutOption($amount, Product $saleableItem) { @@ -194,29 +205,13 @@ public function getAmountWithoutOption($amount, Product $saleableItem) */ protected function getSelectionAmounts(Product $bundleProduct, $searchMin, $useRegularPrice = false) { - return $this->getSelectionPriceListProvider()->getPriceList($bundleProduct, $searchMin, $useRegularPrice); - } - - /** - * Get selection price list provider. - * - * @return SelectionPriceListProviderInterface - * @deprecated 100.2.0 - */ - private function getSelectionPriceListProvider() - { - if (null === $this->selectionPriceListProvider) { - $this->selectionPriceListProvider = \Magento\Framework\App\ObjectManager::getInstance() - ->get(SelectionPriceListProviderInterface::class); - } - - return $this->selectionPriceListProvider; + return $this->selectionPriceListProvider->getPriceList($bundleProduct, $searchMin, $useRegularPrice); } /** * Check this option if it should be skipped * - * @param \Magento\Bundle\Model\Option $option + * @param Option $option * @param bool $canSkipRequiredOption * @return bool * @deprecated 100.2.0 @@ -265,9 +260,9 @@ protected function getBundleOptions(Product $saleableItem) * * @param float $basePriceValue * @param Product $bundleProduct - * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList + * @param BundleSelectionPrice[] $selectionPriceList * @param null|bool|string|array $exclude - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @return AmountInterface */ public function calculateBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude = null) { @@ -282,14 +277,14 @@ public function calculateBundleAmount($basePriceValue, $bundleProduct, $selectio * * @param float $basePriceValue * @param Product $bundleProduct - * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList + * @param BundleSelectionPrice[] $selectionPriceList * @param null|bool|string|array $exclude - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @return AmountInterface */ protected function calculateFixedBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude) { $fullAmount = $basePriceValue; - /** @var $option \Magento\Bundle\Model\Option */ + /** @var $option Option */ foreach ($selectionPriceList as $selectionPrice) { $fullAmount += ($selectionPrice->getValue() * $selectionPrice->getQuantity()); } @@ -301,9 +296,9 @@ protected function calculateFixedBundleAmount($basePriceValue, $bundleProduct, $ * * @param float $basePriceValue * @param Product $bundleProduct - * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList + * @param BundleSelectionPrice[] $selectionPriceList * @param null|bool|string|array $exclude - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @return AmountInterface * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude) @@ -328,7 +323,7 @@ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $store = $bundleProduct->getStore(); $roundingMethod = $this->taxHelper->getCalculationAlgorithm($store); foreach ($amountList as $amountInfo) { - /** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */ + /** @var AmountInterface $itemAmount */ $itemAmount = $amountInfo['amount']; $qty = $amountInfo['quantity']; @@ -366,10 +361,10 @@ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, /** * Create selection price list for the retrieved options * - * @param \Magento\Bundle\Model\Option $option + * @param Option $option * @param Product $bundleProduct * @param bool $useRegularPrice - * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] + * @return BundleSelectionPrice[] */ public function createSelectionPriceList($option, $bundleProduct, $useRegularPrice = false) { @@ -399,10 +394,10 @@ public function createSelectionPriceList($option, $bundleProduct, $useRegularPri /** * Find minimal or maximal price for existing options * - * @param \Magento\Bundle\Model\Option $option - * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList + * @param Option $option + * @param BundleSelectionPrice[] $selectionPriceList * @param bool $searchMin - * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] + * @return BundleSelectionPrice[] * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function processOptions($option, $selectionPriceList, $searchMin = true) diff --git a/app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php b/app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php index 1c724caaa28d8..a76112da0ca4e 100644 --- a/app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php @@ -3,12 +3,17 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Bundle\Pricing\Price; +use Magento\Bundle\Model\ResourceModel\Option\Collection; +use Magento\Bundle\Model\Selection; use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface; use Magento\Catalog\Model\Product; +use Magento\Framework\Pricing\Amount\AmountInterface; use Magento\Framework\Pricing\Price\AbstractPrice; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\Pricing\PriceCurrencyInterface; /** * Bundle option price model with final price. @@ -25,12 +30,6 @@ class BundleOptionPrice extends AbstractPrice implements BundleOptionPriceInterf */ protected $calculator; - /** - * @var BundleSelectionFactory - * @deprecated - */ - protected $selectionFactory; - /** * @var float|bool|null */ @@ -45,26 +44,23 @@ class BundleOptionPrice extends AbstractPrice implements BundleOptionPriceInterf * @param Product $saleableItem * @param float $quantity * @param BundleCalculatorInterface $calculator - * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency - * @param BundleSelectionFactory $bundleSelectionFactory - * @param BundleOptions|null $bundleOptions + * @param PriceCurrencyInterface $priceCurrency + * @param BundleOptions $bundleOptions */ public function __construct( Product $saleableItem, $quantity, BundleCalculatorInterface $calculator, - \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, - BundleSelectionFactory $bundleSelectionFactory, - BundleOptions $bundleOptions = null + PriceCurrencyInterface $priceCurrency, + BundleOptions $bundleOptions ) { - $this->selectionFactory = $bundleSelectionFactory; parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); $this->product->setQty($this->quantity); - $this->bundleOptions = $bundleOptions ?: ObjectManager::getInstance()->get(BundleOptions::class); + $this->bundleOptions = $bundleOptions; } /** - * {@inheritdoc} + * @inheritDoc */ public function getValue() { @@ -75,25 +71,10 @@ public function getValue() return $this->value; } - /** - * Getter for maximal price of options. - * - * @return bool|float - * @deprecated - */ - public function getMaxValue() - { - if (null === $this->maximalPrice) { - $this->maximalPrice = $this->bundleOptions->calculateOptions($this->product, false); - } - - return $this->maximalPrice; - } - /** * Get Options with attached Selections collection. * - * @return \Magento\Bundle\Model\ResourceModel\Option\Collection + * @return Collection */ public function getOptions() { @@ -103,8 +84,9 @@ public function getOptions() /** * Get selection amount. * - * @param \Magento\Bundle\Model\Selection $selection - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @param Selection $selection + * + * @return AmountInterface */ public function getOptionSelectionAmount($selection) { @@ -119,6 +101,7 @@ public function getOptionSelectionAmount($selection) * Calculate maximal or minimal options value. * * @param bool $searchMin + * * @return bool|float */ protected function calculateOptions($searchMin = true) @@ -129,7 +112,7 @@ protected function calculateOptions($searchMin = true) /** * Get minimal amount of bundle price with options * - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @return AmountInterface */ public function getAmount() { diff --git a/app/code/Magento/Bundle/Pricing/Price/FinalPrice.php b/app/code/Magento/Bundle/Pricing/Price/FinalPrice.php index c41f6a4868ab1..66f618c0fcfa5 100644 --- a/app/code/Magento/Bundle/Pricing/Price/FinalPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/FinalPrice.php @@ -3,15 +3,17 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Bundle\Pricing\Price; -use Magento\Catalog\Model\Product; -use Magento\Framework\Pricing\Adjustment\CalculatorInterface; -use Magento\Catalog\Pricing\Price\CustomOptionPrice; use Magento\Bundle\Model\Product\Price; -use Magento\Framework\App\ObjectManager; use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Pricing\Price\CustomOptionPrice; +use Magento\Framework\Pricing\Adjustment\CalculatorInterface; +use Magento\Framework\Pricing\Amount\AmountInterface; +use Magento\Framework\Pricing\PriceCurrencyInterface; /** * Final price model @@ -19,27 +21,27 @@ class FinalPrice extends \Magento\Catalog\Pricing\Price\FinalPrice implements FinalPriceInterface { /** - * @var \Magento\Framework\Pricing\Amount\AmountInterface + * @var AmountInterface */ protected $maximalPrice; /** - * @var \Magento\Framework\Pricing\Amount\AmountInterface + * @var AmountInterface */ protected $minimalPrice; /** - * @var \Magento\Framework\Pricing\Amount\AmountInterface + * @var AmountInterface */ protected $priceWithoutOption; /** - * @var \Magento\Bundle\Pricing\Price\BundleOptionPrice + * @var BundleOptionPrice */ protected $bundleOptionPrice; /** - * @var \Magento\Catalog\Api\ProductCustomOptionRepositoryInterface + * @var ProductCustomOptionRepositoryInterface */ private $productOptionRepository; @@ -47,15 +49,18 @@ class FinalPrice extends \Magento\Catalog\Pricing\Price\FinalPrice implements Fi * @param Product $saleableItem * @param float $quantity * @param CalculatorInterface $calculator - * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency + * @param PriceCurrencyInterface $priceCurrency + * @param ProductCustomOptionRepositoryInterface $productOptionRepository */ public function __construct( Product $saleableItem, $quantity, CalculatorInterface $calculator, - \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency + PriceCurrencyInterface $priceCurrency, + ProductCustomOptionRepositoryInterface $productOptionRepository ) { parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); + $this->productOptionRepository = $productOptionRepository; } /** @@ -65,49 +70,33 @@ public function __construct( */ public function getValue() { - return parent::getValue() + - $this->getBundleOptionPrice()->getValue(); + return parent::getValue() + $this->getBundleOptionPrice()->getValue(); } /** * Returns max price * - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @return AmountInterface */ public function getMaximalPrice() { if (!$this->maximalPrice) { $price = $this->getBasePrice()->getValue(); if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) { - /** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */ + /** @var CustomOptionPrice $customOptionPrice */ $customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE); $price += $customOptionPrice->getCustomOptionRange(false); } $this->maximalPrice = $this->calculator->getMaxAmount($price, $this->product); } - return $this->maximalPrice; - } - /** - * Return ProductCustomOptionRepository - * - * @return ProductCustomOptionRepositoryInterface - * @deprecated 100.1.0 - */ - private function getProductOptionRepository() - { - if (!$this->productOptionRepository) { - $this->productOptionRepository = ObjectManager::getInstance()->get( - ProductCustomOptionRepositoryInterface::class - ); - } - return $this->productOptionRepository; + return $this->maximalPrice; } /** * Returns min price * - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @return AmountInterface */ public function getMinimalPrice() { @@ -117,7 +106,7 @@ public function getMinimalPrice() /** * Returns price amount * - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @return AmountInterface */ public function getAmount() { @@ -125,7 +114,7 @@ public function getAmount() $price = parent::getValue(); if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) { $this->loadProductCustomOptions(); - /** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */ + /** @var CustomOptionPrice $customOptionPrice */ $customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE); $price += $customOptionPrice->getCustomOptionRange(true); } @@ -143,7 +132,7 @@ private function loadProductCustomOptions() { if (!$this->product->getOptions()) { $options = []; - foreach ($this->getProductOptionRepository()->getProductOptions($this->product) as $option) { + foreach ($this->productOptionRepository->getProductOptions($this->product) as $option) { $option->setProduct($this->product); $options[] = $option; } @@ -152,9 +141,9 @@ private function loadProductCustomOptions() } /** - * get bundle product price without any option + * Get bundle product price without any option * - * @return \Magento\Framework\Pricing\Amount\AmountInterface + * @return AmountInterface */ public function getPriceWithoutOption() { @@ -167,7 +156,7 @@ public function getPriceWithoutOption() /** * Returns option price * - * @return \Magento\Bundle\Pricing\Price\BundleOptionPrice + * @return BundleOptionPrice */ protected function getBundleOptionPrice() { diff --git a/app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php b/app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php index ccc8c52d5022f..b31b82a6a72bf 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php @@ -7,174 +7,198 @@ namespace Magento\Bundle\Test\Unit\Model; +use Exception; +use Magento\Bundle\Api\Data\LinkInterface; +use Magento\Bundle\Api\Data\LinkInterfaceFactory; use Magento\Bundle\Model\LinkManagement; +use Magento\Bundle\Model\Option; +use Magento\Bundle\Model\ResourceModel\Bundle; +use Magento\Bundle\Model\ResourceModel\BundleFactory; +use Magento\Bundle\Model\ResourceModel\Option\Collection as OptionCollection; +use Magento\Bundle\Model\ResourceModel\Option\CollectionFactory as OptionCollectionFactory; +use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection; +use Magento\Bundle\Model\Selection; +use Magento\Bundle\Model\SelectionFactory; +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Type; +use Magento\Catalog\Model\ProductRepository; +use Magento\Framework\Api\DataObjectHelper; +use Magento\Framework\EntityManager\EntityMetadata; +use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManagerInterface; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** - * Class LinkManagementTest + * Test class for \Magento\Bundle\Model\LinkManagement * * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class LinkManagementTest extends \PHPUnit\Framework\TestCase +class LinkManagementTest extends TestCase { /** - * @var \Magento\Bundle\Model\LinkManagement + * @var LinkManagement */ - protected $model; + private $model; /** - * @var \Magento\Catalog\Model\ProductRepository|\PHPUnit_Framework_MockObject_MockObject + * @var ProductRepository|MockObject */ - protected $productRepository; + private $productRepository; /** - * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject + * @var Product|MockObject */ - protected $product; + private $product; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var LinkInterfaceFactory|MockObject */ - protected $linkFactory; + private $linkFactory; /** - * @var \Magento\Catalog\Model\Product\Type\Interceptor|\PHPUnit_Framework_MockObject_MockObject + * @var Type|MockObject */ - protected $productType; + private $productType; /** - * @var \Magento\Bundle\Model\ResourceModel\Option\Collection|\PHPUnit_Framework_MockObject_MockObject + * @var OptionCollection|MockObject */ - protected $optionCollection; + private $optionCollection; /** - * @var \Magento\Bundle\Model\ResourceModel\Selection\Collection|\PHPUnit_Framework_MockObject_MockObject + * @var SelectionCollection|MockObject */ - protected $selectionCollection; + private $selectionCollection; /** - * @var \Magento\Bundle\Model\Option|\PHPUnit_Framework_MockObject_MockObject + * @var Option|MockObject */ - protected $option; + private $option; /** - * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Bundle\Model\SelectionFactory + * @var SelectionFactory|MockObject */ - protected $bundleSelectionMock; + private $bundleSelectionMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Bundle\Model\ResourceModel\BundleFactory + * @var BundleFactory|MockObject */ - protected $bundleFactoryMock; + private $bundleFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory + * @var OptionCollectionFactory|MockObject */ - protected $optionCollectionFactoryMock; + private $optionCollectionFactoryMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface|MockObject */ - protected $storeManagerMock; + private $storeManagerMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var LinkInterface|MockObject */ - protected $link; + private $link; /** - * @var int + * @var MockObject */ - protected $storeId = 2; + private $dataObjectHelperMock; /** - * @var array + * @var MetadataPool|MockObject */ - protected $optionIds = [1, 2, 3]; + private $metadataPoolMock; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var EntityMetadata|MockObject */ - protected $dataObjectHelperMock; + private $metadataMock; /** - * @var \Magento\Framework\EntityManager\MetadataPool|\PHPUnit_Framework_MockObject_MockObject + * @var int */ - protected $metadataPoolMock; + private $storeId = 2; /** - * @var \Magento\Framework\EntityManager\EntityMetadata|\PHPUnit_Framework_MockObject_MockObject + * @var array */ - protected $metadataMock; + private $optionIds = [1, 2, 3]; /** * @var string */ - protected $linkField = 'product_id'; + private $linkField = 'product_id'; + /** + * @inheritDoc + */ protected function setUp() { $helper = new ObjectManager($this); - $this->productRepository = $this->getMockBuilder(\Magento\Catalog\Model\ProductRepository::class) + $this->productRepository = $this->getMockBuilder(ProductRepository::class) ->setMethods(['get']) ->disableOriginalConstructor() ->getMock(); - $this->productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type\Interceptor::class) + $this->productType = $this->getMockBuilder(\Magento\Bundle\Model\Product\Type::class) ->setMethods(['getOptionsCollection', 'setStoreFilter', 'getSelectionsCollection', 'getOptionsIds']) ->disableOriginalConstructor() ->getMock(); - $this->option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class) + $this->option = $this->getMockBuilder(Option::class) ->setMethods(['getSelections', 'getOptionId', '__wakeup']) ->disableOriginalConstructor() ->getMock(); - $this->optionCollection = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class) + $this->optionCollection = $this->getMockBuilder(OptionCollection::class) ->setMethods(['appendSelections']) ->disableOriginalConstructor() ->getMock(); $this->selectionCollection = $this->getMockBuilder( - \Magento\Bundle\Model\ResourceModel\Selection\Collection::class + SelectionCollection::class )->disableOriginalConstructor()->getMock(); - $this->product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + $this->product = $this->getMockBuilder(Product::class) ->setMethods(['getTypeInstance', 'getStoreId', 'getTypeId', '__wakeup', 'getId', 'getData']) ->disableOriginalConstructor() ->getMock(); - $this->link = $this->getMockBuilder(\Magento\Bundle\Api\Data\LinkInterface::class) + $this->link = $this->getMockBuilder(LinkInterface::class) ->disableOriginalConstructor() ->getMock(); - $this->linkFactory = $this->getMockBuilder(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class) + $this->linkFactory = $this->getMockBuilder(LinkInterfaceFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->bundleSelectionMock = $this->createPartialMock( - \Magento\Bundle\Model\SelectionFactory::class, + SelectionFactory::class, ['create'] ); $this->bundleFactoryMock = $this->createPartialMock( - \Magento\Bundle\Model\ResourceModel\BundleFactory::class, + BundleFactory::class, ['create'] ); $this->optionCollectionFactoryMock = $this->createPartialMock( - \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory::class, + OptionCollectionFactory::class, ['create'] ); - $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); - $this->metadataPoolMock = $this->getMockBuilder(\Magento\Framework\EntityManager\MetadataPool::class) + $this->storeManagerMock = $this->createMock(StoreManagerInterface::class); + $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class) ->disableOriginalConstructor() ->getMock(); - $this->metadataMock = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadata::class) + $this->metadataMock = $this->getMockBuilder(EntityMetadata::class) ->disableOriginalConstructor() ->getMock(); - $this->metadataPoolMock->expects($this->any())->method('getMetadata') - ->with(\Magento\Catalog\Api\Data\ProductInterface::class) + $this->metadataPoolMock->method('getMetadata') + ->with(ProductInterface::class) ->willReturn($this->metadataMock); - $this->dataObjectHelperMock = $this->getMockBuilder(\Magento\Framework\Api\DataObjectHelper::class) + $this->dataObjectHelperMock = $this->getMockBuilder(DataObjectHelper::class) ->disableOriginalConstructor() ->getMock(); $this->model = $helper->getObject( - LinkManagement::class, [ 'productRepository' => $this->productRepository, @@ -184,12 +208,9 @@ protected function setUp() 'optionCollection' => $this->optionCollectionFactoryMock, 'storeManager' => $this->storeManagerMock, 'dataObjectHelper' => $this->dataObjectHelperMock, + 'metadataPool' => $this->metadataPoolMock ] ); - $refClass = new \ReflectionClass(LinkManagement::class); - $refProperty = $refClass->getProperty('metadataPool'); - $refProperty->setAccessible(true); - $refProperty->setValue($this->model, $this->metadataPoolMock); } public function testGetChildren() @@ -198,31 +219,45 @@ public function testGetChildren() $this->getOptions(); - $this->productRepository->expects($this->any())->method('get')->with($this->equalTo($productSku)) - ->will($this->returnValue($this->product)); + $this->productRepository->method('get') + ->with($this->equalTo($productSku)) + ->willReturn($this->product); - $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('bundle')); + $this->product->expects($this->once()) + ->method('getTypeId') + ->willReturn('bundle'); - $this->productType->expects($this->once())->method('setStoreFilter')->with( - $this->equalTo($this->storeId), - $this->product - ); - $this->productType->expects($this->once())->method('getSelectionsCollection') - ->with($this->equalTo($this->optionIds), $this->equalTo($this->product)) - ->will($this->returnValue($this->selectionCollection)); - $this->productType->expects($this->once())->method('getOptionsIds')->with($this->equalTo($this->product)) - ->will($this->returnValue($this->optionIds)); + $this->productType->expects($this->once()) + ->method('setStoreFilter') + ->with( + $this->equalTo($this->storeId), + $this->product + ); + $this->productType->expects($this->once()) + ->method('getSelectionsCollection') + ->with( + $this->equalTo($this->optionIds), + $this->equalTo($this->product) + ) + ->willReturn($this->selectionCollection); + $this->productType->expects($this->once()) + ->method('getOptionsIds') + ->with($this->equalTo($this->product)) + ->willReturn($this->optionIds); - $this->optionCollection->expects($this->once())->method('appendSelections') + $this->optionCollection->expects($this->once()) + ->method('appendSelections') ->with($this->equalTo($this->selectionCollection)) - ->will($this->returnValue([$this->option])); + ->willReturn([$this->option]); - $this->option->expects($this->any())->method('getSelections')->willReturn([$this->product]); - $this->product->expects($this->any())->method('getData')->willReturn([]); + $this->option->method('getSelections') + ->willReturn([$this->product]); + $this->product->method('getData') + ->willReturn([]); $this->dataObjectHelperMock->expects($this->once()) ->method('populateWithArray') - ->with($this->link, $this->anything(), \Magento\Bundle\Api\Data\LinkInterface::class) + ->with($this->link, $this->anything(), LinkInterface::class) ->willReturnSelf(); $this->link->expects($this->once())->method('setIsDefault')->willReturnSelf(); $this->link->expects($this->once())->method('setQty')->willReturnSelf(); @@ -241,27 +276,42 @@ public function testGetChildrenWithOptionId() $this->getOptions(); - $this->productRepository->expects($this->any())->method('get')->with($this->equalTo($productSku)) - ->will($this->returnValue($this->product)); + $this->productRepository->method('get') + ->with($this->equalTo($productSku)) + ->willReturn($this->product); - $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('bundle')); + $this->product->expects($this->once()) + ->method('getTypeId') + ->willReturn('bundle'); - $this->productType->expects($this->once())->method('setStoreFilter')->with( - $this->equalTo($this->storeId), - $this->product - ); - $this->productType->expects($this->once())->method('getSelectionsCollection') - ->with($this->equalTo($this->optionIds), $this->equalTo($this->product)) - ->will($this->returnValue($this->selectionCollection)); - $this->productType->expects($this->once())->method('getOptionsIds')->with($this->equalTo($this->product)) - ->will($this->returnValue($this->optionIds)); + $this->productType->expects($this->once()) + ->method('setStoreFilter') + ->with( + $this->equalTo($this->storeId), + $this->product + ); + $this->productType->expects($this->once()) + ->method('getSelectionsCollection') + ->with( + $this->equalTo($this->optionIds), + $this->equalTo($this->product) + ) + ->willReturn($this->selectionCollection); + $this->productType->expects($this->once()) + ->method('getOptionsIds') + ->with($this->equalTo($this->product)) + ->willReturn($this->optionIds); - $this->optionCollection->expects($this->once())->method('appendSelections') + $this->optionCollection->expects($this->once()) + ->method('appendSelections') ->with($this->equalTo($this->selectionCollection)) - ->will($this->returnValue([$this->option])); + ->willReturn([$this->option]); - $this->option->expects($this->any())->method('getOptionId')->will($this->returnValue(10)); - $this->option->expects($this->once())->method('getSelections')->willReturn([1, 2]); + $this->option->method('getOptionId') + ->willReturn(10); + $this->option->expects($this->once()) + ->method('getSelections') + ->willReturn([1, 2]); $this->dataObjectHelperMock->expects($this->never())->method('populateWithArray'); @@ -275,10 +325,14 @@ public function testGetChildrenException() { $productSku = 'productSku'; - $this->productRepository->expects($this->once())->method('get')->with($this->equalTo($productSku)) - ->will($this->returnValue($this->product)); + $this->productRepository->expects($this->once()) + ->method('get') + ->with($this->equalTo($productSku)) + ->willReturn($this->product); - $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('simple')); + $this->product->expects($this->once()) + ->method('getTypeId') + ->willReturn('simple'); $this->assertEquals([$this->link], $this->model->getChildren($productSku)); } @@ -288,13 +342,14 @@ public function testGetChildrenException() */ public function testAddChildToNotBundleProduct() { - $productLink = $this->createMock(\Magento\Bundle\Api\Data\LinkInterface::class); - $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue(1)); + $productLink = $this->createMock(LinkInterface::class); + $productLink->method('getOptionId') + ->willReturn(1); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE - )); + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once()) + ->method('getTypeId') + ->willReturn(Type::TYPE_SIMPLE); $this->model->addChild($productMock, 1, $productLink); } @@ -303,37 +358,35 @@ public function testAddChildToNotBundleProduct() */ public function testAddChildNonExistingOption() { - $productLink = $this->createMock(\Magento\Bundle\Api\Data\LinkInterface::class); - $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue(1)); + $productLink = $this->createMock(LinkInterface::class); + $productLink->method('getOptionId')->willReturn(1); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once())->method('getTypeId')->willReturn(Type::TYPE_BUNDLE); - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); - $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + $store = $this->createMock(Store::class); + $this->storeManagerMock->method('getStore')->willReturn($store); + $store->method('getId')->willReturn(0); - $emptyOption = $this->getMockBuilder(\Magento\Bundle\Model\Option::class)->disableOriginalConstructor() + $emptyOption = $this->getMockBuilder(Option::class)->disableOriginalConstructor() ->setMethods(['getId', '__wakeup']) ->getMock(); $emptyOption->expects($this->once()) ->method('getId') - ->will($this->returnValue(null)); + ->willReturn(null); - $optionsCollectionMock = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class); + $optionsCollectionMock = $this->createMock(OptionCollection::class); $optionsCollectionMock->expects($this->once()) ->method('setIdFilter') ->with($this->equalTo(1)) - ->will($this->returnSelf()); + ->willReturnSelf(); $optionsCollectionMock->expects($this->once()) ->method('getFirstItem') - ->will($this->returnValue($emptyOption)); + ->willReturn($emptyOption); - $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( - $this->returnValue($optionsCollectionMock) - ); + $this->optionCollectionFactoryMock + ->method('create') + ->willReturn($optionsCollectionMock); $this->model->addChild($productMock, 1, $productLink); } @@ -343,53 +396,55 @@ public function testAddChildNonExistingOption() */ public function testAddChildLinkedProductIsComposite() { - $productLink = $this->createMock(\Magento\Bundle\Api\Data\LinkInterface::class); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); - $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue(1)); + $productLink = $this->createMock(LinkInterface::class); + $productLink->method('getSku')->willReturn('linked_product_sku'); + $productLink->method('getOptionId')->willReturn(1); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); - $productMock->expects($this->any()) - ->method('getData') + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once()) + ->method('getTypeId') + ->willReturn(Type::TYPE_BUNDLE); + $productMock->method('getData') ->with($this->linkField) ->willReturn($this->linkField); - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->any())->method('getId')->will($this->returnValue(13)); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(true)); - $this->productRepository - ->expects($this->once()) + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->method('getId')->willReturn(13); + $linkedProductMock->expects($this->once()) + ->method('isComposite') + ->willReturn(true); + $this->productRepository->expects($this->once()) ->method('get') ->with('linked_product_sku') - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); - $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + $store = $this->createMock(Store::class); + $this->storeManagerMock + ->method('getStore') + ->willReturn($store); + $store->method('getId') + ->willReturn(0); - $option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class)->disableOriginalConstructor() + $option = $this->getMockBuilder(Option::class)->disableOriginalConstructor() ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getId')->will($this->returnValue(1)); + $option->expects($this->once())->method('getId')->willReturn(1); - $optionsCollectionMock = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class); + $optionsCollectionMock = $this->createMock(OptionCollection::class); $optionsCollectionMock->expects($this->once()) ->method('setIdFilter') ->with($this->equalTo('1')) - ->will($this->returnSelf()); + ->willReturnSelf(); $optionsCollectionMock->expects($this->once()) ->method('getFirstItem') - ->will($this->returnValue($option)); - $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( - $this->returnValue($optionsCollectionMock) - ); + ->willReturn($option); + $this->optionCollectionFactoryMock->method('create') + ->willReturn($optionsCollectionMock); - $bundle = $this->createMock(\Magento\Bundle\Model\ResourceModel\Bundle::class); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->once())->method('getSelectionsData')->with($this->linkField)->willReturn([]); - $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle)); + $this->bundleFactoryMock->expects($this->once())->method('create')->willReturn($bundle); $this->model->addChild($productMock, 1, $productLink); } @@ -398,68 +453,74 @@ public function testAddChildLinkedProductIsComposite() */ public function testAddChildProductAlreadyExistsInOption() { - $productLink = $this->getMockBuilder(\Magento\Bundle\Api\Data\LinkInterface::class) + $productLink = $this->getMockBuilder(LinkInterface::class) ->setMethods(['getSku', 'getOptionId', 'getSelectionId']) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); - $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue(1)); - $productLink->expects($this->any())->method('getSelectionId')->will($this->returnValue(1)); + $productLink->method('getSku')->willReturn('linked_product_sku'); + $productLink->method('getOptionId')->willReturn(1); + $productLink->method('getSelectionId')->willReturn(1); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField); $productMock = $this->createPartialMock( - \Magento\Catalog\Model\Product::class, + Product::class, ['getTypeId', 'getCopyFromView', 'getData', 'getTypeInstance', 'getSku'] ); $productMock->expects($this->once())->method('getTypeId')->willReturn( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE + Type::TYPE_BUNDLE ); - $productMock->expects($this->any()) - ->method('getData') + $productMock->method('getData') ->with($this->linkField) ->willReturn($this->linkField); - $productMock->expects($this->any())->method('getCopyFromView')->will($this->returnValue(false)); - - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->any())->method('getEntityId')->will($this->returnValue(13)); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); - $this->productRepository - ->expects($this->once()) + $productMock->method('getCopyFromView') + ->willReturn(false); + + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->method('getEntityId') + ->willReturn(13); + $linkedProductMock->expects($this->once()) + ->method('isComposite') + ->willReturn(false); + $this->productRepository->expects($this->once()) ->method('get') ->with('linked_product_sku') - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); - $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + $store = $this->createMock(Store::class); + $this->storeManagerMock->method('getStore')->willReturn($store); + $store->method('getId')->willReturn(0); - $option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class)->disableOriginalConstructor() + $option = $this->getMockBuilder(Option::class)->disableOriginalConstructor() ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getId')->will($this->returnValue(1)); + $option->expects($this->once()) + ->method('getId') + ->willReturn(1); - $optionsCollectionMock = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class); + $optionsCollectionMock = $this->createMock(OptionCollection::class); $optionsCollectionMock->expects($this->once()) ->method('setIdFilter') ->with($this->equalTo(1)) - ->will($this->returnSelf()); + ->willReturnSelf(); $optionsCollectionMock->expects($this->once()) ->method('getFirstItem') - ->will($this->returnValue($option)); - $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( - $this->returnValue($optionsCollectionMock) - ); + ->willReturn($option); + $this->optionCollectionFactoryMock->method('create') + ->willReturn($optionsCollectionMock); $selections = [ ['option_id' => 1, 'product_id' => 12, 'parent_product_id' => 'product_id'], ['option_id' => 1, 'product_id' => 13, 'parent_product_id' => 'product_id'], ]; - $bundle = $this->createMock(\Magento\Bundle\Model\ResourceModel\Bundle::class); - $bundle->expects($this->once())->method('getSelectionsData') + $bundle = $this->createMock(Bundle::class); + $bundle->expects($this->once()) + ->method('getSelectionsData') ->with($this->linkField) - ->will($this->returnValue($selections)); - $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle)); + ->willReturn($selections); + $this->bundleFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($bundle); $this->model->addChild($productMock, 1, $productLink); } @@ -468,141 +529,141 @@ public function testAddChildProductAlreadyExistsInOption() */ public function testAddChildCouldNotSave() { - $productLink = $this->getMockBuilder(\Magento\Bundle\Api\Data\LinkInterface::class) + $productLink = $this->getMockBuilder(LinkInterface::class) ->setMethods(['getSku', 'getOptionId', 'getSelectionId']) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); - $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue(1)); - $productLink->expects($this->any())->method('getSelectionId')->will($this->returnValue(1)); + $productLink->method('getSku')->willReturn('linked_product_sku'); + $productLink->method('getOptionId')->willReturn(1); + $productLink->method('getSelectionId')->willReturn(1); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); - $productMock->expects($this->any()) + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once()) + ->method('getTypeId') + ->willReturn(Type::TYPE_BUNDLE); + $productMock ->method('getData') ->with($this->linkField) ->willReturn($this->linkField); - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->any())->method('getId')->will($this->returnValue(13)); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->method('getId')->willReturn(13); + $linkedProductMock->expects($this->once()) + ->method('isComposite') + ->willReturn(false); $this->productRepository ->expects($this->once()) ->method('get') ->with('linked_product_sku') - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); - $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + $store = $this->createMock(Store::class); + $this->storeManagerMock->method('getStore')->willReturn($store); + $store->method('getId')->willReturn(0); - $option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class)->disableOriginalConstructor() + $option = $this->getMockBuilder(Option::class)->disableOriginalConstructor() ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getId')->will($this->returnValue(1)); + $option->expects($this->once())->method('getId')->willReturn(1); - $optionsCollectionMock = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class); + $optionsCollectionMock = $this->createMock(OptionCollection::class); $optionsCollectionMock->expects($this->once()) ->method('setIdFilter') ->with($this->equalTo(1)) - ->will($this->returnSelf()); + ->willReturnSelf(); $optionsCollectionMock->expects($this->once()) ->method('getFirstItem') - ->will($this->returnValue($option)); - $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( - $this->returnValue($optionsCollectionMock) - ); + ->willReturn($option); + $this->optionCollectionFactoryMock->method('create') + ->willReturn($optionsCollectionMock); $selections = [ ['option_id' => 1, 'product_id' => 11], ['option_id' => 1, 'product_id' => 12], ]; - $bundle = $this->createMock(\Magento\Bundle\Model\ResourceModel\Bundle::class); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->once())->method('getSelectionsData') ->with($this->linkField) - ->will($this->returnValue($selections)); - $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle)); + ->willReturn($selections); + $this->bundleFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($bundle); - $selection = $this->createPartialMock(\Magento\Bundle\Model\Selection::class, ['save']); + $selection = $this->createPartialMock(Selection::class, ['save']); $selection->expects($this->once())->method('save') - ->will( - $this->returnCallback( - function () { - throw new \Exception('message'); - } - ) + ->willReturnCallback( + static function () { + throw new Exception('message'); + } ); - $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); + $this->bundleSelectionMock->expects($this->once()) + ->method('create') + ->willReturn($selection); $this->model->addChild($productMock, 1, $productLink); } public function testAddChild() { - $productLink = $this->getMockBuilder(\Magento\Bundle\Api\Data\LinkInterface::class) + $productLink = $this->getMockBuilder(LinkInterface::class) ->setMethods(['getSku', 'getOptionId', 'getSelectionId']) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); - $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue(1)); - $productLink->expects($this->any())->method('getSelectionId')->will($this->returnValue(1)); + $productLink->method('getSku')->willReturn('linked_product_sku'); + $productLink->method('getOptionId')->willReturn(1); + $productLink->method('getSelectionId')->willReturn(1); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); - $productMock->expects($this->any()) + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once())->method('getTypeId')->willReturn(Type::TYPE_BUNDLE); + $productMock ->method('getData') ->with($this->linkField) ->willReturn($this->linkField); - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->any())->method('getId')->will($this->returnValue(13)); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->method('getId')->willReturn(13); + $linkedProductMock->expects($this->once())->method('isComposite')->willReturn(false); $this->productRepository ->expects($this->once()) ->method('get') ->with('linked_product_sku') - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); - $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + $store = $this->createMock(Store::class); + $this->storeManagerMock->method('getStore')->willReturn($store); + $store->method('getId')->willReturn(0); - $option = $this->getMockBuilder(\Magento\Bundle\Model\Option::class)->disableOriginalConstructor() + $option = $this->getMockBuilder(Option::class)->disableOriginalConstructor() ->setMethods(['getId', '__wakeup']) ->getMock(); - $option->expects($this->once())->method('getId')->will($this->returnValue(1)); + $option->expects($this->once())->method('getId')->willReturn(1); - $optionsCollectionMock = $this->createMock(\Magento\Bundle\Model\ResourceModel\Option\Collection::class); + $optionsCollectionMock = $this->createMock(OptionCollection::class); $optionsCollectionMock->expects($this->once()) ->method('setIdFilter') ->with($this->equalTo(1)) - ->will($this->returnSelf()); + ->willReturnSelf(); $optionsCollectionMock->expects($this->once()) ->method('getFirstItem') - ->will($this->returnValue($option)); - $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will( - $this->returnValue($optionsCollectionMock) - ); + ->willReturn($option); + $this->optionCollectionFactoryMock->method('create') + ->willReturn($optionsCollectionMock); $selections = [ ['option_id' => 1, 'product_id' => 11], ['option_id' => 1, 'product_id' => 12], ]; - $bundle = $this->createMock(\Magento\Bundle\Model\ResourceModel\Bundle::class); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->once())->method('getSelectionsData') ->with($this->linkField) - ->will($this->returnValue($selections)); - $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle)); + ->willReturn($selections); + $this->bundleFactoryMock->expects($this->once())->method('create')->willReturn($bundle); - $selection = $this->createPartialMock(\Magento\Bundle\Model\Selection::class, ['save', 'getId']); + $selection = $this->createPartialMock(Selection::class, ['save', 'getId']); $selection->expects($this->once())->method('save'); - $selection->expects($this->once())->method('getId')->will($this->returnValue(42)); - $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); + $selection->expects($this->once())->method('getId')->willReturn(42); + $this->bundleSelectionMock->expects($this->once())->method('create')->willReturn($selection); $result = $this->model->addChild($productMock, 1, $productLink); $this->assertEquals(42, $result); } @@ -621,51 +682,51 @@ public function testSaveChild() $parentProductId = 32; $bundleProductSku = 'bundleProductSku'; - $productLink = $this->getMockBuilder(\Magento\Bundle\Api\Data\LinkInterface::class) + $productLink = $this->getMockBuilder(LinkInterface::class) ->setMethods(['getSku', 'getOptionId', 'getSelectionId']) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); - $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); - $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId)); - $productLink->expects($this->any())->method('getPosition')->will($this->returnValue($position)); - $productLink->expects($this->any())->method('getQty')->will($this->returnValue($qty)); - $productLink->expects($this->any())->method('getPriceType')->will($this->returnValue($priceType)); - $productLink->expects($this->any())->method('getPrice')->will($this->returnValue($price)); - $productLink->expects($this->any())->method('getCanChangeQuantity') - ->will($this->returnValue($canChangeQuantity)); - $productLink->expects($this->any())->method('getIsDefault')->will($this->returnValue($isDefault)); - $productLink->expects($this->any())->method('getSelectionId')->will($this->returnValue($optionId)); + $productLink->method('getSku')->willReturn('linked_product_sku'); + $productLink->method('getId')->willReturn($id); + $productLink->method('getOptionId')->willReturn($optionId); + $productLink->method('getPosition')->willReturn($position); + $productLink->method('getQty')->willReturn($qty); + $productLink->method('getPriceType')->willReturn($priceType); + $productLink->method('getPrice')->willReturn($price); + $productLink->method('getCanChangeQuantity') + ->willReturn($canChangeQuantity); + $productLink->method('getIsDefault')->willReturn($isDefault); + $productLink->method('getSelectionId')->willReturn($optionId); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); - $productMock->expects($this->any()) + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once())->method('getTypeId')->willReturn(Type::TYPE_BUNDLE); + $productMock ->method('getData') ->with($this->linkField) ->willReturn($parentProductId); - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->any())->method('getId')->will($this->returnValue($linkProductId)); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->method('getId')->willReturn($linkProductId); + $linkedProductMock->expects($this->once())->method('isComposite')->willReturn(false); $this->productRepository ->expects($this->at(0)) ->method('get') ->with($bundleProductSku) - ->will($this->returnValue($productMock)); + ->willReturn($productMock); $this->productRepository ->expects($this->at(1)) ->method('get') ->with('linked_product_sku') - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); - $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + $store = $this->createMock(Store::class); + $this->storeManagerMock->method('getStore')->willReturn($store); + $store->method('getId')->willReturn(0); - $selection = $this->createPartialMock(\Magento\Bundle\Model\Selection::class, [ + $selection = $this->createPartialMock( + Selection::class, + [ 'save', 'getId', 'load', @@ -678,10 +739,11 @@ public function testSaveChild() 'setSelectionPriceValue', 'setSelectionCanChangeQty', 'setIsDefault' - ]); + ] + ); $selection->expects($this->once())->method('save'); - $selection->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); - $selection->expects($this->any())->method('getId')->will($this->returnValue($id)); + $selection->expects($this->once())->method('load')->with($id)->willReturnSelf(); + $selection->method('getId')->willReturn($id); $selection->expects($this->once())->method('setProductId')->with($linkProductId); $selection->expects($this->once())->method('setParentProductId')->with($parentProductId); $selection->expects($this->once())->method('setOptionId')->with($optionId); @@ -692,7 +754,7 @@ public function testSaveChild() $selection->expects($this->once())->method('setSelectionCanChangeQty')->with($canChangeQuantity); $selection->expects($this->once())->method('setIsDefault')->with($isDefault); - $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); + $this->bundleSelectionMock->expects($this->once())->method('create')->willReturn($selection); $this->assertTrue($this->model->saveChild($bundleProductSku, $productLink)); } @@ -705,40 +767,45 @@ public function testSaveChildFailedToSave() $linkProductId = 45; $parentProductId = 32; - $productLink = $this->getMockBuilder(\Magento\Bundle\Api\Data\LinkInterface::class) + $productLink = $this->getMockBuilder(LinkInterface::class) ->setMethods(['getSku', 'getOptionId', 'getSelectionId']) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); - $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); - $productLink->expects($this->any())->method('getSelectionId')->will($this->returnValue(1)); + $productLink->method('getSku')->willReturn('linked_product_sku'); + $productLink->method('getId')->willReturn($id); + $productLink->method('getSelectionId')->willReturn(1); $bundleProductSku = 'bundleProductSku'; - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); - $productMock->expects($this->any())->method('getId')->will($this->returnValue($parentProductId)); + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once()) + ->method('getTypeId') + ->willReturn(Type::TYPE_BUNDLE); + $productMock->method('getId') + ->willReturn($parentProductId); - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->any())->method('getId')->will($this->returnValue($linkProductId)); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); - $this->productRepository - ->expects($this->at(0)) + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->method('getId')->willReturn($linkProductId); + $linkedProductMock->expects($this->once()) + ->method('isComposite') + ->willReturn(false); + $this->productRepository->expects($this->at(0)) ->method('get') ->with($bundleProductSku) - ->will($this->returnValue($productMock)); - $this->productRepository - ->expects($this->at(1)) + ->willReturn($productMock); + $this->productRepository->expects($this->at(1)) ->method('get') ->with('linked_product_sku') - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); - $store = $this->createMock(\Magento\Store\Model\Store::class); - $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store)); - $store->expects($this->any())->method('getId')->will($this->returnValue(0)); + $store = $this->createMock(Store::class); + $this->storeManagerMock->method('getStore') + ->willReturn($store); + $store->method('getId') + ->willReturn(0); - $selection = $this->createPartialMock(\Magento\Bundle\Model\Selection::class, [ + $selection = $this->createPartialMock( + Selection::class, + [ 'save', 'getId', 'load', @@ -752,14 +819,25 @@ public function testSaveChildFailedToSave() 'setSelectionPriceValue', 'setSelectionCanChangeQty', 'setIsDefault' - ]); - $mockException = $this->createMock(\Exception::class); - $selection->expects($this->once())->method('save')->will($this->throwException($mockException)); - $selection->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); - $selection->expects($this->any())->method('getId')->will($this->returnValue($id)); - $selection->expects($this->once())->method('setProductId')->with($linkProductId); - - $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); + ] + ); + $mockException = $this->createMock(Exception::class); + $selection->expects($this->once()) + ->method('save') + ->willThrowException($mockException); + $selection->expects($this->once()) + ->method('load') + ->with($id) + ->willReturnSelf(); + $selection->method('getId') + ->willReturn($id); + $selection->expects($this->once()) + ->method('setProductId') + ->with($linkProductId); + + $this->bundleSelectionMock->expects($this->once()) + ->method('create') + ->willReturn($selection); $this->model->saveChild($bundleProductSku, $productLink); } @@ -768,29 +846,29 @@ public function testSaveChildFailedToSave() */ public function testSaveChildWithoutId() { - $bundleProductSku = "bundleSku"; + $bundleProductSku = 'bundleSku'; $linkedProductSku = 'simple'; - $productLink = $this->createMock(\Magento\Bundle\Api\Data\LinkInterface::class); - $productLink->expects($this->any())->method('getId')->will($this->returnValue(null)); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue($linkedProductSku)); + $productLink = $this->createMock(LinkInterface::class); + $productLink->method('getId')->willReturn(null); + $productLink->method('getSku')->willReturn($linkedProductSku); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once()) + ->method('getTypeId') + ->willReturn(Type::TYPE_BUNDLE); - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); - $this->productRepository - ->expects($this->at(0)) + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->expects($this->once()) + ->method('isComposite') + ->willReturn(false); + $this->productRepository->expects($this->at(0)) ->method('get') ->with($bundleProductSku) - ->will($this->returnValue($productMock)); - $this->productRepository - ->expects($this->at(1)) + ->willReturn($productMock); + $this->productRepository->expects($this->at(1)) ->method('get') ->with($linkedProductSku) - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); $this->model->saveChild($bundleProductSku, $productLink); } @@ -803,37 +881,45 @@ public function testSaveChildWithInvalidId() { $id = 12345; $linkedProductSku = 'simple'; - $bundleProductSku = "bundleProductSku"; - $productLink = $this->createMock(\Magento\Bundle\Api\Data\LinkInterface::class); - $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue($linkedProductSku)); - - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); - - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false)); - $this->productRepository - ->expects($this->at(0)) + $bundleProductSku = 'bundleProductSku'; + $productLink = $this->createMock(LinkInterface::class); + $productLink->method('getId')->willReturn($id); + $productLink->method('getSku')->willReturn($linkedProductSku); + + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once()) + ->method('getTypeId') + ->willReturn(Type::TYPE_BUNDLE); + + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->expects($this->once()) + ->method('isComposite') + ->willReturn(false); + $this->productRepository->expects($this->at(0)) ->method('get') ->with($bundleProductSku) - ->will($this->returnValue($productMock)); - $this->productRepository - ->expects($this->at(1)) + ->willReturn($productMock); + $this->productRepository->expects($this->at(1)) ->method('get') ->with($linkedProductSku) - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); - $selection = $this->createPartialMock(\Magento\Bundle\Model\Selection::class, [ + $selection = $this->createPartialMock( + Selection::class, + [ 'getId', 'load', - ]); - $selection->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); - $selection->expects($this->any())->method('getId')->will($this->returnValue(null)); + ] + ); + $selection->expects($this->once()) + ->method('load') + ->with($id) + ->willReturnSelf(); + $selection->method('getId')->willReturn(null); - $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection)); + $this->bundleSelectionMock->expects($this->once()) + ->method('create') + ->willReturn($selection); $this->model->saveChild($bundleProductSku, $productLink); } @@ -843,30 +929,26 @@ public function testSaveChildWithInvalidId() */ public function testSaveChildWithCompositeProductLink() { - $bundleProductSku = "bundleProductSku"; + $bundleProductSku = 'bundleProductSku'; $id = 12; $linkedProductSku = 'simple'; - $productLink = $this->createMock(\Magento\Bundle\Api\Data\LinkInterface::class); - $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue($linkedProductSku)); + $productLink = $this->createMock(LinkInterface::class); + $productLink->method('getId')->willReturn($id); + $productLink->method('getSku')->willReturn($linkedProductSku); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE - )); + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once())->method('getTypeId')->willReturn(Type::TYPE_BUNDLE); - $linkedProductMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(true)); - $this->productRepository - ->expects($this->at(0)) + $linkedProductMock = $this->createMock(Product::class); + $linkedProductMock->expects($this->once())->method('isComposite')->willReturn(true); + $this->productRepository->expects($this->at(0)) ->method('get') ->with($bundleProductSku) - ->will($this->returnValue($productMock)); - $this->productRepository - ->expects($this->at(1)) + ->willReturn($productMock); + $this->productRepository->expects($this->at(1)) ->method('get') ->with($linkedProductSku) - ->will($this->returnValue($linkedProductMock)); + ->willReturn($linkedProductMock); $this->model->saveChild($bundleProductSku, $productLink); } @@ -878,18 +960,18 @@ public function testSaveChildWithSimpleProduct() { $id = 12; $linkedProductSku = 'simple'; - $bundleProductSku = "bundleProductSku"; + $bundleProductSku = 'bundleProductSku'; - $productLink = $this->createMock(\Magento\Bundle\Api\Data\LinkInterface::class); - $productLink->expects($this->any())->method('getId')->will($this->returnValue($id)); - $productLink->expects($this->any())->method('getSku')->will($this->returnValue($linkedProductSku)); + $productLink = $this->createMock(LinkInterface::class); + $productLink->method('getId')->willReturn($id); + $productLink->method('getSku')->willReturn($linkedProductSku); - $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); - $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue( - \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE - )); + $productMock = $this->createMock(Product::class); + $productMock->expects($this->once())->method('getTypeId')->willReturn(Type::TYPE_SIMPLE); - $this->productRepository->expects($this->once())->method('get')->with($bundleProductSku) + $this->productRepository->expects($this->once()) + ->method('get') + ->with($bundleProductSku) ->willReturn($productMock); $this->model->saveChild($bundleProductSku, $productLink); @@ -897,34 +979,33 @@ public function testSaveChildWithSimpleProduct() public function testRemoveChild() { - $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product)); - $bundle = $this->createMock(\Magento\Bundle\Model\ResourceModel\Bundle::class); - $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle)); + $this->productRepository->method('get')->willReturn($this->product); + $bundle = $this->createMock(Bundle::class); + $this->bundleFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($bundle); $productSku = 'productSku'; $optionId = 1; $productId = 1; $childSku = 'childSku'; - $this->product - ->expects($this->any()) - ->method('getTypeId') - ->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)); + $this->product->method('getTypeId') + ->willReturn(Type::TYPE_BUNDLE); $this->getRemoveOptions(); - $selection = $this->getMockBuilder(\Magento\Bundle\Model\Selection::class) + $selection = $this->getMockBuilder(Selection::class) ->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup']) ->disableOriginalConstructor() ->getMock(); - $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku)); - $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId)); - $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55)); - $selection->expects($this->any())->method('getProductId')->willReturn($productId); - - $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection])); - $this->metadataMock->expects($this->any())->method('getLinkField')->willReturn($this->linkField); - $this->product->expects($this->any()) - ->method('getData') + $selection->method('getSku')->willReturn($childSku); + $selection->method('getOptionId')->willReturn($optionId); + $selection->method('getSelectionId')->willReturn(55); + $selection->method('getProductId')->willReturn($productId); + + $this->option->method('getSelections')->willReturn([$selection]); + $this->metadataMock->method('getLinkField')->willReturn($this->linkField); + $this->product->method('getData') ->with($this->linkField) ->willReturn(3); @@ -939,14 +1020,12 @@ public function testRemoveChild() */ public function testRemoveChildForbidden() { - $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product)); + $this->productRepository->method('get')->willReturn($this->product); $productSku = 'productSku'; $optionId = 1; $childSku = 'childSku'; - $this->product - ->expects($this->any()) - ->method('getTypeId') - ->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)); + $this->product->method('getTypeId') + ->willReturn(Type::TYPE_SIMPLE); $this->model->removeChild($productSku, $optionId, $childSku); } @@ -955,28 +1034,26 @@ public function testRemoveChildForbidden() */ public function testRemoveChildInvalidOptionId() { - $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product)); + $this->productRepository->method('get')->willReturn($this->product); $productSku = 'productSku'; $optionId = 1; $childSku = 'childSku'; - $this->product - ->expects($this->any()) - ->method('getTypeId') - ->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)); + $this->product->method('getTypeId') + ->willReturn(Type::TYPE_BUNDLE); $this->getRemoveOptions(); - $selection = $this->getMockBuilder(\Magento\Bundle\Model\Selection::class) + $selection = $this->getMockBuilder(Selection::class) ->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup']) ->disableOriginalConstructor() ->getMock(); - $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku)); - $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId + 1)); - $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55)); - $selection->expects($this->any())->method('getProductId')->will($this->returnValue(1)); + $selection->method('getSku')->willReturn($childSku); + $selection->method('getOptionId')->willReturn($optionId + 1); + $selection->method('getSelectionId')->willReturn(55); + $selection->method('getProductId')->willReturn(1); - $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection])); + $this->option->method('getSelections')->willReturn([$selection]); $this->model->removeChild($productSku, $optionId, $childSku); } @@ -985,61 +1062,71 @@ public function testRemoveChildInvalidOptionId() */ public function testRemoveChildInvalidChildSku() { - $this->productRepository->expects($this->any())->method('get')->will($this->returnValue($this->product)); + $this->productRepository->method('get')->willReturn($this->product); $productSku = 'productSku'; $optionId = 1; $childSku = 'childSku'; - $this->product - ->expects($this->any()) - ->method('getTypeId') - ->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)); + $this->product->method('getTypeId') + ->willReturn(Type::TYPE_BUNDLE); $this->getRemoveOptions(); - $selection = $this->getMockBuilder(\Magento\Bundle\Model\Selection::class) + $selection = $this->getMockBuilder(Selection::class) ->setMethods(['getSku', 'getOptionId', 'getSelectionId', 'getProductId', '__wakeup']) ->disableOriginalConstructor() ->getMock(); - $selection->expects($this->any())->method('getSku')->will($this->returnValue($childSku . '_invalid')); - $selection->expects($this->any())->method('getOptionId')->will($this->returnValue($optionId)); - $selection->expects($this->any())->method('getSelectionId')->will($this->returnValue(55)); - $selection->expects($this->any())->method('getProductId')->will($this->returnValue(1)); + $selection->method('getSku')->willReturn($childSku . '_invalid'); + $selection->method('getOptionId')->willReturn($optionId); + $selection->method('getSelectionId')->willReturn(55); + $selection->method('getProductId')->willReturn(1); - $this->option->expects($this->any())->method('getSelections')->will($this->returnValue([$selection])); + $this->option->method('getSelections') + ->willReturn([$selection]); $this->model->removeChild($productSku, $optionId, $childSku); } private function getOptions() { - $this->product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->productType)); - $this->product->expects($this->once())->method('getStoreId')->will($this->returnValue($this->storeId)); - $this->productType->expects($this->once())->method('setStoreFilter') + $this->product->method('getTypeInstance') + ->willReturn($this->productType); + $this->product->expects($this->once()) + ->method('getStoreId') + ->willReturn($this->storeId); + $this->productType->expects($this->once()) + ->method('setStoreFilter') ->with($this->equalTo($this->storeId), $this->equalTo($this->product)); - $this->productType->expects($this->once())->method('getOptionsCollection') + $this->productType->expects($this->once()) + ->method('getOptionsCollection') ->with($this->equalTo($this->product)) - ->will($this->returnValue($this->optionCollection)); + ->willReturn($this->optionCollection); } public function getRemoveOptions() { - $this->product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($this->productType)); - $this->product->expects($this->once())->method('getStoreId')->will($this->returnValue(1)); + $this->product->method('getTypeInstance') + ->willReturn($this->productType); + $this->product->expects($this->once()) + ->method('getStoreId') + ->willReturn(1); $this->productType->expects($this->once())->method('setStoreFilter'); $this->productType->expects($this->once())->method('getOptionsCollection') ->with($this->equalTo($this->product)) - ->will($this->returnValue($this->optionCollection)); + ->willReturn($this->optionCollection); - $this->productType->expects($this->once())->method('getOptionsIds')->with($this->equalTo($this->product)) - ->will($this->returnValue([1, 2, 3])); + $this->productType->expects($this->once()) + ->method('getOptionsIds') + ->with($this->equalTo($this->product)) + ->willReturn([1, 2, 3]); - $this->productType->expects($this->once())->method('getSelectionsCollection') - ->will($this->returnValue([])); + $this->productType->expects($this->once()) + ->method('getSelectionsCollection') + ->willReturn([]); - $this->optionCollection->expects($this->any())->method('appendSelections') + $this->optionCollection->method('appendSelections') ->with($this->equalTo([]), true) - ->will($this->returnValue([$this->option])); + ->willReturn([$this->option]); } } diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php index 3e9aeaed5c5b4..3c4dbf2e85274 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php @@ -3,50 +3,71 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Bundle\Test\Unit\Model\Sales\Order\Pdf\Items; -class AbstractItemsTest extends \PHPUnit\Framework\TestCase +use Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Sales\Model\Order\Creditmemo; +use Magento\Sales\Model\Order\Invoice; +use Magento\Sales\Model\Order\Item; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; + +class AbstractItemsTest extends TestCase { - /** @var \Magento\Sales\Model\Order\Item|\PHPUnit_Framework_MockObject_MockObject */ - protected $orderItem; + /** + * @var Shipment + */ + private $model; - /** @var \Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment $model */ - protected $model; + /** + * @var Json|MockObject + */ + private $serializerMock; - /** @var \Magento\Framework\Serialize\Serializer\Json $serializer */ - protected $serializer; + /** + * @var Item|MockObject + */ + private $orderItemMock; protected function setUp() { - $this->orderItem = $this->createPartialMock( - \Magento\Sales\Model\Order\Item::class, + $this->orderItemMock = $this->createPartialMock( + Item::class, ['getProductOptions', '__wakeup', 'getParentItem', 'getOrderItem', 'getOrderItemId', 'getId'] ); - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class); + $objectManager = new ObjectManager($this); + $this->serializerMock = $this->createMock(Json::class); $this->model = $objectManager->getObject( - \Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment::class, + Shipment::class, [ - 'serializer' => $this->serializer + 'serializer' => $this->serializerMock ] ); } /** * @dataProvider getChildrenEmptyItemsDataProvider + * + * @param string $class + * @param string $method + * @param string $returnClass */ public function testGetChildrenEmptyItems($class, $method, $returnClass) { $salesModel = $this->createPartialMock($returnClass, ['getAllItems', '__wakeup']); - $salesModel->expects($this->once())->method('getAllItems')->will($this->returnValue([])); + $salesModel->expects($this->once())->method('getAllItems')->willReturn([]); $item = $this->createPartialMock($class, [$method, 'getOrderItem', '__wakeup']); - $item->expects($this->once())->method($method)->will($this->returnValue($salesModel)); - $item->expects($this->once())->method('getOrderItem')->will($this->returnValue($this->orderItem)); - $this->orderItem->expects($this->any())->method('getId')->will($this->returnValue(1)); + $item->expects($this->once())->method($method)->willReturn($salesModel); + $item->expects($this->once())->method('getOrderItem')->willReturn($this->orderItemMock); + $this->orderItemMock->method('getId')->willReturn(1); - $this->assertSame(null, $this->model->getChildren($item)); + $this->assertNull($this->model->getChildren($item)); } /** @@ -56,9 +77,9 @@ public function getChildrenEmptyItemsDataProvider() { return [ [ - \Magento\Sales\Model\Order\Invoice\Item::class, + Invoice\Item::class, 'getInvoice', - \Magento\Sales\Model\Order\Invoice::class + Invoice::class ], [ \Magento\Sales\Model\Order\Shipment\Item::class, @@ -66,38 +87,40 @@ public function getChildrenEmptyItemsDataProvider() \Magento\Sales\Model\Order\Shipment::class ], [ - \Magento\Sales\Model\Order\Creditmemo\Item::class, + Creditmemo\Item::class, 'getCreditmemo', - \Magento\Sales\Model\Order\Creditmemo::class + Creditmemo::class ] ]; } /** * @dataProvider getChildrenDataProvider + * + * @param bool $parentItem */ public function testGetChildren($parentItem) { if ($parentItem) { - $parentItem = $this->createPartialMock(\Magento\Sales\Model\Order\Item::class, ['getId', '__wakeup']); - $parentItem->expects($this->any())->method('getId')->will($this->returnValue(1)); + $parentItem = $this->createPartialMock(Item::class, ['getId', '__wakeup']); + $parentItem->method('getId')->willReturn(1); } - $this->orderItem->expects($this->any())->method('getOrderItem')->will($this->returnSelf()); - $this->orderItem->expects($this->any())->method('getParentItem')->will($this->returnValue($parentItem)); - $this->orderItem->expects($this->any())->method('getOrderItemId')->will($this->returnValue(2)); - $this->orderItem->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->orderItemMock->method('getOrderItem')->willReturnSelf(); + $this->orderItemMock->method('getParentItem')->willReturn($parentItem); + $this->orderItemMock->method('getOrderItemId')->willReturn(2); + $this->orderItemMock->method('getId')->willReturn(1); - $salesModel = $this->createPartialMock(\Magento\Sales\Model\Order\Invoice::class, ['getAllItems', '__wakeup']); - $salesModel->expects($this->once())->method('getAllItems')->will($this->returnValue([$this->orderItem])); + $salesModel = $this->createPartialMock(Invoice::class, ['getAllItems', '__wakeup']); + $salesModel->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]); $item = $this->createPartialMock( - \Magento\Sales\Model\Order\Invoice\Item::class, + Invoice\Item::class, ['getInvoice', 'getOrderItem', '__wakeup'] ); - $item->expects($this->once())->method('getInvoice')->will($this->returnValue($salesModel)); - $item->expects($this->any())->method('getOrderItem')->will($this->returnValue($this->orderItem)); + $item->expects($this->once())->method('getInvoice')->willReturn($salesModel); + $item->method('getOrderItem')->willReturn($this->orderItemMock); - $this->assertSame([2 => $this->orderItem], $this->model->getChildren($item)); + $this->assertSame([2 => $this->orderItemMock], $this->model->getChildren($item)); } /** @@ -113,11 +136,14 @@ public function getChildrenDataProvider() /** * @dataProvider isShipmentSeparatelyWithoutItemDataProvider + * + * @param array $productOptions + * @param bool $result */ public function testIsShipmentSeparatelyWithoutItem($productOptions, $result) { - $this->model->setItem($this->orderItem); - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); + $this->model->setItem($this->orderItemMock); + $this->orderItemMock->method('getProductOptions')->willReturn($productOptions); $this->assertSame($result, $this->model->isShipmentSeparately()); } @@ -136,23 +162,27 @@ public function isShipmentSeparatelyWithoutItemDataProvider() /** * @dataProvider isShipmentSeparatelyWithItemDataProvider + * + * @param array $productOptions + * @param bool $result + * @param bool $parentItem */ public function testIsShipmentSeparatelyWithItem($productOptions, $result, $parentItem) { if ($parentItem) { $parentItem = $this->createPartialMock( - \Magento\Sales\Model\Order\Item::class, + Item::class, ['getProductOptions', '__wakeup'] ); - $parentItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); + $parentItem->method('getProductOptions')->willReturn($productOptions); } else { - $this->orderItem->expects($this->any())->method('getProductOptions') - ->will($this->returnValue($productOptions)); + $this->orderItemMock->method('getProductOptions') + ->willReturn($productOptions); } - $this->orderItem->expects($this->any())->method('getParentItem')->will($this->returnValue($parentItem)); - $this->orderItem->expects($this->any())->method('getOrderItem')->will($this->returnSelf()); + $this->orderItemMock->method('getParentItem')->willReturn($parentItem); + $this->orderItemMock->method('getOrderItem')->willReturnSelf(); - $this->assertSame($result, $this->model->isShipmentSeparately($this->orderItem)); + $this->assertSame($result, $this->model->isShipmentSeparately($this->orderItemMock)); } /** @@ -170,11 +200,14 @@ public function isShipmentSeparatelyWithItemDataProvider() /** * @dataProvider isChildCalculatedWithoutItemDataProvider + * + * @param array $productOptions + * @param bool $result */ public function testIsChildCalculatedWithoutItem($productOptions, $result) { - $this->model->setItem($this->orderItem); - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); + $this->model->setItem($this->orderItemMock); + $this->orderItemMock->method('getProductOptions')->willReturn($productOptions); $this->assertSame($result, $this->model->isChildCalculated()); } @@ -193,23 +226,27 @@ public function isChildCalculatedWithoutItemDataProvider() /** * @dataProvider isChildCalculatedWithItemDataProvider + * + * @param array $productOptions + * @param bool $result + * @param bool $parentItem */ public function testIsChildCalculatedWithItem($productOptions, $result, $parentItem) { if ($parentItem) { $parentItem = $this->createPartialMock( - \Magento\Sales\Model\Order\Item::class, + Item::class, ['getProductOptions', '__wakeup'] ); - $parentItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); + $parentItem->method('getProductOptions')->willReturn($productOptions); } else { - $this->orderItem->expects($this->any())->method('getProductOptions') - ->will($this->returnValue($productOptions)); + $this->orderItemMock->method('getProductOptions') + ->willReturn($productOptions); } - $this->orderItem->expects($this->any())->method('getParentItem')->will($this->returnValue($parentItem)); - $this->orderItem->expects($this->any())->method('getOrderItem')->will($this->returnSelf()); + $this->orderItemMock->method('getParentItem')->willReturn($parentItem); + $this->orderItemMock->method('getOrderItem')->willReturnSelf(); - $this->assertSame($result, $this->model->isChildCalculated($this->orderItem)); + $this->assertSame($result, $this->model->isChildCalculated($this->orderItemMock)); } /** @@ -227,11 +264,13 @@ public function isChildCalculatedWithItemDataProvider() /** * @dataProvider getBundleOptionsDataProvider + * @param array $productOptions + * @param array|string $result */ public function testGetBundleOptions($productOptions, $result) { - $this->model->setItem($this->orderItem); - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); + $this->model->setItem($this->orderItemMock); + $this->orderItemMock->method('getProductOptions')->willReturn($productOptions); $this->assertSame($result, $this->model->getBundleOptions()); } @@ -248,8 +287,8 @@ public function getBundleOptionsDataProvider() public function testGetSelectionAttributes() { - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue([])); - $this->assertNull($this->model->getSelectionAttributes($this->orderItem)); + $this->orderItemMock->method('getProductOptions')->willReturn([]); + $this->assertNull($this->model->getSelectionAttributes($this->orderItemMock)); } public function testGetSelectionAttributesWithBundle() @@ -258,13 +297,12 @@ public function testGetSelectionAttributesWithBundle() $options = ['bundle_selection_attributes' => $bundleAttributes]; $unserializedResult = 'result of "bundle_selection_attributes" unserialization'; - $this->serializer->expects($this->any()) - ->method('unserialize') + $this->serializerMock->method('unserialize') ->with($bundleAttributes) - ->will($this->returnValue($unserializedResult)); - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($options)); + ->willReturn($unserializedResult); + $this->orderItemMock->method('getProductOptions')->willReturn($options); - $this->assertEquals($unserializedResult, $this->model->getSelectionAttributes($this->orderItem)); + $this->assertEquals($unserializedResult, $this->model->getSelectionAttributes($this->orderItemMock)); } public function testGetOrderOptions() @@ -274,28 +312,32 @@ public function testGetOrderOptions() 'additional_options' => ['additional_options'], 'attributes_info' => ['attributes_info'], ]; - $this->model->setItem($this->orderItem); - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); + $this->model->setItem($this->orderItemMock); + $this->orderItemMock->method('getProductOptions')->willReturn($productOptions); $this->assertEquals(['attributes_info', 'options', 'additional_options'], $this->model->getOrderOptions()); } public function testGetOrderItem() { - $this->model->setItem($this->orderItem); - $this->assertSame($this->orderItem, $this->model->getOrderItem()); + $this->model->setItem($this->orderItemMock); + $this->assertSame($this->orderItemMock, $this->model->getOrderItem()); } /** * @dataProvider canShowPriceInfoDataProvider + * + * @param bool $parentItem + * @param array $productOptions + * @param bool $result */ public function testCanShowPriceInfo($parentItem, $productOptions, $result) { - $this->model->setItem($this->orderItem); - $this->orderItem->expects($this->any())->method('getOrderItem')->will($this->returnSelf()); - $this->orderItem->expects($this->any())->method('getParentItem')->will($this->returnValue($parentItem)); - $this->orderItem->expects($this->any())->method('getProductOptions')->will($this->returnValue($productOptions)); + $this->model->setItem($this->orderItemMock); + $this->orderItemMock->method('getOrderItem')->willReturnSelf(); + $this->orderItemMock->method('getParentItem')->willReturn($parentItem); + $this->orderItemMock->method('getProductOptions')->willReturn($productOptions); - $this->assertSame($result, $this->model->canShowPriceInfo($this->orderItem)); + $this->assertSame($result, $this->model->canShowPriceInfo($this->orderItemMock)); } /** diff --git a/app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleOptionsTest.php b/app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleOptionsTest.php index 37973b9b8ae28..d795af793675b 100644 --- a/app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleOptionsTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleOptionsTest.php @@ -7,23 +7,24 @@ namespace Magento\Bundle\Test\Unit\Pricing\Price; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; -use PHPUnit_Framework_MockObject_MockObject as MockObject; -use Magento\Framework\Pricing\Amount\AmountFactory; -use Magento\Framework\Pricing\Adjustment\Calculator as AdjustmentCalculator; -use Magento\Framework\Pricing\PriceInfo\Base as BasePriceInfo; -use Magento\Framework\Pricing\PriceCurrencyInterface; -use Magento\Framework\Pricing\Amount\AmountInterface; -use Magento\Framework\Pricing\Amount\Base as BaseAmount; -use Magento\Bundle\Pricing\Price\BundleOptions; -use Magento\Bundle\Pricing\Price\BundleSelectionPrice; -use Magento\Bundle\Pricing\Price\BundleSelectionFactory; -use Magento\Bundle\Pricing\Adjustment\Calculator as BundleAdjustmentCalculator; use Magento\Bundle\Model\Option as BundleOption; use Magento\Bundle\Model\Product\Type as BundleProductType; use Magento\Bundle\Model\ResourceModel\Option\Collection as BundleOptionCollection; +use Magento\Bundle\Pricing\Adjustment\Calculator as BundleAdjustmentCalculator; +use Magento\Bundle\Pricing\Adjustment\SelectionPriceListProviderInterface; +use Magento\Bundle\Pricing\Price\BundleOptions; +use Magento\Bundle\Pricing\Price\BundleSelectionFactory; +use Magento\Bundle\Pricing\Price\BundleSelectionPrice; use Magento\Catalog\Model\Product; +use Magento\Framework\Pricing\Adjustment\Calculator as AdjustmentCalculator; +use Magento\Framework\Pricing\Amount\AmountFactory; +use Magento\Framework\Pricing\Amount\AmountInterface; +use Magento\Framework\Pricing\Amount\Base as BaseAmount; +use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Framework\Pricing\PriceInfo\Base as BasePriceInfo; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Tax\Helper\Data as TaxHelperData; +use PHPUnit_Framework_MockObject_MockObject as MockObject; /** * Test for Magento\Bundle\Pricing\Price\BundleOptions @@ -71,6 +72,11 @@ class BundleOptionsTest extends \PHPUnit\Framework\TestCase */ private $priceInfoMock; + /** + * @var SelectionPriceListProviderInterface + */ + private $selectionPriceListProviderMock; + protected function setUp() { $this->priceInfoMock = $this->getMockBuilder(BasePriceInfo::class) @@ -102,9 +108,20 @@ function ($fullAmount, $adjustments) { ->disableOriginalConstructor() ->getMock(); + $this->selectionPriceListProviderMock = $this->getMockBuilder(SelectionPriceListProviderInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->bundleCalculatorMock = $this->getMockBuilder(BundleAdjustmentCalculator::class) ->setConstructorArgs( - [$this->baseCalculator, $this->amountFactory, $this->selectionFactoryMock, $taxData, $priceCurrency] + [ + $this->baseCalculator, + $this->amountFactory, + $this->selectionFactoryMock, + $taxData, + $priceCurrency, + $this->selectionPriceListProviderMock + ] ) ->setMethods(['getOptionsAmount']) ->getMock(); diff --git a/app/code/Magento/Bundle/Test/Unit/Pricing/Price/FinalPriceTest.php b/app/code/Magento/Bundle/Test/Unit/Pricing/Price/FinalPriceTest.php index 4463709391102..d21971b821691 100644 --- a/app/code/Magento/Bundle/Test/Unit/Pricing/Price/FinalPriceTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Pricing/Price/FinalPriceTest.php @@ -3,121 +3,156 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Bundle\Test\Unit\Pricing\Price; +use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface; use Magento\Bundle\Pricing\Price\BundleOptionPrice; +use Magento\Bundle\Pricing\Price\FinalPrice; +use Magento\Catalog\Api\Data\ProductCustomOptionInterface; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Pricing\Price\BasePrice; use Magento\Catalog\Pricing\Price\CustomOptionPrice; use Magento\Bundle\Model\Product\Price; use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface; use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Framework\Pricing\PriceInfo\Base; +use Magento\Framework\Pricing\SaleableInterface; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** - * @SuppressWarnings(PHPMD) + * Test class for \Magento\Bundle\Pricing\Price\FinalPrice + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class FinalPriceTest extends \PHPUnit\Framework\TestCase +class FinalPriceTest extends TestCase { - /** @var \Magento\Bundle\Pricing\Price\FinalPrice */ - protected $finalPrice; + /** + * @var FinalPrice + */ + private $finalPrice; - /** @var ObjectManagerHelper */ - protected $objectManagerHelper; + /** + * @var ObjectManagerHelper + */ + private $objectManagerHelper; - /** @var \Magento\Framework\Pricing\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $saleableInterfaceMock; + /** + * @var SaleableInterface|MockObject + */ + private $saleableInterfaceMock; - /** @var float */ - protected $quantity = 1.; + /** + * @var float + */ + private $quantity = 1.; - /** @var float*/ - protected $baseAmount; + /** + * @var BundleCalculatorInterface|MockObject + */ + private $bundleCalculatorMock; - /** @var \Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $bundleCalculatorMock; + /** + * @var PriceCurrencyInterface|MockObject + */ + private $priceCurrencyMock; - /** @var \Magento\Framework\Pricing\PriceInfo\Base |\PHPUnit_Framework_MockObject_MockObject */ - protected $priceInfoMock; + /** + * @var ProductCustomOptionRepositoryInterface|MockObject + */ + private $productOptionRepositoryMock; - /** @var \Magento\Catalog\Pricing\Price\BasePrice|\PHPUnit_Framework_MockObject_MockObject */ - protected $basePriceMock; + /** + * @var float + */ + private $baseAmount; - /** @var BundleOptionPrice|\PHPUnit_Framework_MockObject_MockObject */ - protected $bundleOptionMock; + /** + * @var Base|MockObject + */ + private $priceInfoMock; - /** @var CustomOptionPrice|\PHPUnit_Framework_MockObject_MockObject */ - protected $customOptionPriceMock; + /** + * @var BasePrice|MockObject + */ + private $basePriceMock; /** - * @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject + * @var BundleOptionPrice|MockObject */ - protected $priceCurrencyMock; + private $bundleOptionMock; /** - * @var ProductCustomOptionRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + * @var CustomOptionPrice|MockObject */ - private $productOptionRepositoryMock; + private $customOptionPriceMock; /** * @return void */ protected function prepareMock() { - $this->saleableInterfaceMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + $this->saleableInterfaceMock = $this->getMockBuilder(Product::class) ->disableOriginalConstructor() ->setMethods(['getPriceType', 'getPriceInfo']) ->getMock(); $this->bundleCalculatorMock = $this->createMock( - \Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface::class + BundleCalculatorInterface::class ); - $this->basePriceMock = $this->createMock(\Magento\Catalog\Pricing\Price\BasePrice::class); - $this->basePriceMock->expects($this->any()) - ->method('getValue') - ->will($this->returnValue($this->baseAmount)); + $this->basePriceMock = $this->createMock(BasePrice::class); + $this->basePriceMock->method('getValue') + ->willReturn($this->baseAmount); - $this->bundleOptionMock = $this->getMockBuilder(\Magento\Bundle\Pricing\Price\BundleOptionPrice::class) + $this->bundleOptionMock = $this->getMockBuilder(BundleOptionPrice::class) ->disableOriginalConstructor() ->getMock(); - $this->customOptionPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\CustomOptionPrice::class) + $this->customOptionPriceMock = $this->getMockBuilder(CustomOptionPrice::class) ->disableOriginalConstructor() ->getMock(); - $this->priceInfoMock = $this->createMock(\Magento\Framework\Pricing\PriceInfo\Base::class); + $this->priceInfoMock = $this->createMock(Base::class); $this->priceInfoMock->expects($this->atLeastOnce()) ->method('getPrice') - ->will($this->returnValueMap([ - [\Magento\Catalog\Pricing\Price\BasePrice::PRICE_CODE, $this->basePriceMock], - [BundleOptionPrice::PRICE_CODE, $this->bundleOptionMock], - [CustomOptionPrice::PRICE_CODE, $this->customOptionPriceMock], - ])); + ->willReturnMap( + [ + [BasePrice::PRICE_CODE, $this->basePriceMock], + [BundleOptionPrice::PRICE_CODE, $this->bundleOptionMock], + [CustomOptionPrice::PRICE_CODE, $this->customOptionPriceMock], + ] + ); $this->saleableInterfaceMock->expects($this->once()) ->method('getPriceInfo') - ->will($this->returnValue($this->priceInfoMock)); - - $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class); - - $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->finalPrice = new \Magento\Bundle\Pricing\Price\FinalPrice( - $this->saleableInterfaceMock, - $this->quantity, - $this->bundleCalculatorMock, - $this->priceCurrencyMock - ); + ->willReturn($this->priceInfoMock); + $this->priceCurrencyMock = $this->createMock(PriceCurrencyInterface::class); $this->productOptionRepositoryMock = $this->getMockForAbstractClass( ProductCustomOptionRepositoryInterface::class ); - $reflection = new \ReflectionClass(get_class($this->finalPrice)); - $reflectionProperty = $reflection->getProperty('productOptionRepository'); - $reflectionProperty->setAccessible(true); - $reflectionProperty->setValue($this->finalPrice, $this->productOptionRepositoryMock); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->finalPrice = $this->objectManagerHelper->getObject( + FinalPrice::class, + [ + 'saleableItem' => $this->saleableInterfaceMock, + 'quantity' => $this->quantity, + 'calculator' => $this->bundleCalculatorMock, + 'priceCurrency' => $this->priceCurrencyMock, + 'productOptionRepository' => $this->productOptionRepositoryMock + ] + ); } /** + * @param $baseAmount + * @param $optionsValue + * @param $result * @dataProvider getValueDataProvider */ public function testGetValue($baseAmount, $optionsValue, $result) @@ -126,7 +161,7 @@ public function testGetValue($baseAmount, $optionsValue, $result) $this->prepareMock(); $this->bundleOptionMock->expects($this->once()) ->method('getValue') - ->will($this->returnValue($optionsValue)); + ->willReturn($optionsValue); $this->assertSame($result, $this->finalPrice->getValue()); } @@ -144,6 +179,7 @@ public function getValueDataProvider() } /** + * @param $baseAmount * @dataProvider getValueDataProvider */ public function testGetMaximalPrice($baseAmount) @@ -155,7 +191,7 @@ public function testGetMaximalPrice($baseAmount) $this->bundleCalculatorMock->expects($this->once()) ->method('getMaxAmount') ->with($this->equalTo($this->baseAmount), $this->equalTo($this->saleableInterfaceMock)) - ->will($this->returnValue($result)); + ->willReturn($result); $this->assertSame($result, $this->finalPrice->getMaximalPrice()); //The second call should use cached value $this->assertSame($result, $this->finalPrice->getMaximalPrice()); @@ -179,7 +215,7 @@ public function testGetMaximalPriceFixedBundleWithOption() $this->bundleCalculatorMock->expects($this->once()) ->method('getMaxAmount') ->with($this->equalTo($this->baseAmount + $optionMaxPrice), $this->equalTo($this->saleableInterfaceMock)) - ->will($this->returnValue($result)); + ->willReturn($result); $this->assertSame($result, $this->finalPrice->getMaximalPrice()); //The second call should use cached value $this->assertSame($result, $this->finalPrice->getMaximalPrice()); @@ -192,7 +228,7 @@ public function testGetMinimalPriceFixedBundleWithOption() $result = 7; $this->prepareMock(); $customOptions = [ - $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductCustomOptionInterface::class) + $this->getMockBuilder(ProductCustomOptionInterface::class) ->setMethods(['setProduct']) ->getMockForAbstractClass() ]; @@ -213,7 +249,7 @@ public function testGetMinimalPriceFixedBundleWithOption() $this->bundleCalculatorMock->expects($this->once()) ->method('getAmount') ->with($this->equalTo($this->baseAmount + $optionMaxPrice), $this->equalTo($this->saleableInterfaceMock)) - ->will($this->returnValue($result)); + ->willReturn($result); $this->assertSame($result, $this->finalPrice->getMinimalPrice()); //The second call should use cached value $this->assertSame($result, $this->finalPrice->getMinimalPrice()); @@ -231,7 +267,7 @@ public function testGetMinimalPrice($baseAmount) $this->bundleCalculatorMock->expects($this->once()) ->method('getAmount') ->with($this->equalTo($this->baseAmount), $this->equalTo($this->saleableInterfaceMock)) - ->will($this->returnValue($result)); + ->willReturn($result); $this->assertSame($result, $this->finalPrice->getMinimalPrice()); //The second call should use cached value $this->assertSame($result, $this->finalPrice->getMinimalPrice()); @@ -244,7 +280,7 @@ public function testGetPriceWithoutOption() $this->bundleCalculatorMock->expects($this->once()) ->method('getAmountWithoutOption') ->with($this->equalTo($this->baseAmount), $this->equalTo($this->saleableInterfaceMock)) - ->will($this->returnValue($result)); + ->willReturn($result); $this->assertSame($result, $this->finalPrice->getPriceWithoutOption()); //The second call should use cached value $this->assertSame($result, $this->finalPrice->getPriceWithoutOption()); diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php index 4dbaa93b1d134..c8a846cb2a758 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php @@ -6,10 +6,10 @@ namespace Magento\Newsletter\Test\Unit\Model\Plugin; use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Api\Data\CustomerExtensionInterface; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Customer\Model\Config\Share; use Magento\Customer\Model\ResourceModel\CustomerRepository; -use Magento\Customer\Api\Data\CustomerExtensionInterface; use Magento\Framework\Api\ExtensionAttributesFactory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Newsletter\Model\Plugin\CustomerPlugin; @@ -134,7 +134,13 @@ public function testAfterSave(?int $originalStatus, ?bool $newValue, ?bool $expe } $this->subscriberFactory->method('create')->willReturn($subscriber); - $customerExtension = $this->createPartialMock(CustomerExtensionInterface::class, ['getIsSubscribed']); + $customerExtension = $this->createPartialMock( + CustomerExtensionInterface::class, + [ + 'getIsSubscribed', + 'CustomerExtensionInterface' + ] + ); $customerExtension->method('getIsSubscribed')->willReturn($newValue); /** @var CustomerInterface|MockObject $customer */ $customer = $this->createMock(CustomerInterface::class); @@ -152,7 +158,14 @@ public function testAfterSave(?int $originalStatus, ?bool $newValue, ?bool $expe $this->subscriptionManager->expects($this->never())->method('subscribeCustomer'); $this->subscriptionManager->expects($this->never())->method('unsubscribeCustomer'); } - $resultExtension = $this->createPartialMock(CustomerExtensionInterface::class, ['setIsSubscribed']); + $resultExtension = $this->createPartialMock( + CustomerExtensionInterface::class, + [ + 'setIsSubscribed', + 'getIsSubscribed', + 'CustomerExtensionInterface' + ] + ); $resultExtension->expects($this->once())->method('setIsSubscribed')->with($resultIsSubscribed); /** @var CustomerInterface|MockObject $result */ $result = $this->createMock(CustomerInterface::class); @@ -291,7 +304,7 @@ public function testAfterGetByIdCreatesExtensionAttributes(): void $customerExtension = $this->createPartialMock( CustomerExtensionInterface::class, - ['getIsSubscribed', 'setIsSubscribed'] + ['getIsSubscribed', 'setIsSubscribed','CustomerExtensionInterface'] ); $customerExtension->expects($this->once())->method('setIsSubscribed')->with($subscribed); $this->extensionFactory->expects($this->once())->method('create')->willReturn($customerExtension); diff --git a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js index 443d35f1b0ded..84e9494a8e781 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/prompt.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/prompt.js @@ -111,6 +111,7 @@ define([ _create: function () { this.options.focus = this.options.promptField; this.options.validation = this.options.validation && this.options.validationRules.length; + this.options.outerClickHandler = this.options.outerClickHandler || _.bind(this.closeModal, this, false); this._super(); this.modal.find(this.options.modalContent).append(this.getFormTemplate()); this.modal.find(this.options.modalCloseBtn).off().on('click', _.bind(this.closeModal, this, false)); diff --git a/app/code/Magento/WeeeGraphQl/Test/Unit/FixedProductTaxTest.php b/app/code/Magento/WeeeGraphQl/Test/Unit/FixedProductTaxTest.php index 9e5812282545a..b289c7d1dac55 100644 --- a/app/code/Magento/WeeeGraphQl/Test/Unit/FixedProductTaxTest.php +++ b/app/code/Magento/WeeeGraphQl/Test/Unit/FixedProductTaxTest.php @@ -58,7 +58,7 @@ protected function setUp() ->getMock(); $this->extensionAttributesMock = $this->getMockBuilder(ContextExtensionInterface::class) - ->setMethods(['getStore']) + ->setMethods(['getStore', 'setStore', 'getIsCustomer', 'setIsCustomer']) ->getMock(); $this->contextMock->method('getExtensionAttributes') diff --git a/app/code/Magento/WishlistGraphQl/Test/Unit/CustomerWishlistResolverTest.php b/app/code/Magento/WishlistGraphQl/Test/Unit/CustomerWishlistResolverTest.php index f5baa5183e558..67c38561c7e41 100644 --- a/app/code/Magento/WishlistGraphQl/Test/Unit/CustomerWishlistResolverTest.php +++ b/app/code/Magento/WishlistGraphQl/Test/Unit/CustomerWishlistResolverTest.php @@ -58,7 +58,7 @@ protected function setUp() ->getMock(); $this->extensionAttributesMock = $this->getMockBuilder(ContextExtensionInterface::class) - ->setMethods(['getIsCustomer']) + ->setMethods(['getStore', 'setStore', 'getIsCustomer', 'setIsCustomer']) ->getMock(); $this->contextMock->method('getExtensionAttributes') diff --git a/app/design/frontend/Magento/blank/Magento_Checkout/web/css/source/module/_minicart.less b/app/design/frontend/Magento/blank/Magento_Checkout/web/css/source/module/_minicart.less index c9b1d41857eee..9ed7e3a1ba839 100644 --- a/app/design/frontend/Magento/blank/Magento_Checkout/web/css/source/module/_minicart.less +++ b/app/design/frontend/Magento/blank/Magento_Checkout/web/css/source/module/_minicart.less @@ -135,7 +135,7 @@ .product { .actions { float: right; - margin: -24px 0 0; + margin: -28px 0 0; text-align: right; > .primary, diff --git a/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_minicart.less b/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_minicart.less index 14c754623cf03..a97cc041b1c42 100644 --- a/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_minicart.less +++ b/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/_minicart.less @@ -145,7 +145,7 @@ .product { .actions { float: right; - margin: -24px 0 0; + margin: -28px 0 0; > .primary, > .secondary { diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/modal/prompt.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/modal/prompt.test.js index f2c74729e0ee8..7a0d3ac3fef91 100644 --- a/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/modal/prompt.test.js +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/modal/prompt.test.js @@ -10,8 +10,20 @@ define([ 'use strict'; describe('ui/js/modal/prompt', function () { - var element = $('<div>some element</div>'), + + var element, + prompt, + widget; + + beforeEach(function () { + element = $('<div id="element">some element</div>'), prompt = element.prompt({}); + widget = element.prompt({}).data('mage-prompt'); + }); + + afterEach(function () { + $('#element').remove(); + }); it('Check for modal definition', function () { expect(prompt).toBeDefined(); @@ -23,5 +35,12 @@ define([ it('Integration: modal created on page', function () { expect(prompt.length).toEqual(1); }); + it('Check cancel action', function () { + var cancel = spyOn(widget.options.actions, 'cancel'); + + jQuery('.modals-overlay').click(); + expect(widget.options.outerClickHandler).toBeDefined(); + expect(cancel).toHaveBeenCalled(); + }); }); }); diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/DateTimeTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/DateTimeTest.php index 4f003c4b8ba10..210e36ee05ef1 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/DateTimeTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/DateTimeTest.php @@ -5,13 +5,18 @@ */ namespace Magento\Framework\Stdlib\Test\Unit\DateTime; +use DateTimeImmutable; +use DateTimeInterface; +use Exception; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** - * Magento\Framework\Stdlib\DateTimeTest test case + * Tests for @see DateTime */ -class DateTimeTest extends \PHPUnit\Framework\TestCase +class DateTimeTest extends TestCase { /** * @var string @@ -19,12 +24,14 @@ class DateTimeTest extends \PHPUnit\Framework\TestCase private $testDate = '2015-04-02 21:03:00'; /** - * @param int|string|\DateTimeInterface $input + * @param int|string|DateTimeInterface $input + * @throws Exception + * * @dataProvider dateTimeInputDataProvider */ public function testGmtTimestamp($input) { - /** @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject $timezone */ + /** @var TimezoneInterface|MockObject $timezone */ $timezone = $this->getMockBuilder(TimezoneInterface::class)->getMock(); $timezone->method('date')->willReturn(new \DateTime($this->testDate)); @@ -33,12 +40,14 @@ public function testGmtTimestamp($input) } /** - * @param int|string|\DateTimeInterface $input + * @param int|string|DateTimeInterface $input + * @throws Exception + * * @dataProvider dateTimeInputDataProvider */ public function testTimestamp($input) { - /** @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject $timezone */ + /** @var TimezoneInterface|MockObject $timezone */ $timezone = $this->getMockBuilder(TimezoneInterface::class)->getMock(); $timezone->method('date')->willReturn(new \DateTime($this->testDate)); @@ -48,29 +57,50 @@ public function testTimestamp($input) public function testGtmOffset() { - /** @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject $timezone */ + /** @var TimezoneInterface|MockObject $timezone */ $timezone = $this->getMockBuilder(TimezoneInterface::class)->getMock(); - // Asia/Tbilisi timezone have no DST - $timezone->method('getConfigTimezone')->willReturn('Asia/Tbilisi'); + $timezone->method('getConfigTimezone')->willReturn('Europe/Amsterdam'); - /** @var DateTime|\PHPUnit_Framework_MockObject_MockObject $dateTime */ + /** @var DateTime|MockObject $dateTime */ $dateTime = $this->getMockBuilder(DateTime::class) ->setConstructorArgs([$timezone]) ->setMethods(null) ->getMock(); - $this->assertEquals(14400, $dateTime->getGmtOffset()); + $this->assertEquals( + $this->getExpectedGtmOffset($timezone->getConfigTimezone()), + $dateTime->getGmtOffset() + ); } /** + * Returns expected offset according to Daylight Saving Time in timezone + * + * @param string $timezoneIdentifier + * @return int + */ + private function getExpectedGtmOffset(string $timezoneIdentifier): int + { + $timeZoneToReturn = date_default_timezone_get(); + date_default_timezone_set($timezoneIdentifier); + $expectedOffset = (date('I', time()) + 1) * 3600; + date_default_timezone_set($timeZoneToReturn); + + return (int) $expectedOffset; + } + + /** + * Data provider + * * @return array + * @throws Exception */ public function dateTimeInputDataProvider() { return [ 'string' => [$this->testDate], 'int' => [strtotime($this->testDate)], - \DateTimeInterface::class => [new \DateTimeImmutable($this->testDate)], + DateTimeInterface::class => [new DateTimeImmutable($this->testDate)], ]; } } diff --git a/setup/src/Magento/Setup/Controller/Navigation.php b/setup/src/Magento/Setup/Controller/Navigation.php index c1d42d905b3eb..e3f2091accbbd 100644 --- a/setup/src/Magento/Setup/Controller/Navigation.php +++ b/setup/src/Magento/Setup/Controller/Navigation.php @@ -8,8 +8,11 @@ use Laminas\Mvc\Controller\AbstractActionController; use Laminas\View\Model\JsonModel; use Laminas\View\Model\ViewModel; +use Magento\Backend\Model\UrlInterface; +use Magento\Framework\ObjectManagerInterface; use Magento\Setup\Model\Cron\Status; use Magento\Setup\Model\Navigation as NavModel; +use Magento\Setup\Model\ObjectManagerProvider; /** * Navigation controller @@ -32,13 +35,20 @@ class Navigation extends AbstractActionController protected $view; /** - * @param NavModel $navigation - * @param Status $status + * @var ObjectManagerInterface */ - public function __construct(NavModel $navigation, Status $status) + private $objectManagerProvider; + + /** + * @param NavModel $navigation + * @param Status $status + * @param ObjectManagerProvider $objectManagerProvider + */ + public function __construct(NavModel $navigation, Status $status, ObjectManagerProvider $objectManagerProvider) { $this->navigation = $navigation; $this->status = $status; + $this->objectManagerProvider = $objectManagerProvider->get(); $this->view = new ViewModel(); $this->view->setVariable('menu', $this->navigation->getMenuItems()); $this->view->setVariable('main', $this->navigation->getMainItems()); @@ -80,8 +90,11 @@ public function menuAction() */ public function sideMenuAction() { + /** @var UrlInterface $backendUrl */ + $backendUrl = $this->objectManagerProvider->get(UrlInterface::class); $this->view->setTemplate('/magento/setup/navigation/side-menu.phtml'); $this->view->setVariable('isInstaller', $this->navigation->getType() == NavModel::NAV_INSTALLER); + $this->view->setVariable('backendUrl', $backendUrl->getRouteUrl('adminhtml')); $this->view->setTerminal(true); return $this->view; } diff --git a/setup/view/magento/setup/navigation/side-menu.phtml b/setup/view/magento/setup/navigation/side-menu.phtml index f34a6c7c72e69..b731881e8bf4f 100644 --- a/setup/view/magento/setup/navigation/side-menu.phtml +++ b/setup/view/magento/setup/navigation/side-menu.phtml @@ -20,9 +20,11 @@ ng-show="<?= implode( '&&', $expressions) ?>" > <nav class="admin__menu" ng-controller="mainController"> - <span class="logo logo-static" data-edition="Community Edition"> - <img class="logo-img" src="<?= $this->basePath() ?>/pub/images/logo.svg" alt="Magento Admin Panel"> - </span> + <a href="<?= $this->backendUrl ?>" class="logo" data-edition="Community Edition"> + <span> + <img class="logo-img" src="<?= $this->basePath() ?>/pub/images/logo.svg" alt="Magento Admin Panel"> + </span> + </a> <ul id="nav" role="menubar"> <li class="item-home level-0" ng-class="{_active: $state.current.name === 'root.home'}"> <a href="" ui-sref="root.home">