diff --git a/app/code/Magento/Checkout/Block/Total/Nominal.php b/app/code/Magento/Checkout/Block/Total/Nominal.php deleted file mode 100644 index f390c315bae5e..0000000000000 --- a/app/code/Magento/Checkout/Block/Total/Nominal.php +++ /dev/null @@ -1,141 +0,0 @@ -priceCurrency = $priceCurrency; - parent::__construct($context, $customerSession, $checkoutSession, $salesConfig, $data); - } - - /** - * Getter for a quote item name - * - * @param \Magento\Sales\Model\Quote\Item\AbstractItem $quoteItem - * @return string - */ - public function getItemName(\Magento\Sales\Model\Quote\Item\AbstractItem $quoteItem) - { - return $quoteItem->getName(); - } - - /** - * Getter for a quote item row total - * - * @param \Magento\Sales\Model\Quote\Item\AbstractItem $quoteItem - * @return float - */ - public function getItemRowTotal(\Magento\Sales\Model\Quote\Item\AbstractItem $quoteItem) - { - return $quoteItem->getNominalRowTotal(); - } - - /** - * Getter for nominal total item details - * - * @param \Magento\Sales\Model\Quote\Item\AbstractItem $quoteItem - * @return array - */ - public function getTotalItemDetails(\Magento\Sales\Model\Quote\Item\AbstractItem $quoteItem) - { - return $quoteItem->getNominalTotalDetails(); - } - - /** - * Getter for details row label - * - * @param \Magento\Framework\Object $row - * @return string - */ - public function getItemDetailsRowLabel(\Magento\Framework\Object $row) - { - return $row->getLabel(); - } - - /** - * Getter for details row amount - * - * @param \Magento\Framework\Object $row - * @return string - */ - public function getItemDetailsRowAmount(\Magento\Framework\Object $row) - { - return $row->getAmount(); - } - - /** - * Getter for details row compounded state - * - * @param \Magento\Framework\Object $row - * @return bool - */ - public function getItemDetailsRowIsCompounded(\Magento\Framework\Object $row) - { - return $row->getIsCompounded(); - } - - /** - * Format an amount without container - * - * @param float $amount - * @return string - */ - public function formatPrice($amount) - { - return $this->priceCurrency->format($amount, false); - } - - /** - * Import total data into the block, if there are items - * - * @return string - */ - protected function _toHtml() - { - $total = $this->getTotal(); - $items = $total->getItems(); - if ($items) { - foreach ($total->getData() as $key => $value) { - $this->setData("total_{$key}", $value); - } - return parent::_toHtml(); - } - return ''; - } -} diff --git a/app/code/Magento/Checkout/Model/Type/Onepage.php b/app/code/Magento/Checkout/Model/Type/Onepage.php index c49669e912c33..6e9925c2c5192 100644 --- a/app/code/Magento/Checkout/Model/Type/Onepage.php +++ b/app/code/Magento/Checkout/Model/Type/Onepage.php @@ -431,7 +431,7 @@ public function saveBilling($data, $customerAddressId) $address = $this->getQuote()->getBillingAddress(); } - if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) { + if (!$this->getQuote()->getCustomerId() && $this->isCheckoutMethodRegister()) { if ($this->_customerEmailExists($address->getEmail(), $this->_storeManager->getWebsite()->getId())) { return [ 'error' => 1, @@ -492,13 +492,19 @@ public function saveBilling($data, $customerAddressId) )->setCollectShippingRates( true )->collectTotals(); - $shipping->save(); + if (!$this->isCheckoutMethodRegister()) { + $shipping->save(); + } $this->getCheckout()->setStepData('shipping', 'complete', true); break; } } - $this->quoteRepository->save($this->getQuote()); + if ($this->isCheckoutMethodRegister()) { + $this->quoteRepository->save($this->getQuote()); + } else { + $address->save(); + } $this->getCheckout()->setStepData( 'billing', @@ -517,6 +523,16 @@ public function saveBilling($data, $customerAddressId) return []; } + /** + * Check whether checkout method is "register" + * + * @return bool + */ + protected function isCheckoutMethodRegister() + { + return $this->getQuote()->getCheckoutMethod() == self::METHOD_REGISTER; + } + /** * Validate customer data and set some its data for further usage in quote * diff --git a/app/code/Magento/Checkout/etc/sales.xml b/app/code/Magento/Checkout/etc/sales.xml deleted file mode 100644 index 69ebcbc6f04e1..0000000000000 --- a/app/code/Magento/Checkout/etc/sales.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - -
- - - - - -
-
diff --git a/app/code/Magento/Checkout/view/frontend/templates/total/nominal.phtml b/app/code/Magento/Checkout/view/frontend/templates/total/nominal.phtml deleted file mode 100644 index 13adb333776cb..0000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/total/nominal.phtml +++ /dev/null @@ -1,33 +0,0 @@ - - - - getRenderingArea() == $this->getTotalArea()) ? '%s' : '%s', $this->escapeHtml($this->getTotalTitle())) ?> - - -getTotalItems() as $i => $item): ?> - getTotalItemDetails($item) as $j => $row):?> - - - escapeHtml($this->getItemDetailsRowLabel($row)) ?> - - - formatPrice($this->getItemDetailsRowAmount($row)) ?> - - - - - -
escapeHtml($this->getItemName($item)); ?>
- - - helper('Magento\Checkout\Helper\Data')->formatPrice($this->getItemRowTotal($item)) ?> - - - diff --git a/app/code/Magento/Multishipping/Helper/Data.php b/app/code/Magento/Multishipping/Helper/Data.php index 9df86f3b14250..3d85088207977 100644 --- a/app/code/Magento/Multishipping/Helper/Data.php +++ b/app/code/Magento/Multishipping/Helper/Data.php @@ -87,7 +87,6 @@ public function isMultishippingCheckoutAvailable() true ) && $quote->getItemsSummaryQty() - $quote->getItemVirtualQty() > 0 && - $quote->getItemsSummaryQty() <= $this->getMaximumQty() && - !$quote->hasNominalItems(); + $quote->getItemsSummaryQty() <= $this->getMaximumQty(); } } diff --git a/app/code/Magento/Payment/Model/Cart/SalesModel/Quote.php b/app/code/Magento/Payment/Model/Cart/SalesModel/Quote.php index dd6d7e16f1434..cde66236a50e9 100644 --- a/app/code/Magento/Payment/Model/Cart/SalesModel/Quote.php +++ b/app/code/Magento/Payment/Model/Cart/SalesModel/Quote.php @@ -50,7 +50,7 @@ public function getAllItems() 'parent_item' => $item->getParentItem(), 'name' => $item->getName(), 'qty' => (int)$item->getTotalQty(), - 'price' => $item->isNominal() ? 0 : (double)$item->getBaseCalculationPrice(), + 'price' => (double)$item->getBaseCalculationPrice(), 'original_item' => $item, ] ); diff --git a/app/code/Magento/Sales/Api/Data/OrderItemInterface.php b/app/code/Magento/Sales/Api/Data/OrderItemInterface.php index 5532e6f6f878f..2b8d76a0350b3 100644 --- a/app/code/Magento/Sales/Api/Data/OrderItemInterface.php +++ b/app/code/Magento/Sales/Api/Data/OrderItemInterface.php @@ -266,11 +266,7 @@ interface OrderItemInterface extends \Magento\Framework\Api\ExtensibleDataInterf */ const BASE_HIDDEN_TAX_REFUNDED = 'base_hidden_tax_refunded'; /* - * Is-nominal flag. - */ - const IS_NOMINAL = 'is_nominal'; - /* - * Tax-canceled flag. + * Tax canceled flag */ const TAX_CANCELED = 'tax_canceled'; /* @@ -751,13 +747,6 @@ public function getHiddenTaxInvoiced(); */ public function getHiddenTaxRefunded(); - /** - * Gets the is-nominal flag value for the order item. - * - * @return int Is-nominal flag value. - */ - public function getIsNominal(); - /** * Gets the is-quantity-decimal flag value for the order item. * diff --git a/app/code/Magento/Sales/Model/Config.php b/app/code/Magento/Sales/Model/Config.php index 086decbdad64a..b7a4606b61cb2 100644 --- a/app/code/Magento/Sales/Model/Config.php +++ b/app/code/Magento/Sales/Model/Config.php @@ -49,7 +49,7 @@ public function getTotalsRenderer($section, $group, $code) /** * Retrieve totals for group - * e.g. quote, nominal_totals, etc + * e.g. quote, etc * * @param string $section * @param string $group diff --git a/app/code/Magento/Sales/Model/Config/Converter.php b/app/code/Magento/Sales/Model/Config/Converter.php index 1c28d520bbba5..7529fc9d34c37 100644 --- a/app/code/Magento/Sales/Model/Config/Converter.php +++ b/app/code/Magento/Sales/Model/Config/Converter.php @@ -5,7 +5,7 @@ */ /** - * Converts sales totals (incl. nominal, creditmemo, invoice) from \DOMDocument to array + * Converts sales totals (incl. creditmemo, invoice) from \DOMDocument to array */ namespace Magento\Sales\Model\Config; diff --git a/app/code/Magento/Sales/Model/Config/Reader.php b/app/code/Magento/Sales/Model/Config/Reader.php index 415bd0458ddf7..8922b4756e186 100644 --- a/app/code/Magento/Sales/Model/Config/Reader.php +++ b/app/code/Magento/Sales/Model/Config/Reader.php @@ -5,7 +5,7 @@ */ /** - * Sales configuration filesystem loader. Loads all totals (incl. nominal, creditmemo, invoice) + * Sales configuration filesystem loader. Loads all totals (incl. creditmemo, invoice) * configuration from XML file */ namespace Magento\Sales\Model\Config; diff --git a/app/code/Magento/Sales/Model/ConfigInterface.php b/app/code/Magento/Sales/Model/ConfigInterface.php index 6fe4b3ae37436..89d359b405e60 100644 --- a/app/code/Magento/Sales/Model/ConfigInterface.php +++ b/app/code/Magento/Sales/Model/ConfigInterface.php @@ -19,7 +19,7 @@ public function getTotalsRenderer($section, $group, $code); /** * Retrieve totals for group - * e.g. quote, nominal_totals, etc + * e.g. quote, etc * * @param string $section * @param string $group diff --git a/app/code/Magento/Sales/Model/Order.php b/app/code/Magento/Sales/Model/Order.php index 5daad893b4934..33085bcd11296 100644 --- a/app/code/Magento/Sales/Model/Order.php +++ b/app/code/Magento/Sales/Model/Order.php @@ -802,6 +802,10 @@ public function canEdit() return false; } + if ($this->hasInvoices()) { + return false; + } + if (!$this->getPayment()->getMethodInstance()->canEdit()) { return false; } @@ -1491,21 +1495,6 @@ public function addItem(\Magento\Sales\Model\Order\Item $item) return $this; } - /** - * Whether the order has nominal items only - * - * @return bool - */ - public function isNominal() - { - foreach ($this->getAllVisibleItems() as $item) { - if ('0' == $item->getIsNominal()) { - return false; - } - } - return true; - } - /*********************** PAYMENTS ***************************/ /** @@ -1821,6 +1810,18 @@ public function getInvoiceCollection() return $this->_invoices; } + /** + * Set order invoices collection + * + * @param InvoiceCollection $invoices + * @return $this + */ + public function setInvoiceCollection(InvoiceCollection $invoices) + { + $this->_invoices = $invoices; + return $this; + } + /** * Retrieve order shipments collection * diff --git a/app/code/Magento/Sales/Model/Order/Item.php b/app/code/Magento/Sales/Model/Order/Item.php index aeeb47d00f218..d0ad825fea617 100644 --- a/app/code/Magento/Sales/Model/Order/Item.php +++ b/app/code/Magento/Sales/Model/Order/Item.php @@ -88,7 +88,6 @@ * @method \Magento\Sales\Model\Order\Item setBaseHiddenTaxInvoiced(float $value) * @method \Magento\Sales\Model\Order\Item setHiddenTaxRefunded(float $value) * @method \Magento\Sales\Model\Order\Item setBaseHiddenTaxRefunded(float $value) - * @method \Magento\Sales\Model\Order\Item setIsNominal(int $value) * @method \Magento\Sales\Model\Order\Item setTaxCanceled(float $value) * @method \Magento\Sales\Model\Order\Item setHiddenTaxCanceled(float $value) * @method \Magento\Sales\Model\Order\Item setTaxRefunded(float $value) @@ -1272,16 +1271,6 @@ public function getHiddenTaxRefunded() return $this->getData(OrderItemInterface::HIDDEN_TAX_REFUNDED); } - /** - * Returns is_nominal - * - * @return int - */ - public function getIsNominal() - { - return $this->getData(OrderItemInterface::IS_NOMINAL); - } - /** * Returns is_qty_decimal * diff --git a/app/code/Magento/Sales/Model/Order/Payment.php b/app/code/Magento/Sales/Model/Order/Payment.php index fa245e8ce5302..c1c956a50b92e 100644 --- a/app/code/Magento/Sales/Model/Order/Payment.php +++ b/app/code/Magento/Sales/Model/Order/Payment.php @@ -378,7 +378,7 @@ protected function processAction($action, \Magento\Sales\Model\Order $order) $this->_order($baseTotalDue); break; case \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE: - $this->_authorize(true, $baseTotalDue); + $this->authorize(true, $baseTotalDue); // base amount will be set inside $this->setAmountAuthorized($totalDue); break; @@ -471,12 +471,9 @@ public function capture($invoice) $invoice->setIsPaid(true); $this->_updateTotals(['base_amount_paid_online' => $amountToCapture]); } - if ($order->isNominal()) { - $message = $this->_prependMessage(__('An order with subscription items was registered.')); - } else { - $message = $this->_prependMessage($message); - $message = $this->_appendTransactionToMessage($transaction, $message); - } + $message = $this->_prependMessage($message); + $message = $this->_appendTransactionToMessage($transaction, $message); + $order->setState($state, $status, $message); $this->getMethodInstance()->processInvoice($invoice, $this); return $this; @@ -575,7 +572,7 @@ public function registerCaptureNotification($amount, $skipFraudDetection = false */ public function registerAuthorizationNotification($amount) { - return $this->_isTransactionExists() ? $this : $this->_authorize(false, $amount); + return $this->_isTransactionExists() ? $this : $this->authorize(false, $amount); } /** @@ -1129,9 +1126,10 @@ protected function _order($amount) * * @param bool $isOnline * @param float $amount + * * @return $this */ - protected function _authorize($isOnline, $amount) + public function authorize($isOnline, $amount) { // check for authorization amount to be equal to grand total $this->setShouldCloseParentTransaction(false); @@ -1155,13 +1153,14 @@ protected function _authorize($isOnline, $amount) // similar logic of "payment review" order as in capturing if ($this->getIsTransactionPending()) { + $state = \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW; $message = __( 'We will authorize %1 after the payment is approved at the payment gateway.', $this->_formatPrice($amount) ); - $state = \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW; } else { if ($this->getIsFraudDetected()) { + $state = \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW; $message = __( 'Order is suspended as its authorizing amount %1 is suspected to be fraudulent.', $this->_formatPrice($amount, $this->getCurrencyCode()) @@ -1171,35 +1170,19 @@ protected function _authorize($isOnline, $amount) } } if ($this->getIsFraudDetected()) { - $state = \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW; $status = \Magento\Sales\Model\Order::STATUS_FRAUD; } // update transactions, order state and add comments $transaction = $this->_addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH); - if ($order->isNominal()) { - $message = $this->_prependMessage(__('An order with subscription items was registered.')); - } else { - $message = $this->_prependMessage($message); - $message = $this->_appendTransactionToMessage($transaction, $message); - } + $message = $this->_prependMessage($message); + $message = $this->_appendTransactionToMessage($transaction, $message); + $order->setState($state, $status, $message); return $this; } - /** - * Public access to _authorize method - * - * @param bool $isOnline - * @param float $amount - * @return $this - */ - public function authorize($isOnline, $amount) - { - return $this->_authorize($isOnline, $amount); - } - /** * Void payment either online or offline (process void notification) * NOTE: that in some cases authorization can be voided after a capture. In such case it makes sense to use diff --git a/app/code/Magento/Sales/Model/Quote.php b/app/code/Magento/Sales/Model/Quote.php index a34cc20245be5..5969c0ad6084c 100644 --- a/app/code/Magento/Sales/Model/Quote.php +++ b/app/code/Magento/Sales/Model/Quote.php @@ -1246,22 +1246,6 @@ public function removeAllItems() */ public function addItem(\Magento\Sales\Model\Quote\Item $item) { - /** - * Temporary workaround for purchase process: it is too dangerous to purchase more than one nominal item - * or a mixture of nominal and non-nominal items, although technically possible. - * - * The problem is that currently it is implemented as sequential submission of nominal items and order, - * by one click. It makes logically impossible to make the process of the purchase failsafe. - * Proper solution is to submit items one by one with customer confirmation each time. - */ - if ($item->isNominal() && $this->hasItems() || $this->hasNominalItems()) { - throw new \Magento\Framework\Model\Exception( - // @codingStandardsIgnoreStart - __('Sorry, but items with payment agreements must be ordered one at a time To continue, please remove or buy the other items in your cart, then order this item by itself.') - // @codingStandardsIgnoreEnd - ); - } - $item->setQuote($this); if (!$item->getId()) { $this->getItemsCollection()->addItem($item); @@ -2190,41 +2174,6 @@ public function merge(Quote $quote) return $this; } - /** - * Getter whether quote has nominal items - * Can bypass treating virtual items as nominal - * - * @param bool $countVirtual - * @return bool - */ - public function hasNominalItems($countVirtual = true) - { - foreach ($this->getAllVisibleItems() as $item) { - if ($item->isNominal()) { - if (!$countVirtual && $item->getProduct()->isVirtual()) { - continue; - } - return true; - } - } - return false; - } - - /** - * Whether quote has nominal items only - * - * @return bool - */ - public function isNominal() - { - foreach ($this->getAllVisibleItems() as $item) { - if (!$item->isNominal()) { - return false; - } - } - return true; - } - /** * @return $this */ diff --git a/app/code/Magento/Sales/Model/Quote/Address.php b/app/code/Magento/Sales/Model/Quote/Address.php index 8137f2d7174cb..b31a7ee3d7913 100644 --- a/app/code/Magento/Sales/Model/Quote/Address.php +++ b/app/code/Magento/Sales/Model/Quote/Address.php @@ -182,13 +182,6 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress */ protected $_baseTotalAmounts = []; - /** - * Whether to segregate by nominal items only - * - * @var bool - */ - protected $_nominalOnly = null; - /** * Core store config * @@ -571,23 +564,14 @@ public function getItemsCollection() */ public function getAllItems() { - // We calculate item list once and cache it in three arrays - all items, nominal, non-nominal - $cachedItems = $this->_nominalOnly ? 'nominal' : ($this->_nominalOnly === false ? 'nonnominal' : 'all'); + // We calculate item list once and cache it in three arrays - all items + $cachedItems = 'all'; $key = 'cached_items_' . $cachedItems; if (!$this->hasData($key)) { - // For compatibility we will use $this->_filterNominal to divide nominal items from non-nominal - // (because it can be overloaded) - // So keep current flag $this->_nominalOnly and restore it after cycle - $wasNominal = $this->_nominalOnly; - $this->_nominalOnly = true; - // Now $this->_filterNominal() will return positive values for nominal items - $quoteItems = $this->getQuote()->getItemsCollection(); $addressItems = $this->getItemsCollection(); $items = []; - $nominalItems = []; - $nonNominalItems = []; if ($this->getQuote()->getIsMultiShipping() && $addressItems->count() > 0) { foreach ($addressItems as $aItem) { if ($aItem->isDeleted()) { @@ -601,11 +585,6 @@ public function getAllItems() } } $items[] = $aItem; - if ($this->_filterNominal($aItem)) { - $nominalItems[] = $aItem; - } else { - $nonNominalItems[] = $aItem; - } } } else { /* @@ -622,21 +601,12 @@ public function getAllItems() continue; } $items[] = $qItem; - if ($this->_filterNominal($qItem)) { - $nominalItems[] = $qItem; - } else { - $nonNominalItems[] = $qItem; - } } } } // Cache calculated lists $this->setData('cached_items_all', $items); - $this->setData('cached_items_nominal', $nominalItems); - $this->setData('cached_items_nonnominal', $nonNominalItems); - - $this->_nominalOnly = $wasNominal; // Restore original value before we changed it } $items = $this->getData($key); @@ -644,51 +614,6 @@ public function getAllItems() return $items; } - /** - * Getter for all non-nominal items - * - * @return array - */ - public function getAllNonNominalItems() - { - $this->_nominalOnly = false; - $result = $this->getAllItems(); - $this->_nominalOnly = null; - return $result; - } - - /** - * Getter for all nominal items - * - * @return array - */ - public function getAllNominalItems() - { - $this->_nominalOnly = true; - $result = $this->getAllItems(); - $this->_nominalOnly = null; - - return $result; - } - - /** - * Segregate by nominal criteria - * - * Returns - * true: get nominals only - * false: get non-nominals only - * null: get all - * - * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item - * @return \Magento\Sales\Model\Quote\Item\AbstractItem|false - */ - protected function _filterNominal($item) - { - return null === $this->_nominalOnly || - false === $this->_nominalOnly && !$item->isNominal() || - true === $this->_nominalOnly && $item->isNominal() ? $item : false; - } - /** * Retrieve all visible items * @@ -861,9 +786,6 @@ public function getShippingRatesCollection() { if (null === $this->_rates) { $this->_rates = $this->_rateCollectionFactory->create()->setAddressFilter($this->getId()); - if ($this->getQuote()->hasNominalItems(false)) { - $this->_rates->setFixedOnlyFilter(true); - } if ($this->getId()) { foreach ($this->_rates as $rate) { $rate->setAddress($this); diff --git a/app/code/Magento/Sales/Model/Quote/Address/Total/AbstractTotal.php b/app/code/Magento/Sales/Model/Quote/Address/Total/AbstractTotal.php index b90abc626ed1e..d9c57affc69c0 100644 --- a/app/code/Magento/Sales/Model/Quote/Address/Total/AbstractTotal.php +++ b/app/code/Magento/Sales/Model/Quote/Address/Total/AbstractTotal.php @@ -188,14 +188,14 @@ protected function _addBaseAmount($baseAmount) } /** - * Get all items except nominals + * Get all items * * @param \Magento\Sales\Model\Quote\Address $address * @return array */ protected function _getAddressItems(\Magento\Sales\Model\Quote\Address $address) { - return $address->getAllNonNominalItems(); + return $address->getAllItems(); } /** diff --git a/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal.php b/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal.php deleted file mode 100644 index 7ad7aae70a71c..0000000000000 --- a/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal.php +++ /dev/null @@ -1,93 +0,0 @@ -_collectorFactory = $collectorFactory; - } - - /** - * Invoke collector for nominal items - * - * @param \Magento\Sales\Model\Quote\Address $address - * @return $this - */ - public function collect(\Magento\Sales\Model\Quote\Address $address) - { - $collector = $this->_collectorFactory->create(['store' => $address->getQuote()->getStore()]); - - // invoke nominal totals - foreach ($collector->getCollectors() as $model) { - $model->collect($address); - } - - // aggregate collected amounts into one to have sort of grand total per item - foreach ($address->getAllNominalItems() as $item) { - $rowTotal = 0; - $baseRowTotal = 0; - $totalDetails = []; - foreach ($collector->getCollectors() as $model) { - $itemRowTotal = $model->getItemRowTotal($item); - if ($model->getIsItemRowTotalCompoundable($item)) { - $rowTotal += $itemRowTotal; - $baseRowTotal += $model->getItemBaseRowTotal($item); - $isCompounded = true; - } else { - $isCompounded = false; - } - if ((double)$itemRowTotal > 0 && ($label = $model->getLabel())) { - $totalDetails[] = new \Magento\Framework\Object( - ['label' => $label, 'amount' => $itemRowTotal, 'is_compounded' => $isCompounded] - ); - } - } - $item->setNominalRowTotal($rowTotal); - $item->setBaseNominalRowTotal($baseRowTotal); - $item->setNominalTotalDetails($totalDetails); - } - - return $this; - } - - /** - * Fetch collected nominal items - * - * @param \Magento\Sales\Model\Quote\Address $address - * @return $this - */ - public function fetch(\Magento\Sales\Model\Quote\Address $address) - { - $items = $address->getAllNominalItems(); - if ($items) { - $address->addTotal( - [ - 'code' => $this->getCode(), - 'title' => __('Subscription Items'), - 'items' => $items, - 'area' => 'footer', - ] - ); - } - return $this; - } -} diff --git a/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal/Collector.php b/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal/Collector.php deleted file mode 100644 index 60846e18b796c..0000000000000 --- a/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal/Collector.php +++ /dev/null @@ -1,27 +0,0 @@ -getAllNominalItems(); - if (!count($items)) { - return $this; - } - - // estimate quote with all address items to get their row weights - $this->_shouldGetAllItems = true; - parent::collect($address); - $address->setCollectShippingRates(true); - $this->_shouldGetAllItems = false; - // now $items contains row weight information - - // collect shipping rates for each item individually - foreach ($items as $item) { - if (!$item->getProduct()->isVirtual()) { - $address->requestShippingRates($item); - $baseAmount = $item->getBaseShippingAmount(); - if ($baseAmount) { - $item->setShippingAmount( - $this->priceCurrency->convert($baseAmount, $address->getQuote()->getStore()) - ); - } - } - } - - return $this; - } - - /** - * Don't fetch anything - * - * @param \Magento\Sales\Model\Quote\Address $address - * @return array - */ - public function fetch(\Magento\Sales\Model\Quote\Address $address) - { - return \Magento\Sales\Model\Quote\Address\Total\AbstractTotal::fetch($address); - } - - /** - * Get nominal items only or indeed get all items, depending on current logic requirements - * - * @param \Magento\Sales\Model\Quote\Address $address - * @return array - */ - protected function _getAddressItems(\Magento\Sales\Model\Quote\Address $address) - { - if ($this->_shouldGetAllItems) { - return $address->getAllItems(); - } - return $address->getAllNominalItems(); - } -} diff --git a/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal/Subtotal.php b/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal/Subtotal.php deleted file mode 100644 index 9f43af1ebfa4f..0000000000000 --- a/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal/Subtotal.php +++ /dev/null @@ -1,59 +0,0 @@ -getAllNominalItems(); - } -} diff --git a/app/code/Magento/Sales/Model/Quote/Item/AbstractItem.php b/app/code/Magento/Sales/Model/Quote/Item/AbstractItem.php index e40981592423c..2a2340f2e9b89 100644 --- a/app/code/Magento/Sales/Model/Quote/Item/AbstractItem.php +++ b/app/code/Magento/Sales/Model/Quote/Item/AbstractItem.php @@ -484,28 +484,6 @@ public function getBaseCalculationPriceOriginal() return $this->_getData('base_calculation_price'); } - /** - * Get whether the item is nominal - * TODO: fix for multishipping checkout - * - * @return bool - */ - public function isNominal() - { - return false; - } - - /** - * Data getter for 'is_nominal' - * Used for converting item to order item - * - * @return int - */ - public function getIsNominal() - { - return (int)$this->isNominal(); - } - /** * Get original price (retrieved from product) for item. * Original price value is in quote selected currency diff --git a/app/code/Magento/Sales/Model/Service/Quote.php b/app/code/Magento/Sales/Model/Service/Quote.php index e87ff919c1b1f..f5aa07a01436e 100644 --- a/app/code/Magento/Sales/Model/Service/Quote.php +++ b/app/code/Magento/Sales/Model/Service/Quote.php @@ -40,7 +40,7 @@ class Quote protected $_order = null; /** - * If it is true, quote will be inactivate after submitting order or nominal items + * If it is true, quote will be inactivate after submitting order * * @var bool */ @@ -213,7 +213,6 @@ protected function prepareCustomerData(\Magento\Sales\Model\Quote $quote) */ public function submitOrderWithDataObject() { - $this->_deleteNominalItems(); $this->_validate(); $quote = $this->_quote; $isVirtual = $quote->isVirtual(); @@ -302,22 +301,6 @@ public function submitOrderWithDataObject() return $order; } - /** - * Submit nominal items - * - * @return void - */ - public function submitNominalItems() - { - $this->_validate(); - $this->_eventManager->dispatch( - 'sales_model_service_quote_submit_nominal_items', - ['quote' => $this->_quote] - ); - $this->_inactivateQuote(); - $this->_deleteNominalItems(); - } - /** * Submit all available items * All created items will be set to the object @@ -327,16 +310,6 @@ public function submitNominalItems() */ public function submitAllWithDataObject() { - // don't allow submitNominalItems() to inactivate quote - $inactivateQuoteOld = $this->_shouldInactivateQuote; - $this->_shouldInactivateQuote = false; - try { - $this->submitNominalItems(); - $this->_shouldInactivateQuote = $inactivateQuoteOld; - } catch (\Exception $e) { - $this->_shouldInactivateQuote = $inactivateQuoteOld; - throw $e; - } // no need to submit the order if there are no normal items remained if (!$this->_quote->getAllVisibleItems()) { $this->_inactivateQuote(); @@ -404,18 +377,4 @@ protected function _validate() return $this; } - - /** - * Get rid of all nominal items - * - * @return void - */ - protected function _deleteNominalItems() - { - foreach ($this->_quote->getAllVisibleItems() as $item) { - if ($item->isNominal()) { - $item->isDeleted(true); - } - } - } } diff --git a/app/code/Magento/Sales/etc/fieldset.xml b/app/code/Magento/Sales/etc/fieldset.xml index efd1f230bc688..0c2601c754313 100644 --- a/app/code/Magento/Sales/etc/fieldset.xml +++ b/app/code/Magento/Sales/etc/fieldset.xml @@ -479,9 +479,6 @@ - - -
diff --git a/app/code/Magento/Sales/etc/sales.xml b/app/code/Magento/Sales/etc/sales.xml index 160026e5378e1..da0699d53c17f 100644 --- a/app/code/Magento/Sales/etc/sales.xml +++ b/app/code/Magento/Sales/etc/sales.xml @@ -8,15 +8,10 @@
- - - - -
diff --git a/app/code/Magento/Sales/sql/sales_setup/install-2.0.0.php b/app/code/Magento/Sales/sql/sales_setup/install-2.0.0.php index dc37eadc6f05a..87dfff6eaa459 100644 --- a/app/code/Magento/Sales/sql/sales_setup/install-2.0.0.php +++ b/app/code/Magento/Sales/sql/sales_setup/install-2.0.0.php @@ -1635,12 +1635,6 @@ '12,4', [], 'Base Hidden Tax Refunded' -)->addColumn( - 'is_nominal', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'default' => '0'], - 'Is Nominal' )->addColumn( 'tax_canceled', \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, diff --git a/app/code/Magento/Sales/sql/sales_setup/update-2.0.1.php b/app/code/Magento/Sales/sql/sales_setup/update-2.0.1.php new file mode 100644 index 0000000000000..c8961b1ba40e9 --- /dev/null +++ b/app/code/Magento/Sales/sql/sales_setup/update-2.0.1.php @@ -0,0 +1,13 @@ +startSetup(); +/** + * update table 'sales_order_item' + */ +$table = $this->getConnection()->dropColumn('sales_order_item', 'is_nominal'); +$this->endSetup(); diff --git a/app/code/Magento/SalesRule/Model/Quote/Nominal/Discount.php b/app/code/Magento/SalesRule/Model/Quote/Nominal/Discount.php deleted file mode 100644 index d9ef3cf20eba0..0000000000000 --- a/app/code/Magento/SalesRule/Model/Quote/Nominal/Discount.php +++ /dev/null @@ -1,41 +0,0 @@ -getAllNominalItems(); - } -} diff --git a/app/code/Magento/SalesRule/etc/sales.xml b/app/code/Magento/SalesRule/etc/sales.xml index b23e9ccc33ed2..7c9005f1e6ba5 100644 --- a/app/code/Magento/SalesRule/etc/sales.xml +++ b/app/code/Magento/SalesRule/etc/sales.xml @@ -10,8 +10,5 @@ - - -
diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/Nominal/Subtotal.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/Nominal/Subtotal.php deleted file mode 100644 index 033d98c5b69fc..0000000000000 --- a/app/code/Magento/Tax/Model/Sales/Total/Quote/Nominal/Subtotal.php +++ /dev/null @@ -1,42 +0,0 @@ -getAllNominalItems(); - } -} diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/Nominal/Tax.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/Nominal/Tax.php deleted file mode 100644 index 3aa0f418f436c..0000000000000 --- a/app/code/Magento/Tax/Model/Sales/Total/Quote/Nominal/Tax.php +++ /dev/null @@ -1,67 +0,0 @@ -getAllNominalItems(); - } - - /** - * Process model configuration array - * - * This method can be used for changing totals collect sort order - * - * @param array $config - * @param int|string|\Magento\Store\Model\Store $store - * @return array - */ - public function processConfigArray($config, $store) - { - /** - * Nominal totals use sort_order configuration node to define the order (not before or after nodes) - * If there is a requirement to change the order, in which nominal total is calculated, change sort_order - */ - return $config; - } -} diff --git a/app/code/Magento/Tax/etc/sales.xml b/app/code/Magento/Tax/etc/sales.xml index 20d55ea6060a2..c1e211e9c4f18 100644 --- a/app/code/Magento/Tax/etc/sales.xml +++ b/app/code/Magento/Tax/etc/sales.xml @@ -31,9 +31,5 @@ - - - - diff --git a/app/code/Magento/Weee/Model/Total/Quote/Nominal/Weee.php b/app/code/Magento/Weee/Model/Total/Quote/Nominal/Weee.php deleted file mode 100644 index 781d8d7085913..0000000000000 --- a/app/code/Magento/Weee/Model/Total/Quote/Nominal/Weee.php +++ /dev/null @@ -1,38 +0,0 @@ -getAllNominalItems(); - } -} diff --git a/app/code/Magento/Weee/etc/sales.xml b/app/code/Magento/Weee/etc/sales.xml index 04a5528f988dd..586c3588ed7a4 100644 --- a/app/code/Magento/Weee/etc/sales.xml +++ b/app/code/Magento/Weee/etc/sales.xml @@ -11,9 +11,6 @@ - - -
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php index a7d1caa2023ce..8b2db1eafdbce 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php @@ -6,8 +6,6 @@ */ namespace Magento\Framework\Interception; -use Magento\Framework\ObjectManager\Config\Config as ObjectManagerConfig; - /** * Class GeneralTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Core/Model/Fieldset/_files/fieldset.xml b/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Core/Model/Fieldset/_files/fieldset.xml index 8ba436ce08bd6..120bafba36ad6 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Core/Model/Fieldset/_files/fieldset.xml +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Core/Model/Fieldset/_files/fieldset.xml @@ -479,9 +479,6 @@ - - - diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Core/Model/Fieldset/_files/invalid_fieldset.xml b/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Core/Model/Fieldset/_files/invalid_fieldset.xml index f82f02292c78a..8fba3db47c123 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Core/Model/Fieldset/_files/invalid_fieldset.xml +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/Magento/Core/Model/Fieldset/_files/invalid_fieldset.xml @@ -479,9 +479,6 @@ * - - * - * diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 553c41e4a1dfd..5081d8b97e99d 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -2845,4 +2845,12 @@ ['Magento\Framework\App\Cache\State\Options', 'Magento\Framework\App\Cache\State'], ['Magento\Framework\App\Cache\State\OptionsInterface', 'Magento\Framework\App\Cache\State'], ['Magento\Framework\Logger', 'Psr\Log\LoggerInterface'], + ['Magento\Weee\Model\Total\Quote\Nominal\Weee'], + ['Magento\Tax\Model\Sales\Total\Quote\Nominal\Tax'], + ['Magento\Tax\Model\Sales\Total\Quote\Nominal\Subtotal'], + ['Magento\SalesRule\Model\Quote\Nominal\Discount'], + ['Magento\Sales\Model\Quote\Address\Total\Nominal'], + ['Magento\Sales\Model\Quote\Address\Total\Nominal\Collector'], + ['Magento\Sales\Model\Quote\Address\Total\Nominal\Shipping'], + ['Magento\Sales\Model\Quote\Address\Total\Nominal\Subtotal'], ]; diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index 318e38dd9454e..d3bd171fec9b7 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -1659,6 +1659,7 @@ ['_isDataChanged', 'Magento\Catalog\Model\Product'], ['getVisibleOnFrontStates', 'Magento\Sales\Model\Order\Config', 'getVisibleOnFrontStatuses'], ['getInvisibleOnFrontStates', 'Magento\Sales\Model\Order\Config', 'getInvisibleOnFrontStatuses'], + ['_authorize', 'Magento\Sales\Model\Order\Payment'], ['_shouldBeConverted', 'Magento\Sales\Model\Resource\AbstractResource'], ['_beforeSave', 'Magento\Sales\Model\Resource\AbstractResource'], ['_afterSave', 'Magento\Sales\Model\Resource\AbstractResource'], @@ -2021,5 +2022,9 @@ ['getIsNullNotNullCondition', 'Magento\Catalog\Model\Resource\Helper'], ['_getCategoryPath', 'Magento\Catalog\Model\Resource\Setup'], ['_getCategoryEntityRow', 'Magento\Catalog\Model\Resource\Setup'], - ['createEavAttributeResource', 'Magento\Catalog\Model\Resource\Setup'] + ['createEavAttributeResource', 'Magento\Catalog\Model\Resource\Setup'], + ['getAllNonNominalItems', 'Magento\Sales\Model\Quote\Address'], + ['getAllNominalItems', 'Magento\Sales\Model\Quote\Address'], + ['isNominal', 'Magento\Sales\Model\Order\Item'], + ['getIsNominal', 'Magento\Sales\Model\Quote\Item\AbbstractItem'] ]; diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_paths.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_paths.php index 4057ba46de443..7ae96fdd6f596 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_paths.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_paths.php @@ -234,4 +234,12 @@ ['/app/etc/local.xml', '/app/etc/config.php'], ['/app/code/Magento/RecurringPayment'], ['/app/code/Magento/PayPalRecurringPayment'], + ['/app/code/Magento/Weee/Model/Total/Quote/Nominal/Weee.php'], + ['/app/code/Magento/Tax/Model/Sales/Total/Quote/Nominal/Subtotal.php'], + ['/app/code/Magento/Tax/Model/Sales/Total/Quote/Nominal/Tax.php'], + ['/app/code/Magento/SalesRule/Model/Quote/Nominal/Discount.php'], + ['/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal.php'], + ['/app/code/Magento/Sales/Model/Quote/Address/Total/Nominal'], + ['/app/code/Magento/Checkout/Block/Total/Nominal.php'], + ['/app/code/Magento/Checkout/etc/sales.xml'], ]; diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt index 083fbe5c84c2f..ccd0a6929c467 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt @@ -113,8 +113,6 @@ lib/internal/Magento/Framework/App/Config Magento/Cron/Model Magento/SalesRule/Model/Resource/Report/Rule Magento/SalesRule/Model/Resource/Rule -Magento/SalesRule/Model/Quote/Nominal -Magento/Tax/Model/Sales/Total/Quote/Nominal Magento/Theme/Block/Adminhtml/System/Design/Theme/Edit Magento/User/Block/User/Edit var/generation @@ -144,4 +142,4 @@ app/code/Magento/Sales/Model/Spi Magento/Catalog/Model/ProductLink Magento/GroupedProduct/Model/Resource/Product/Type/Grouped lib/internal/Magento/Framework/Interception/ObjectManager/Config -app/code/Magento/OfflinePayments/Model \ No newline at end of file +app/code/Magento/OfflinePayments/Model diff --git a/dev/tests/unit/testsuite/Magento/Checkout/Model/Type/OnepageTest.php b/dev/tests/unit/testsuite/Magento/Checkout/Model/Type/OnepageTest.php index 6985c63f98be2..1030fee677e52 100644 --- a/dev/tests/unit/testsuite/Magento/Checkout/Model/Type/OnepageTest.php +++ b/dev/tests/unit/testsuite/Magento/Checkout/Model/Type/OnepageTest.php @@ -47,8 +47,8 @@ class OnepageTest extends \PHPUnit_Framework_TestCase /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $addressFactoryMock; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $formFactoryMock; + /** @var \Magento\Customer\Model\FormFactory|\PHPUnit_Framework_MockObject_MockObject */ + protected $customerFormFactoryMock; /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $customerFactoryMock; @@ -66,7 +66,7 @@ class OnepageTest extends \PHPUnit_Framework_TestCase protected $messageManagerMock; /** @var \Magento\Customer\Model\Metadata\FormFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $customerFormFactoryMock; + protected $formFactoryMock; /** @var \Magento\Customer\Api\Data\CustomerDataBuilder|\PHPUnit_Framework_MockObject_MockObject */ protected $customerBuilderMock; @@ -135,7 +135,7 @@ protected function setUp() ['isAjax', 'getModuleName', 'setModuleName', 'getActionName', 'setActionName', 'getParam', 'getCookie'] ); $this->addressFactoryMock = $this->getMock('Magento\Customer\Model\AddressFactory', [], [], '', false); - $this->formFactoryMock = $this->getMock('Magento\Customer\Model\FormFactory', [], [], '', false); + $this->formFactoryMock = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', [], [], '', false); $this->customerFactoryMock = $this->getMock('Magento\Customer\Model\CustomerFactory', [], [], '', false); $this->quoteFactoryMock = $this->getMock('Magento\Sales\Model\Service\QuoteFactory', [], [], '', false); $this->orderFactoryMock = $this->getMock('Magento\Sales\Model\OrderFactory', ['create'], [], '', false); @@ -143,7 +143,7 @@ protected function setUp() $this->messageManagerMock = $this->getMock('Magento\Framework\Message\ManagerInterface'); $this->customerFormFactoryMock = $this->getMock( - 'Magento\Customer\Model\Metadata\FormFactory', + 'Magento\Customer\Model\FormFactory', ['create'], [], '', @@ -213,13 +213,13 @@ protected function setUp() 'storeManager' => $this->storeManagerMock, 'request' => $this->requestMock, 'customrAddrFactory' => $this->addressFactoryMock, - 'customerFormFactory' => $this->formFactoryMock, + 'customerFormFactory' => $this->customerFormFactoryMock, 'customerFactory' => $this->customerFactoryMock, 'serviceQuoteFactory' => $this->quoteFactoryMock, 'orderFactory' => $this->orderFactoryMock, 'objectCopyService' => $this->copyMock, 'messageManager' => $this->messageManagerMock, - 'formFactory' => $this->customerFormFactoryMock, + 'formFactory' => $this->formFactoryMock, 'customerBuilder' => $this->customerBuilderMock, 'addressBuilder' => $this->addressBuilderMock, 'mathRandom' => $this->randomMock, @@ -397,6 +397,8 @@ public function testSaveBilling( $getStepDataResult, $expected ) { + $useForShipping = (int)$data['use_for_shipping']; + $passwordHash = 'password hash'; $this->requestMock->expects($this->any())->method('isAjax')->will($this->returnValue(false)); $customerValidationResultMock = $this->getMock( @@ -455,17 +457,52 @@ public function testSaveBilling( ); $shippingAddressMock = $this->getMock( 'Magento\Sales\Model\Quote\Address', - ['setSameAsBilling', 'save', '__wakeup', 'unserialize'], + [ + 'setSameAsBilling', + 'save', + 'collectTotals', + 'addData', + 'setShippingMethod', + 'setCollectShippingRates' + ], [], '', false ); - $shippingAddressMock->expects($this->any())->method('setSameAsBilling')->with((int)$data['use_for_shipping']); - $shippingAddressMock->expects($this->once())->method('save'); + $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock)); + + $shippingAddressMock->expects($useForShipping ? $this->any() : $this->once()) + ->method('setSameAsBilling') + ->with($useForShipping) + ->will($this->returnSelf()); + + $expects = (!$useForShipping || ($checkoutMethod != Onepage::METHOD_REGISTER)) ? $this->once() : $this->never(); + $shippingAddressMock->expects($expects) + ->method('save'); + + $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never()) + ->method('addData') + ->will($this->returnSelf()); + + $shippingAddressMock->expects($this->any()) + ->method('setSaveInAddressBook') + ->will($this->returnSelf()); + + $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never()) + ->method('setShippingMethod') + ->will($this->returnSelf()); + + $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never()) + ->method('setCollectShippingRates') + ->will($this->returnSelf()); + + $shippingAddressMock->expects($useForShipping ? $this->once() : $this->never()) + ->method('collectTotals'); + $quoteMock->expects($this->any())->method('setPasswordHash')->with($passwordHash); $quoteMock->expects($this->any())->method('getCheckoutMethod')->will($this->returnValue($checkoutMethod)); $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue($isVirtual)); - $quoteMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($shippingAddressMock)); + $addressMock = $this->getMock( 'Magento\Sales\Model\Quote\Address', [ @@ -487,7 +524,15 @@ public function testSaveBilling( $quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock)); $quoteMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($quoteCustomerId)); - $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); + + $this->quoteRepositoryMock + ->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->once() : $this->never()) + ->method('save') + ->with($quoteMock); + + $addressMock->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once()) + ->method('save'); + $quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock)); $data1 = []; $extensibleDataObjectConverterMock = $this->getMock( @@ -505,7 +550,7 @@ public function testSaveBilling( $formMock = $this->getMock('Magento\Customer\Model\Metadata\Form', [], [], '', false); $formMock->expects($this->atLeastOnce())->method('validateData')->will($this->returnValue($validateDataResult)); - $this->customerFormFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock)); + $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($formMock)); $formMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->requestMock)); $formMock->expects($this->any()) ->method('extractData') @@ -526,7 +571,7 @@ public function testSaveBilling( $this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $this->checkoutSessionMock->expects($this->any()) ->method('getStepData') - ->will($this->returnValue((int)$data['use_for_shipping'] === 1 ? true : $getStepDataResult)); + ->will($this->returnValue($useForShipping ? true : $getStepDataResult)); $this->checkoutSessionMock->expects($this->any())->method('setStepData')->will($this->returnSelf()); $customerAddressMock = $this->getMockForAbstractClass( 'Magento\Customer\Api\Data\AddressInterface', @@ -541,13 +586,6 @@ public function testSaveBilling( ->method('getById') ->will($isAddress ? $this->returnValue($customerAddressMock) : $this->throwException(new \Exception())); - $this->customerBuilderMock - ->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once()) - ->method('populate'); - $this->customerBuilderMock - ->expects($checkoutMethod === Onepage::METHOD_REGISTER ? $this->never() : $this->once()) - ->method('setGroupId'); - $websiteMock = $this->getMock('Magento\Store\Model\Website', [], [], '', false); $this->storeManagerMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock)); $this->assertEquals($expected, $this->onepage->saveBilling($data, $customerAddressId)); @@ -572,6 +610,23 @@ public function saveBillingDataProvider() false, // $isVirtual false, // $getStepDataResult [], // $expected + ], + [ + ['use_for_shipping' => 1], // $data + 1, // $customerAddressId + 1, // $quoteCustomerId + 1, // $addressCustomerId + true, //$isAddress + true, // $validateDataResult + true, // $validateResult + Onepage::METHOD_CUSTOMER, // $checkoutMethod + 'password', // $customerPassword + 'password', // $confirmPassword + [], // $validationResultMessages + true, // $isEmailAvailable + false, // $isVirtual + false, // $getStepDataResult + [], // $expected ] ]; } diff --git a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php index 50314f90c66ae..5a3d33ab032df 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/ObjectManager/DefinitionFactoryTest.php @@ -92,12 +92,12 @@ public function createPluginsAndRelationsReadableDataProvider() { return [ 'relations' => [ - 'DefinitionDir/relations.php', + 'DefinitionDir/relations.ser', 'createRelations', '\Magento\Framework\ObjectManager\Relations\Compiled', ], 'plugins' => [ - 'DefinitionDir/plugins.php', + 'DefinitionDir/plugins.ser', 'createPluginDefinition', '\Magento\Framework\Interception\Definition\Compiled', ], @@ -122,12 +122,12 @@ public function createPluginsAndRelationsNotReadableDataProvider() { return [ 'relations' => [ - 'DefinitionDir/relations.php', + 'DefinitionDir/relations.ser', 'createRelations', '\Magento\Framework\ObjectManager\Relations\Runtime', ], 'plugins' => [ - 'DefinitionDir/plugins.php', + 'DefinitionDir/plugins.ser', 'createPluginDefinition', '\Magento\Framework\Interception\Definition\Runtime', ], diff --git a/dev/tests/unit/testsuite/Magento/Framework/ObjectTest.php b/dev/tests/unit/testsuite/Magento/Framework/ObjectTest.php index ac27afc4bbe4b..ef105acc1a032 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/ObjectTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/ObjectTest.php @@ -454,10 +454,11 @@ public function underscoreDataProvider() return [ 'Test 1' => ['Stone1Color', 'stone_1_color'], 'Test 2' => ['StoneColor', 'stone_color'], - 'Test 3' => ['StoneToXML', 'stone_to_xml'], + 'Test 3' => ['StoneToXml', 'stone_to_xml'], 'Test 4' => ['1StoneColor', '1_stone_color'], 'Test 5' => ['getCcLast4', 'get_cc_last_4'], - 'Test 6' => ['99Bottles', '99_bottles'] + 'Test 6' => ['99Bottles', '99_bottles'], + 'Test 7' => ['XApiLogin', 'x_api_login'] ]; } } diff --git a/dev/tests/unit/testsuite/Magento/Multishipping/Helper/DataTest.php b/dev/tests/unit/testsuite/Magento/Multishipping/Helper/DataTest.php index 3295d49fa2980..7e9e1810bcb9d 100644 --- a/dev/tests/unit/testsuite/Magento/Multishipping/Helper/DataTest.php +++ b/dev/tests/unit/testsuite/Magento/Multishipping/Helper/DataTest.php @@ -88,7 +88,6 @@ public function testGetMaximumQty() * @param int $itemsSummaryQty * @param int $itemVirtualQty * @param int $maximumQty - * @param bool $hasNominalItems * @dataProvider isMultishippingCheckoutAvailableDataProvider */ public function testIsMultishippingCheckoutAvailable( @@ -99,8 +98,7 @@ public function testIsMultishippingCheckoutAvailable( $validateMinimumAmount, $itemsSummaryQty, $itemVirtualQty, - $maximumQty, - $hasNominalItems + $maximumQty ) { $this->scopeConfigMock->expects( $this->once() @@ -159,7 +157,6 @@ public function testIsMultishippingCheckoutAvailable( )->will( $this->returnValue($maximumQty) ); - $this->quoteMock->expects($this->any())->method('hasNominalItems')->will($this->returnValue($hasNominalItems)); $this->assertEquals($result, $this->helper->isMultishippingCheckoutAvailable()); } @@ -172,15 +169,13 @@ public function testIsMultishippingCheckoutAvailable( public function isMultishippingCheckoutAvailableDataProvider() { return [ - [true, false, true, null, null, null, null, null, null], - [false, false, false, null, null, null, null, null, null], - [false, true, true, true, null, null, null, null, null], - [false, true, true, false, false, null, null, null, null], - [true, true, true, false, true, 2, 1, 3, null], - [false, true, true, false, true, 1, 2, null, null], - [false, true, true, false, true, 2, 1, 1, null], - [true, true, true, false, true, 2, 1, 3, false], - [false, true, true, false, true, 2, 1, 3, true] + [true, false, true, null, null, null, null, null], + [false, false, false, null, null, null, null, null], + [false, true, true, true, null, null, null, null], + [false, true, true, false, false, null, null, null], + [true, true, true, false, true, 2, 1, 3], + [false, true, true, false, true, 1, 2, null], + [false, true, true, false, true, 2, 1, 1], ]; } } diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Cart/SalesModel/QuoteTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Cart/SalesModel/QuoteTest.php index 3e6157e94ffaf..22a37fafbf404 100644 --- a/dev/tests/unit/testsuite/Magento/Payment/Model/Cart/SalesModel/QuoteTest.php +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Cart/SalesModel/QuoteTest.php @@ -56,17 +56,15 @@ public function testGetTaxContainer() } /** - * @param int $isNominal * @param string $pItem * @param string $name * @param int $qty * @param float $price * @dataProvider getAllItemsDataProvider */ - public function testGetAllItems($isNominal, $pItem, $name, $qty, $price) + public function testGetAllItems($pItem, $name, $qty, $price) { $itemMock = $this->getMock('Magento\Sales\Model\Quote\Item\AbstractItem', [], [], '', false); - $itemMock->expects($this->any())->method('isNominal')->will($this->returnValue($isNominal)); $itemMock->expects($this->any())->method('getParentItem')->will($this->returnValue($pItem)); $itemMock->expects($this->once())->method('__call')->with('getName')->will($this->returnValue($name)); $itemMock->expects($this->any())->method('getTotalQty')->will($this->returnValue($qty)); @@ -77,7 +75,7 @@ public function testGetAllItems($isNominal, $pItem, $name, $qty, $price) 'parent_item' => $pItem, 'name' => $name, 'qty' => $qty, - 'price' => $isNominal ? 0 : $price, + 'price' => $price, 'original_item' => $itemMock, ] ), @@ -89,12 +87,9 @@ public function testGetAllItems($isNominal, $pItem, $name, $qty, $price) public function getAllItemsDataProvider() { return [ - [0, 'parent item 1', 'name 1', 1, 0.1], - [1, 'parent item 1', 'name 1', 1, 0.1], - [0, 'parent item 2', 'name 2', 2, 1.2], - [1, 'parent item 2', 'name 2', 2, 1.2], - [0, 'parent item 3', 'name 3', 3, 2.3], - [1, 'parent item 3', 'name 3', 3, 2.3] + ['parent item 1', 'name 1', 1, 0.1], + ['parent item 2', 'name 2', 2, 1.2], + ['parent item 3', 'name 3', 3, 2.3], ]; } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/Config/_files/core_totals_config.php b/dev/tests/unit/testsuite/Magento/Sales/Model/Config/_files/core_totals_config.php index 9d8282cdaacc6..85d8171cc6108 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/Config/_files/core_totals_config.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/Config/_files/core_totals_config.php @@ -6,8 +6,7 @@ return [ // Totals declared in Magento_Sales - 'nominal' => ['before' => ['subtotal'], 'after' => []], - 'subtotal' => ['after' => ['nominal'], 'before' => ['grand_total']], + 'subtotal' => ['after' => [], 'before' => ['grand_total']], 'shipping' => [ 'after' => ['subtotal', 'freeshipping', 'tax_subtotal'], 'before' => ['grand_total'], diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/Config/_files/custom_totals_config.php b/dev/tests/unit/testsuite/Magento/Sales/Model/Config/_files/custom_totals_config.php index d1c0b866cc846..3ecf9e3209f6c 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/Config/_files/custom_totals_config.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/Config/_files/custom_totals_config.php @@ -8,8 +8,8 @@ $result += [ 'handling' => ['after' => ['shipping'], 'before' => ['tax']], 'handling_tax' => ['after' => ['tax_shipping'], 'before' => ['tax']], - 'own_subtotal' => ['after' => ['nominal'], 'before' => ['subtotal']], - 'own_total1' => ['after' => ['nominal'], 'before' => ['subtotal']], - 'own_total2' => ['after' => ['nominal'], 'before' => ['subtotal']] + 'own_subtotal' => ['after' => [], 'before' => ['subtotal']], + 'own_total1' => ['after' => [], 'before' => ['subtotal']], + 'own_total2' => ['after' => [], 'before' => ['subtotal']] ]; return $result; diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/Order/PaymentTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/Order/PaymentTest.php index c028f1de79e69..ac27cb0057052 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/Order/PaymentTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/Order/PaymentTest.php @@ -7,67 +7,115 @@ /** * Class PaymentTest + * * @package Magento\Sales\Model\Order */ class PaymentTest extends \PHPUnit_Framework_TestCase { - /** - * @var Payment - */ - protected $payment; + /** @var Payment */ + private $payment; - /** - * @var \Magento\Payment\Helper\Data | \PHPUnit_Framework_MockObject_MockObject - */ - protected $helper; + /** @var \Magento\Payment\Helper\Data | \PHPUnit_Framework_MockObject_MockObject */ + private $helperMock; - /** - * @var \Magento\Framework\Event\Manager | \PHPUnit_Framework_MockObject_MockObject - */ - protected $eventManager; + /** @var \Magento\Framework\Event\Manager | \PHPUnit_Framework_MockObject_MockObject */ + private $eventManagerMock; + + /** @var \Magento\Directory\Model\PriceCurrency | \PHPUnit_Framework_MockObject_MockObject */ + private $priceCurrencyMock; + + /** @var \Magento\Sales\Model\Order | \PHPUnit_Framework_MockObject_MockObject $orderMock */ + private $orderMock; + + /** @var \Magento\Payment\Model\Method\AbstractMethod | \PHPUnit_Framework_MockObject_MockObject $orderMock */ + private $paymentMethodMock; protected function setUp() { - $objectManger = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\Manager') + ->disableOriginalConstructor() + ->getMock(); - $this->eventManager = $this->getMock('Magento\Framework\Event\Manager', [], [], '', false); + $context = $this->getMockBuilder('Magento\Framework\Model\Context') + ->disableOriginalConstructor() + ->getMock(); - $context = $this->getMock('Magento\Framework\Model\Context', [], [], '', false); $context->expects($this->once()) ->method('getEventDispatcher') - ->will($this->returnValue($this->eventManager)); + ->will($this->returnValue($this->eventManagerMock)); + + $this->helperMock = $this->getMockBuilder('Magento\Payment\Helper\Data') + ->disableOriginalConstructor() + ->setMethods(['getMethodInstance']) + ->getMock(); + + $this->priceCurrencyMock = $this->getMockBuilder('Magento\Directory\Model\PriceCurrency') + ->disableOriginalConstructor() + ->setMethods(['format']) + ->getMock(); + + $this->priceCurrencyMock->expects($this->any()) + ->method('format') + ->willReturnCallback( + function ($value) { + return $value; + } + ); + + $this->paymentMethodMock = $this->getMockBuilder('Magento\Payment\Model\Method\AbstractMethod') + ->disableOriginalConstructor() + ->setMethods([ + 'canVoid', + 'authorize', + 'getConfigData', + 'getConfigPaymentAction', + 'validate', + ]) + ->getMock(); + + $this->helperMock->expects($this->once()) + ->method('getMethodInstance') + ->will($this->returnValue($this->paymentMethodMock)); - $this->helper = $this->getMock('Magento\Payment\Helper\Data', ['getMethodInstance'], [], '', false); + $this->orderMock = $this->getMockBuilder('Magento\Sales\Model\Order') + ->disableOriginalConstructor() + ->setMethods([ + 'getConfig', + 'setState', + 'getStoreId', + 'getBaseGrandTotal', + 'getBaseCurrency', + 'getBaseCurrencyCode', + 'getTotalDue', + 'getBaseTotalDue', + ]) + ->getMock(); - $this->payment = $objectManger->getObject( + $this->payment = (new \Magento\TestFramework\Helper\ObjectManager($this))->getObject( 'Magento\Sales\Model\Order\Payment', [ - 'paymentData' => $this->helper, - 'context' => $context + 'context' => $context, + 'paymentData' => $this->helperMock, + 'priceCurrency' => $this->priceCurrencyMock, ] ); + + $this->payment->setMethod('any'); + $this->payment->setOrder($this->orderMock); } protected function tearDown() { - $this->payment = null; + unset($this->payment); } public function testCancel() { - $paymentMethod = $this->getMock('Magento\Payment\Model\Method\AbstractMethod', ['canVoid'], [], '', false); - $this->helper->expects($this->once())->method('getMethodInstance')->will($this->returnValue($paymentMethod)); - $this->payment->setMethod('any'); // check fix for partial refunds in Payflow Pro - $paymentMethod->expects( - $this->once() - )->method( - 'canVoid' - )->with( - new \PHPUnit_Framework_Constraint_IsIdentical($this->payment) - )->will( - $this->returnValue(false) - ); + $this->paymentMethodMock->expects($this->once()) + ->method('canVoid') + ->with($this->payment) + ->willReturn(false); $this->assertEquals($this->payment, $this->payment->cancel()); } @@ -75,36 +123,192 @@ public function testCancel() public function testPlace() { $newOrderStatus = 'new_status'; - /** @var \Magento\Sales\Model\Order\Config | \PHPUnit_Framework_MockObject_MockObject $orderConfig */ - $orderConfig = $this->getMock('Magento\Sales\Model\Order\Config', [], [], '', false); - $orderConfig->expects($this->at(0)) + + /** @var \Magento\Sales\Model\Order\Config | \PHPUnit_Framework_MockObject_MockObject $orderConfigMock */ + $orderConfigMock = $this->getMockBuilder('Magento\Sales\Model\Order\Config') + ->disableOriginalConstructor() + ->setMethods(['getStateStatuses', 'getStateDefaultStatus']) + ->getMock(); + + $orderConfigMock->expects($this->once()) ->method('getStateStatuses') ->with(\Magento\Sales\Model\Order::STATE_NEW) ->will($this->returnValue(['firstStatus', 'secondStatus'])); - $orderConfig->expects($this->at(1)) + + $orderConfigMock->expects($this->once()) ->method('getStateDefaultStatus') ->with(\Magento\Sales\Model\Order::STATE_NEW) ->will($this->returnValue($newOrderStatus)); - /** @var \Magento\Sales\Model\Order | \PHPUnit_Framework_MockObject_MockObject $order */ - $order = $this->getMock('Magento\Sales\Model\Order', [], [], '', false); - $order->expects($this->any()) + + $this->orderMock->expects($this->exactly(2)) ->method('getConfig') - ->will($this->returnValue($orderConfig)); - $order->expects($this->once()) + ->will($this->returnValue($orderConfigMock)); + + $this->orderMock->expects($this->once()) ->method('setState') ->with(\Magento\Sales\Model\Order::STATE_NEW, $newOrderStatus); - $methodInstance = $this->getMock('Magento\Payment\Model\Method\AbstractMethod', [], [], '', false); - $this->payment->setOrder($order); - $this->payment->setMethodInstance($methodInstance); + $this->paymentMethodMock->expects($this->once()) + ->method('getConfigPaymentAction') + ->willReturn(null); - $this->eventManager->expects($this->at(0)) + $this->eventManagerMock->expects($this->at(0)) ->method('dispatch') ->with('sales_order_payment_place_start', ['payment' => $this->payment]); - $this->eventManager->expects($this->at(1)) + + $this->eventManagerMock->expects($this->at(1)) ->method('dispatch') ->with('sales_order_payment_place_end', ['payment' => $this->payment]); $this->assertEquals($this->payment, $this->payment->place()); } + + public function testAuthorize() + { + $storeID = 1; + $amount = 10; + + $baseCurrencyMock = $this->getMockBuilder('Magento\Directory\Model\Currency') + ->disableOriginalConstructor() + ->setMethods(['formatTxt']) + ->getMock(); + + $baseCurrencyMock->expects($this->once()) + ->method('formatTxt') + ->willReturnCallback( + function ($value) { + return $value; + } + ); + + $this->orderMock->expects($this->once()) + ->method('getStoreId') + ->willReturn($storeID); + + $this->orderMock->expects($this->once()) + ->method('getBaseGrandTotal') + ->willReturn($amount); + + $this->orderMock->expects($this->once()) + ->method('getBaseCurrency') + ->willReturn($baseCurrencyMock); + + $this->orderMock->expects($this->once()) + ->method('setState') + ->with(\Magento\Sales\Model\Order::STATE_PROCESSING, true, 'Authorized amount of ' . $amount); + + $this->paymentMethodMock->expects($this->once()) + ->method('authorize') + ->with($this->payment) + ->willReturnSelf(); + + $paymentResult = $this->payment->authorize(true, $amount); + + $this->assertInstanceOf('Magento\Sales\Model\Order\Payment', $paymentResult); + $this->assertEquals($amount, $paymentResult->getBaseAmountAuthorized()); + } + + public function testAuthorizeFraudDetected() + { + $storeID = 1; + $amount = 10; + + $baseCurrencyMock = $this->getMockBuilder('Magento\Directory\Model\Currency') + ->disableOriginalConstructor() + ->setMethods(['formatTxt']) + ->getMock(); + + $baseCurrencyMock->expects($this->once()) + ->method('formatTxt') + ->willReturnCallback( + function ($value) { + return $value; + } + ); + + $this->orderMock->expects($this->once()) + ->method('getStoreId') + ->willReturn($storeID); + + $this->orderMock->expects($this->once()) + ->method('getBaseCurrencyCode') + ->willReturn("USD"); + + $this->orderMock->expects($this->once()) + ->method('getBaseCurrency') + ->willReturn($baseCurrencyMock); + + $this->orderMock->expects($this->once()) + ->method('setState') + ->with( + \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW, + \Magento\Sales\Model\Order::STATUS_FRAUD, + "Order is suspended as its authorizing amount $amount is suspected to be fraudulent." + ); + + $this->paymentMethodMock->expects($this->once()) + ->method('authorize') + ->with($this->payment) + ->willReturnSelf(); + + $this->payment->setCurrencyCode('GBP'); + + $paymentResult = $this->payment->authorize(true, $amount); + + $this->assertInstanceOf('Magento\Sales\Model\Order\Payment', $paymentResult); + $this->assertEquals($amount, $paymentResult->getBaseAmountAuthorized()); + $this->assertTrue($paymentResult->getIsFraudDetected()); + } + + public function testAuthorizeTransactionPending() + { + $storeID = 1; + $amount = 10; + + $baseCurrencyMock = $this->getMockBuilder('Magento\Directory\Model\Currency') + ->disableOriginalConstructor() + ->setMethods(['formatTxt']) + ->getMock(); + + $baseCurrencyMock->expects($this->once()) + ->method('formatTxt') + ->willReturnCallback( + function ($value) { + return $value; + } + ); + + $this->orderMock->expects($this->once()) + ->method('getStoreId') + ->willReturn($storeID); + + $this->orderMock->expects($this->once()) + ->method('getBaseGrandTotal') + ->willReturn($amount); + + $this->orderMock->expects($this->once()) + ->method('getBaseCurrency') + ->willReturn($baseCurrencyMock); + + $this->orderMock->expects($this->once()) + ->method('setState') + ->with( + \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW, + true, + "We will authorize $amount after the payment is approved at the payment gateway." + ); + + $this->paymentMethodMock->expects($this->once()) + ->method('authorize') + ->with($this->payment) + ->willReturnSelf(); + + $this->payment->setIsTransactionPending(true); + + $paymentResult = $this->payment->authorize(true, $amount); + + $this->assertInstanceOf('Magento\Sales\Model\Order\Payment', $paymentResult); + $this->assertEquals($amount, $paymentResult->getBaseAmountAuthorized()); + $this->assertTrue($paymentResult->getIsTransactionPending()); + } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/OrderTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/OrderTest.php index f0a9c46968e2b..df0bad597be43 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/OrderTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/OrderTest.php @@ -192,6 +192,23 @@ public function testCanCancelIsPaymentReview() $this->assertFalse($this->order->canCancel()); } + public function testCanEditIfHasInvoices() + { + $invoiceCollection = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Invoice\Collection') + ->disableOriginalConstructor() + ->setMethods(['count']) + ->getMock(); + + $invoiceCollection->expects($this->once()) + ->method('count') + ->willReturn(2); + + $this->order->setInvoiceCollection($invoiceCollection); + $this->order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING); + + $this->assertFalse($this->order->canEdit()); + } + public function testCanCancelCanReviewPayment() { $paymentMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Order\Payment') diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/Address/Total/SubtotalTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/Address/Total/SubtotalTest.php index 1fd8df1400b8a..195b73360c971 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/Address/Total/SubtotalTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/Address/Total/SubtotalTest.php @@ -99,7 +99,7 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri '', false ); - $address->expects($this->any())->method('getAllNonNominalItems')->will( + $address->expects($this->any())->method('getAllItems')->will( $this->returnValue([$quoteItem]) ); @@ -135,7 +135,7 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri $quote->expects($this->any())->method('getStore')->will($this->returnValue($store)); $quoteItem->setProduct($product)->setQuote($quote)->setOriginalCustomPrice($price); - $address->expects($this->any())->method('getAllNonNominalItems')->will( + $address->expects($this->any())->method('getAllItems')->will( $this->returnValue([$quoteItem]) ); $address->expects($this->any())->method('getQuote')->will($this->returnValue($quote)); diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/QuoteTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/QuoteTest.php index ebdb9106a7290..4a212d2d86cd7 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/QuoteTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/QuoteTest.php @@ -1049,4 +1049,33 @@ public function testGetPaymentIsDeleted() $this->assertInstanceOf('\Magento\Sales\Model\Quote\Payment', $this->quote->getPayment()); } + + public function testAddItem() + { + $item = $this->getMock('Magento\Sales\Model\Quote\Item', ['setQuote', 'getId'], [], '', false); + $item->expects($this->once()) + ->method('setQuote'); + $item->expects($this->once()) + ->method('getId') + ->willReturn(false); + $itemsMock = $this->getMock( + 'Magento\Eav\Model\Entity\Collection\AbstractCollection', + ['setQuote', 'addItem'], + [], + '', + false + ); + $itemsMock->expects($this->once()) + ->method('setQuote'); + $itemsMock->expects($this->once()) + ->method('addItem') + ->with($item); + $this->quoteItemCollectionFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($itemsMock); + $this->eventManagerMock->expects($this->once()) + ->method('dispatch'); + + $this->quote->addItem($item); + } } diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/Service/QuoteTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/Service/QuoteTest.php new file mode 100644 index 0000000000000..78738f3372995 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/Service/QuoteTest.php @@ -0,0 +1,53 @@ +getMock('Magento\Sales\Model\Convert\QuoteFactory', ['create'], [], '', false); + $convertFactory->expects($this->once()) + ->method('create'); + $this->quoteMock = $this->getMock( + 'Magento\Sales\Model\Quote', + ['getAllVisibleItems', 'setIsActive'], + [], + '', + false + ); + $this->quoteService = $objectManager->getObject( + 'Magento\Sales\Model\Service\Quote', + ['quote' => $this->quoteMock, 'convertQuoteFactory' => $convertFactory] + ); + } + + public function testSubmitAllWithDataObject() + { + $this->quoteMock->expects($this->once()) + ->method('getAllVisibleItems') + ->willReturn(false); + $this->quoteMock->expects($this->once()) + ->method('setIsActive'); + $this->quoteService->submitAllWithDataObject(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Quote/DiscountTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Quote/DiscountTest.php index 372929acae164..7afd9c18bdd48 100644 --- a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Quote/DiscountTest.php +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Quote/DiscountTest.php @@ -113,13 +113,13 @@ public function testCollectItemNoDiscount() ->getMock(); $addressMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address') ->disableOriginalConstructor() - ->setMethods(['getQuote', 'getAllNonNominalItems', 'getShippingAmount', '__wakeup']) + ->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup']) ->getMock(); $addressMock->expects($this->any()) ->method('getQuote') ->willReturn($quoteMock); $addressMock->expects($this->any()) - ->method('getAllNonNominalItems') + ->method('getAllItems') ->willReturn([$itemNoDiscount]); $addressMock->expects($this->any()) ->method('getShippingAmount') @@ -165,13 +165,13 @@ public function testCollectItemHasParent() ->getMock(); $addressMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address') ->disableOriginalConstructor() - ->setMethods(['getQuote', 'getAllNonNominalItems', 'getShippingAmount', '__wakeup']) + ->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup']) ->getMock(); $addressMock->expects($this->any()) ->method('getQuote') ->willReturn($quoteMock); $addressMock->expects($this->any()) - ->method('getAllNonNominalItems') + ->method('getAllItems') ->willReturn([$itemWithParentId]); $addressMock->expects($this->any()) ->method('getShippingAmount') @@ -249,13 +249,13 @@ public function testCollectItemHasChildren($childItemData, $parentData, $expecte ->getMock(); $addressMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address') ->disableOriginalConstructor() - ->setMethods(['getQuote', 'getAllNonNominalItems', 'getShippingAmount', '__wakeup']) + ->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup']) ->getMock(); $addressMock->expects($this->any()) ->method('getQuote') ->willReturn($quoteMock); $addressMock->expects($this->any()) - ->method('getAllNonNominalItems') + ->method('getAllItems') ->willReturn([$itemWithChildren]); $addressMock->expects($this->any()) ->method('getShippingAmount') @@ -368,13 +368,13 @@ public function testCollectItemHasNoChildren() ->getMock(); $addressMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address') ->disableOriginalConstructor() - ->setMethods(['getQuote', 'getAllNonNominalItems', 'getShippingAmount', '__wakeup']) + ->setMethods(['getQuote', 'getAllItems', 'getShippingAmount', '__wakeup']) ->getMock(); $addressMock->expects($this->any()) ->method('getQuote') ->willReturn($quoteMock); $addressMock->expects($this->any()) - ->method('getAllNonNominalItems') + ->method('getAllItems') ->willReturn([$itemWithChildren]); $addressMock->expects($this->any()) ->method('getShippingAmount') diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Quote/Nominal/DiscountTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Quote/Nominal/DiscountTest.php deleted file mode 100644 index 875bcf35b3cc1..0000000000000 --- a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Quote/Nominal/DiscountTest.php +++ /dev/null @@ -1,135 +0,0 @@ -objectManager = new ObjectManager($this); - - $this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->validatorMock = $this->getMockBuilder('Magento\SalesRule\Model\Validator') - ->disableOriginalConstructor() - ->setMethods( - [ - 'canApplyRules', - 'reset', - 'init', - 'initTotals', - 'sortItemsByPriority', - 'setSkipActionsValidation', - 'process', - 'processShippingAmount', - 'canApplyDiscount', - '__wakeup', - ] - ) - ->getMock(); - - $this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\Manager') - ->disableOriginalConstructor() - ->getMock(); - - /** @var \Magento\SalesRule\Model\Quote\Nominal\Discount $discount */ - $this->discount = $this->objectManager->getObject( - 'Magento\SalesRule\Model\Quote\Nominal\Discount', - [ - 'storeManager' => $this->storeManagerMock, - 'validator' => $this->validatorMock, - 'eventManager' => $this->eventManagerMock - ] - ); - } - - public function testFetch() - { - $addressMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address') - ->disableOriginalConstructor() - ->getMock(); - $this->assertInternalType('array', $this->discount->fetch($addressMock)); - } - - public function testGetNominalAddressItems() - { - $item = $this->getMockBuilder('Magento\Sales\Model\Quote\Item') - ->disableOriginalConstructor() - ->setMethods(['__wakeup']) - ->getMock(); - - $this->validatorMock->expects($this->once()) - ->method('sortItemsByPriority') - ->willReturnArgument(0); - - $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') - ->disableOriginalConstructor() - ->setMethods(['getStore', '__wakeup']) - ->getMock(); - - $this->storeManagerMock->expects($this->once()) - ->method('getStore') - ->willReturn($storeMock); - - $quoteMock = $this->getMockBuilder('Magento\Sales\Model\Quote') - ->disableOriginalConstructor() - ->getMock(); - - $addressMock = $this->getMockBuilder('Magento\Sales\Model\Quote\Address') - ->disableOriginalConstructor() - ->setMethods(['getQuote', 'getAllNominalItems', 'getShippingAmount', '__wakeup']) - ->getMock(); - - $addressMock->expects($this->any()) - ->method('getQuote') - ->willReturn($quoteMock); - - $addressMock->expects($this->once()) - ->method('getAllNominalItems') - ->willReturn([$item]); - - $addressMock->expects($this->once()) - ->method('getShippingAmount') - ->willReturn(true); - - $this->assertInstanceOf( - 'Magento\SalesRule\Model\Quote\Discount', - $this->discount->collect($addressMock) - ); - } -} diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/ValidatorTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/ValidatorTest.php index fba929bda23c8..eaaf5fb497ccf 100644 --- a/dev/tests/unit/testsuite/Magento/SalesRule/Model/ValidatorTest.php +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/ValidatorTest.php @@ -135,12 +135,11 @@ protected function getQuoteItemMock() /** @var $quote \Magento\Sales\Model\Quote */ $quote = $this->getMock( 'Magento\Sales\Model\Quote', - ['hasNominalItems', 'getStoreId', '__wakeup'], + ['getStoreId', '__wakeup'], [], '', false ); - $quote->expects($this->any())->method('hasNominalItems')->will($this->returnValue(false)); $quote->expects($this->any())->method('getStoreId')->will($this->returnValue(1)); $itemData = include $fixturePath . 'quote_item_downloadable.php'; diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/_files/quote_item_downloadable.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/_files/quote_item_downloadable.php index c53d2b673fc29..80bf622d42b89 100644 --- a/dev/tests/unit/testsuite/Magento/SalesRule/Model/_files/quote_item_downloadable.php +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/_files/quote_item_downloadable.php @@ -69,7 +69,6 @@ 'product' => null, 'tax_class_id' => '0', 'has_error' => false, - 'is_nominal' => false, 'base_calculation_price' => 8, 'calculation_price' => 8, 'converted_price' => 8, diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/_files/quote_item_simple.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/_files/quote_item_simple.php index fe86d9c999283..acf35bac2813e 100644 --- a/dev/tests/unit/testsuite/Magento/SalesRule/Model/_files/quote_item_simple.php +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/_files/quote_item_simple.php @@ -69,7 +69,6 @@ 'product' => null, 'tax_class_id' => '2', 'has_error' => false, - 'is_nominal' => false, 'base_calculation_price' => 10, 'calculation_price' => 10, 'converted_price' => 10, diff --git a/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/ShippingTest.php b/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/ShippingTest.php index 179126e5a76e1..8b0e4dcf57dba 100644 --- a/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/ShippingTest.php +++ b/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/ShippingTest.php @@ -114,7 +114,7 @@ public function testCollectDoesNotCalculateTaxIfThereIsNoItemsRelatedToGivenAddr ] ); $addressMock = $this->getMockObject('Magento\Sales\Model\Quote\Address', [ - 'all_non_nominal_items' => [], + 'all_items' => [], 'shipping_tax_calculation_amount' => 100, 'base_shipping_tax_calculation_amount' => 200, 'shipping_discount_amount' => 10, diff --git a/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/SubtotalTest.php b/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/SubtotalTest.php index d6fa4e75ad3b4..a82f8f6086373 100644 --- a/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/SubtotalTest.php +++ b/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/SubtotalTest.php @@ -113,7 +113,7 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods([ 'getAssociatedTaxables', 'getQuote', 'getBillingAddress', - 'getRegionId', 'getAllNonNominalItems', '__wakeup', + 'getRegionId', 'getAllItems', '__wakeup', 'getParentItem', ])->getMock(); @@ -128,7 +128,7 @@ protected function setUp() public function testCollectEmptyAddresses() { - $this->addressMock->expects($this->once())->method('getAllNonNominalItems')->willReturn(null); + $this->addressMock->expects($this->once())->method('getAllItems')->willReturn(null); $this->taxConfigMock->expects($this->never())->method('priceIncludesTax'); $this->model->collect($this->addressMock); } @@ -155,7 +155,7 @@ protected function checkGetAddressItems() { $customerTaxClassId = 2425; $this->addressMock->expects($this->atLeastOnce()) - ->method('getAllNonNominalItems')->willReturn([$this->addressMock]); + ->method('getAllItems')->willReturn([$this->addressMock]); // calls in populateAddressData() $this->quoteDetailsBuilder->expects($this->atLeastOnce())->method('setBillingAddress'); diff --git a/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php b/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php index 7e7b0cfcdcb0d..7a3777118476f 100644 --- a/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php +++ b/dev/tests/unit/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php @@ -289,7 +289,7 @@ public function testCollect($itemData, $appliedRatesData, $taxDetailsData, $quot ->method('create') ->will($this->returnValue($address)); - $addressData["cached_items_nonnominal"] = $items; + $addressData["cached_items_all"] = $items; foreach ($addressData as $key => $value) { $address->setData($key, $value); } @@ -550,7 +550,7 @@ public function testMapQuoteExtraTaxables($itemData, $addressData) ->method('getBillingAddress') ->will($this->returnValue($address)); - $addressData["cached_items_nonnominal"] = $items; + $addressData["cached_items_all"] = $items; foreach ($addressData as $key => $value) { $address->setData($key, $value); } @@ -622,7 +622,7 @@ public function testFetch($appliedTaxesData, $addressData) $address = $this->getMock( '\Magento\Sales\Model\Quote\Address', [ - 'getAppliedTaxes', 'getQuote', 'getAllNonNominalItems', 'getGrandTotal', '__wakeup', + 'getAppliedTaxes', 'getQuote', 'getAllItems', 'getGrandTotal', '__wakeup', 'addTotal', 'getTaxAmount' ], [], @@ -639,7 +639,7 @@ public function testFetch($appliedTaxesData, $addressData) ->will($this->returnValue($quote)); $address ->expects($this->once()) - ->method('getAllNonNominalItems') + ->method('getAllItems') ->will($this->returnValue($items)); $address ->expects($this->any()) @@ -654,7 +654,7 @@ public function testFetch($appliedTaxesData, $addressData) ->method('getTaxAmount') ->will($this->returnValue(8)); - $addressData["cached_items_nonnominal"] = $items; + $addressData["cached_items_all"] = $items; foreach ($addressData as $key => $value) { $address->setData($key, $value); } @@ -713,7 +713,7 @@ public function testEmptyAddress() ->disableOriginalConstructor() ->setMethods( [ - 'getAllNonNominalItems', + 'getAllItems', '__wakeup', ] )->getMock(); @@ -730,7 +730,7 @@ public function testEmptyAddress() $address->setBaseSubtotalInclTax(1); $address->expects($this->once()) - ->method('getAllNonNominalItems') + ->method('getAllItems') ->will($this->returnValue([])); $objectManager = new ObjectManager($this); diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php index c36d1fe5bc178..08f65859539f9 100644 --- a/dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/App/CompilerTest.php @@ -8,93 +8,122 @@ class CompilerTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Tools\Di\App\Compiler + * @var Compiler */ private $model; /** - * @var \Magento\Framework\App\AreaList | \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\ObjectManagerInterface | \PHPUnit_Framework_MockObject_MockObject */ - private $areaList; + private $objectManagerMock; /** - * @var \Magento\Tools\Di\Code\Reader\ClassesScanner | \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Tools\Di\App\Task\Manager | \PHPUnit_Framework_MockObject_MockObject */ - private $classesScanner; + private $taskManagerMock; /** - * @var \Magento\Tools\Di\Code\Generator\InterceptionConfigurationBuilder | \PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\Console\Response | \PHPUnit_Framework_MockObject_MockObject */ - private $interceptionConfigurationBuilder; - - /** - * @var \Magento\Tools\Di\Compiler\Config\Reader | \PHPUnit_Framework_MockObject_MockObject - */ - private $configReader; - - /** - * @var \Magento\Tools\Di\Compiler\Config\Writer\Filesystem | \PHPUnit_Framework_MockObject_MockObject - */ - private $configWriter; + private $responseMock; protected function setUp() { - $this->areaList = $this->getMockBuilder('\Magento\Framework\App\AreaList') - ->disableOriginalConstructor() + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + ->setMethods([]) ->getMock(); - - $this->classesScanner = $this->getMockBuilder('\Magento\Tools\Di\Code\Reader\ClassesScanner') + $this->taskManagerMock = $this->getMockBuilder('Magento\Tools\Di\App\Task\Manager') ->disableOriginalConstructor() - ->setMethods(['getList']) + ->setMethods([]) ->getMock(); - - $this->interceptionConfigurationBuilder = $this->getMockBuilder( - '\Magento\Tools\Di\Code\Generator\InterceptionConfigurationBuilder' - )->disableOriginalConstructor()->getMock(); - - $this->configReader = $this->getMockBuilder('\Magento\Tools\Di\Compiler\Config\Reader') + $this->responseMock = $this->getMockBuilder('Magento\Framework\App\Console\Response') ->disableOriginalConstructor() + ->setMethods([]) ->getMock(); - - $this->configWriter = $this->getMockBuilder('\Magento\Tools\Di\Compiler\Config\Writer\Filesystem') - ->setMethods(['write']) - ->getMock(); - - $this->model = new \Magento\Tools\Di\App\Compiler( - $this->areaList, - $this->classesScanner, - $this->interceptionConfigurationBuilder, - $this->configReader, - $this->configWriter + $this->model = new Compiler( + $this->taskManagerMock, + $this->objectManagerMock, + $this->responseMock ); } - public function testLaunch() + public function testLaunchSuccess() { - $this->classesScanner->expects($this->exactly(3)) - ->method('getList') - ->willReturn([]); - - $this->configReader->expects($this->any()) - ->method('generateCachePerScope') - ->willReturn([]); + $this->objectManagerMock->expects($this->once()) + ->method('configure') + ->with($this->getPreferences()); + $index = 0; + foreach ($this->getOptions() as $code => $arguments) { + $this->taskManagerMock->expects($this->at($index)) + ->method('addOperation') + ->with($code, $arguments); + $index++; + } + $this->taskManagerMock->expects($this->at($index))->method('process'); + $this->responseMock->expects($this->once()) + ->method('setCode') + ->with(\Magento\Framework\App\Console\Response::SUCCESS); - $areaListResult = ['global', 'frontend', 'admin']; - $this->areaList->expects($this->once()) - ->method('getCodes') - ->willReturn($areaListResult); + $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->model->launch()); + } - $count = count($areaListResult) + 1; - $this->configWriter->expects($this->exactly($count)) - ->method('write'); + public function testLaunchException() + { + $this->objectManagerMock->expects($this->once()) + ->method('configure') + ->with($this->getPreferences()); + $code = key($this->getOptions()); + $arguments = current($this->getOptions()); + $exception = new Task\OperationException( + 'Unrecognized operation', + Task\OperationException::UNAVAILABLE_OPERATION + ); - $this->interceptionConfigurationBuilder->expects($this->exactly($count)) - ->method('addAreaCode'); + $this->taskManagerMock->expects($this->once()) + ->method('addOperation') + ->with($code, $arguments) + ->willThrowException($exception); - $this->interceptionConfigurationBuilder->expects($this->once()) - ->method('getInterceptionConfiguration') - ->willReturn([]); + $this->taskManagerMock->expects($this->never())->method('process'); + $this->responseMock->expects($this->once()) + ->method('setCode') + ->with(\Magento\Framework\App\Console\Response::ERROR); $this->assertInstanceOf('\Magento\Framework\App\Console\Response', $this->model->launch()); } + + /** + * Returns configured preferences + * + * @return array + */ + private function getPreferences() + { + return [ + 'preferences' => + [ + 'Magento\Tools\Di\Compiler\Config\WriterInterface' => + 'Magento\Tools\Di\Compiler\Config\Writer\Filesystem' + ] + ]; + } + + /** + * Returns options + * + * @return array + */ + private function getOptions() + { + return [ + Task\OperationFactory::AREA => [ + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' + ], + Task\OperationFactory::INTERCEPTION => + BP . '/var/generation', + Task\OperationFactory::INTERCEPTION_CACHE => [ + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' + ] + ]; + } } diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/AreaTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/AreaTest.php new file mode 100644 index 0000000000000..867c8c3c2d905 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/AreaTest.php @@ -0,0 +1,106 @@ +areaListMock = $this->getMockBuilder('Magento\Framework\App\AreaList') + ->disableOriginalConstructor() + ->getMock(); + $this->classesScannerMock = $this->getMockBuilder('Magento\Tools\Di\Code\Reader\ClassesScanner') + ->disableOriginalConstructor() + ->getMock(); + $this->configReaderMock = $this->getMockBuilder('Magento\Tools\Di\Compiler\Config\Reader') + ->disableOriginalConstructor() + ->getMock(); + $this->configWriterMock = $this->getMockBuilder('Magento\Tools\Di\Compiler\Config\WriterInterface') + ->disableOriginalConstructor() + ->getMock(); + } + + public function testDoOperationEmptyPath() + { + $areaOperation = new Area( + $this->areaListMock, + $this->classesScannerMock, + $this->configReaderMock, + $this->configWriterMock + ); + + $this->assertNull($areaOperation->doOperation()); + } + + public function testDoOperationGlobalArea() + { + $path = 'path/to/codebase/'; + $generatedConfig = [ + 'arguments' => [], + 'nonShared' => [], + 'preferences' => [], + 'instanceTypes' => [] + ]; + $definitions = new DefinitionsCollection(); + $definitions->addDefinition('class', []); + $areaOperation = new Area( + $this->areaListMock, + $this->classesScannerMock, + $this->configReaderMock, + $this->configWriterMock, + [$path] + ); + + $this->areaListMock->expects($this->once()) + ->method('getCodes') + ->willReturn([]); + $this->classesScannerMock->expects($this->once()) + ->method('getList') + ->with($path) + ->willReturn(['class' => []]); + $this->configReaderMock->expects($this->once()) + ->method('generateCachePerScope') + ->with( + $this->isInstanceOf('Magento\Tools\Di\Definition\Collection'), + App\Area::AREA_GLOBAL + ) + ->willReturn($generatedConfig); + $this->configWriterMock->expects($this->once()) + ->method('write') + ->with( + App\Area::AREA_GLOBAL, + $generatedConfig + ); + + $areaOperation->doOperation(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/OperationFactoryTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/OperationFactoryTest.php new file mode 100644 index 0000000000000..c15e189b777db --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/App/Task/OperationFactoryTest.php @@ -0,0 +1,71 @@ +objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + ->setMethods([]) + ->getMock(); + $this->factory = new OperationFactory( + $this->objectManagerMock + ); + } + + /** + * @param string $alias + * @param mixed $arguments + * @dataProvider aliasesDataProvider + */ + public function testCreateSuccess($alias, $arguments, $instanceName) + { + $operationInstance = $this->getMockBuilder('Magento\Tools\Di\App\Task\OperationInterface') + ->getMock(); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with($instanceName, ['data' => $arguments]) + ->willReturn($operationInstance); + + $this->assertSame($operationInstance, $this->factory->create($alias, $arguments)); + } + + public function testCreateException() + { + $notRegisteredOperation = 'coffee'; + $this->setExpectedException( + 'Magento\Tools\Di\App\Task\OperationException', + sprintf('Unrecognized operation "%s"', $notRegisteredOperation), + OperationException::UNAVAILABLE_OPERATION + ); + $this->factory->create($notRegisteredOperation); + } + + /** + * @return array + */ + public function aliasesDataProvider() + { + return [ + [OperationFactory::AREA, [], 'Magento\Tools\Di\App\Task\Operation\Area'], + [OperationFactory::INTERCEPTION, null, 'Magento\Tools\Di\App\Task\Operation\Interception'], + [OperationFactory::INTERCEPTION_CACHE, 1, 'Magento\Tools\Di\App\Task\Operation\InterceptionCache'], + ]; + } + +} diff --git a/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/ReaderTest.php b/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/ReaderTest.php index 3011d02fa4eac..7ccdb02d2065c 100644 --- a/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/ReaderTest.php +++ b/dev/tests/unit/testsuite/Magento/Tools/Di/Compiler/Config/ReaderTest.php @@ -72,21 +72,17 @@ protected function setUp() ); } - /** - * @dataProvider generateCachePerScopeDataProvider - */ - public function testGenerateCachePerScope($extendConfig) + public function testGenerateCachePerScopeExtends() { $definitionsCollection = $this->getMock('Magento\Tools\Di\Definition\Collection', [], [], '', false); - if ($extendConfig) { - $this->diContainerConfig->expects($this->once()) - ->method('extend') - ->with([]); - $this->configLoader->expects($this->once()) - ->method('load') - ->with('areaCode') - ->willReturn([]); - } + $this->diContainerConfig->expects($this->once()) + ->method('extend') + ->with([]); + $this->configLoader->expects($this->once()) + ->method('load') + ->with('areaCode') + ->willReturn([]); + $this->argumentsResolverFactory->expects($this->once()) ->method('create') ->with($this->diContainerConfig) @@ -141,17 +137,6 @@ public function testGenerateCachePerScope($extendConfig) ['instanceType1', 'instanceType1ss'], ['instanceType2', 'instanceType2'], ]); - $this->model->generateCachePerScope($definitionsCollection, 'areaCode', $extendConfig); - } - - /** - * @return array - */ - public function generateCachePerScopeDataProvider() - { - return [ - [true], - [false] - ]; + $this->model->generateCachePerScope($definitionsCollection, 'areaCode'); } } diff --git a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTaxTest.php b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTaxTest.php index fe770d8bf4b44..009b16cbcad41 100644 --- a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTaxTest.php +++ b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTaxTest.php @@ -125,7 +125,7 @@ protected function setupAddressMock($itemMock, $isWeeeTaxable, $itemData, $addre 'Magento\Sales\Model\Quote\Address', [ '__wakeup', - 'getAllNonNominalItems', + 'getAllItems', 'getQuote', 'getWeeeCodeToItemMap', 'getExtraTaxableDetails', @@ -180,7 +180,7 @@ protected function setupAddressMock($itemMock, $isWeeeTaxable, $itemData, $addre $storeMock->expects($this->any())->method('convertPrice')->will($this->returnArgument(0)); $quoteMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); - $addressMock->expects($this->any())->method('getAllNonNominalItems')->will($this->returnValue([$itemMock])); + $addressMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock])); $addressMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $addressMock->expects($this->any())->method('getWeeeCodeToItemMap')->will($this->returnValue($map)); $addressMock->expects($this->any())->method('getExtraTaxableDetails')->will($this->returnValue($extraDetails)); diff --git a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php index 0fe602d0dfe7d..b327cbb395b51 100644 --- a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php +++ b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php @@ -119,7 +119,7 @@ protected function setupAddressMock($itemMock) 'Magento\Sales\Model\Quote\Address', [ '__wakeup', - 'getAllNonNominalItems', + 'getAllItems', 'getQuote', ], [], @@ -134,7 +134,7 @@ protected function setupAddressMock($itemMock) $this->priceCurrency->expects($this->any())->method('convert')->willReturnArgument(0); $quoteMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); - $addressMock->expects($this->any())->method('getAllNonNominalItems')->will($this->returnValue([$itemMock])); + $addressMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock])); $addressMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); return $addressMock; diff --git a/dev/tools/Magento/Tools/Di/App/Compiler.php b/dev/tools/Magento/Tools/Di/App/Compiler.php index d04434a01121d..f57b1ae9cbb77 100644 --- a/dev/tools/Magento/Tools/Di/App/Compiler.php +++ b/dev/tools/Magento/Tools/Di/App/Compiler.php @@ -7,64 +7,44 @@ namespace Magento\Tools\Di\App; use Magento\Framework\App; -use Magento\Framework\Interception\Code\Generator\Interceptor; -use Magento\Tools\Di\Code\Generator\InterceptionConfigurationBuilder; -use Magento\Tools\Di\Code\Reader\ClassesScanner; -use Magento\Tools\Di\Compiler\Config; -use Magento\Tools\Di\Definition\Collection as DefinitionsCollection; +use Magento\Framework\App\Console\Response; +use Magento\Framework\ObjectManagerInterface; /** * Class Compiler * @package Magento\Tools\Di\App * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Compiler implements \Magento\Framework\AppInterface { /** - * @var App\AreaList + * @var ObjectManagerInterface */ - private $areaList; + private $objectManager; /** - * @var ClassesScanner + * @var Task\Manager */ - private $classesScanner; + private $taskManager; /** - * @var InterceptionConfigurationBuilder + * @var Response */ - private $interceptionConfigurationBuilder; + private $response; /** - * @var Config\Reader - */ - private $configReader; - - /** - * @var Config\Writer\Filesystem - */ - private $configWriter; - - /** - * @param App\AreaList $areaList - * @param ClassesScanner $classesScanner - * @param InterceptionConfigurationBuilder $interceptionConfigurationBuilder - * @param Config\Reader $configReader - * @param Config\Writer\Filesystem $configWriter + * @param Task\Manager $taskManager + * @param ObjectManagerInterface $objectManager + * @param Response $response */ public function __construct( - App\AreaList $areaList, - ClassesScanner $classesScanner, - InterceptionConfigurationBuilder $interceptionConfigurationBuilder, - Config\Reader $configReader, - Config\Writer\Filesystem $configWriter + Task\Manager $taskManager, + ObjectManagerInterface $objectManager, + Response $response ) { - $this->areaList = $areaList; - $this->classesScanner = $classesScanner; - $this->interceptionConfigurationBuilder = $interceptionConfigurationBuilder; - $this->configReader = $configReader; - $this->configWriter = $configWriter; + $this->taskManager = $taskManager; + $this->objectManager = $objectManager; + $this->response = $response; } /** @@ -74,30 +54,44 @@ public function __construct( */ public function launch() { - $paths = ['app/code', 'lib/internal/Magento/Framework', 'var/generation']; - $definitionsCollection = new DefinitionsCollection(); - foreach ($paths as $path) { - $definitionsCollection->addCollection($this->getDefinitionsCollection(BP . '/' . $path)); - } - - $this->configWriter->write( - App\Area::AREA_GLOBAL, - $this->configReader->generateCachePerScope($definitionsCollection, App\Area::AREA_GLOBAL) + $this->objectManager->configure( + [ + 'preferences' => + [ + 'Magento\Tools\Di\Compiler\Config\WriterInterface' => + 'Magento\Tools\Di\Compiler\Config\Writer\Filesystem' + ] + ] ); - $this->interceptionConfigurationBuilder->addAreaCode(App\Area::AREA_GLOBAL); - foreach ($this->areaList->getCodes() as $areaCode) { - $this->interceptionConfigurationBuilder->addAreaCode($areaCode); - $this->configWriter->write( - $areaCode, - $this->configReader->generateCachePerScope($definitionsCollection, $areaCode, true) - ); - } - $this->generateInterceptors(); + $operations = [ + Task\OperationFactory::AREA => [ + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' + ], + Task\OperationFactory::INTERCEPTION => + BP . '/var/generation', + Task\OperationFactory::INTERCEPTION_CACHE => [ + BP . '/' . 'app/code', BP . '/' . 'lib/internal/Magento/Framework', BP . '/' . 'var/generation' + ] + ]; + + $responseCode = Response::SUCCESS; + try { + foreach ($operations as $operationCode => $arguments) { + $this->taskManager->addOperation( + $operationCode, + $arguments + ); + } + $this->taskManager->process(); + + } catch (Task\OperationException $e) { + $responseCode = Response::ERROR; + $this->response->setBody($e->getMessage()); + } - $response = new \Magento\Framework\App\Console\Response(); - $response->setCode(0); - return $response; + $this->response->setCode($responseCode); + return $this->response; } /** @@ -117,40 +111,4 @@ public function catchException(App\Bootstrap $bootstrap, \Exception $exception) { return false; } - - /** - * Returns definitions collection - * - * @param string $path - * @return DefinitionsCollection - */ - protected function getDefinitionsCollection($path) - { - $definitions = new DefinitionsCollection(); - foreach ($this->classesScanner->getList($path) as $className => $constructorArguments) { - $definitions->addDefinition($className, $constructorArguments); - } - return $definitions; - } - - /** - * Creates interceptors configuration and generates code - * - * @return void - */ - private function generateInterceptors() - { - $generatorIo = new \Magento\Framework\Code\Generator\Io( - new \Magento\Framework\Filesystem\Driver\File(), - BP . '/var/generation' - ); - $generator = new \Magento\Tools\Di\Code\Generator( - $generatorIo, - [ - Interceptor::ENTITY_TYPE => 'Magento\Tools\Di\Code\Generator\Interceptor', - ] - ); - $configuration = $this->interceptionConfigurationBuilder->getInterceptionConfiguration(get_declared_classes()); - $generator->generateList($configuration); - } } diff --git a/dev/tools/Magento/Tools/Di/App/Task/Manager.php b/dev/tools/Magento/Tools/Di/App/Task/Manager.php new file mode 100644 index 0000000000000..c9c0d0d048b7e --- /dev/null +++ b/dev/tools/Magento/Tools/Di/App/Task/Manager.php @@ -0,0 +1,53 @@ +operationFactory = $operationFactory; + } + + /** + * Adds operations to task + * + * @param string $operationCode + * @param mixed $arguments + * @return void + */ + public function addOperation($operationCode, $arguments = null) + { + $this->operationsList[] = $this->operationFactory->create($operationCode, $arguments); + } + + /** + * Processes list of operations + * + * @return void + */ + public function process() + { + /** @var OperationInterface $operation */ + foreach ($this->operationsList as $operation) { + $operation->doOperation(); + } + $this->operationsList = []; + } +} diff --git a/dev/tools/Magento/Tools/Di/App/Task/Operation/Area.php b/dev/tools/Magento/Tools/Di/App/Task/Operation/Area.php new file mode 100644 index 0000000000000..b57279ea62cca --- /dev/null +++ b/dev/tools/Magento/Tools/Di/App/Task/Operation/Area.php @@ -0,0 +1,99 @@ +areaList = $areaList; + $this->classesScanner = $classesScanner; + $this->configReader = $configReader; + $this->configWriter = $configWriter; + $this->data = $data; + } + + /** + * {@inheritdoc} + */ + public function doOperation() + { + if (empty($this->data)) { + return; + } + + $definitionsCollection = new DefinitionsCollection(); + foreach ($this->data as $path) { + $definitionsCollection->addCollection($this->getDefinitionsCollection($path)); + } + + $areaCodes = array_merge([App\Area::AREA_GLOBAL], $this->areaList->getCodes()); + foreach ($areaCodes as $areaCode) { + $this->configWriter->write( + $areaCode, + $this->configReader->generateCachePerScope($definitionsCollection, $areaCode) + ); + } + } + + /** + * Returns definitions collection + * + * @param string $path + * @return DefinitionsCollection + */ + protected function getDefinitionsCollection($path) + { + $definitions = new DefinitionsCollection(); + foreach ($this->classesScanner->getList($path) as $className => $constructorArguments) { + $definitions->addDefinition($className, $constructorArguments); + } + return $definitions; + } +} diff --git a/dev/tools/Magento/Tools/Di/App/Task/Operation/Interception.php b/dev/tools/Magento/Tools/Di/App/Task/Operation/Interception.php new file mode 100644 index 0000000000000..43bff9fa412ce --- /dev/null +++ b/dev/tools/Magento/Tools/Di/App/Task/Operation/Interception.php @@ -0,0 +1,72 @@ +interceptionConfigurationBuilder = $interceptionConfigurationBuilder; + $this->areaList = $areaList; + $this->data = $data; + } + + /** + * {@inheritdoc} + */ + public function doOperation() + { + if (empty($this->data)) { + return; + } + $this->interceptionConfigurationBuilder->addAreaCode(App\Area::AREA_GLOBAL); + + foreach ($this->areaList->getCodes() as $areaCode) { + $this->interceptionConfigurationBuilder->addAreaCode($areaCode); + } + + $generatorIo = new \Magento\Framework\Code\Generator\Io( + new \Magento\Framework\Filesystem\Driver\File(), + $this->data + ); + $generator = new \Magento\Tools\Di\Code\Generator( + $generatorIo, + [ + Interceptor::ENTITY_TYPE => 'Magento\Tools\Di\Code\Generator\Interceptor', + ] + ); + $configuration = $this->interceptionConfigurationBuilder->getInterceptionConfiguration(get_declared_classes()); + $generator->generateList($configuration); + } +} diff --git a/dev/tools/Magento/Tools/Di/App/Task/Operation/InterceptionCache.php b/dev/tools/Magento/Tools/Di/App/Task/Operation/InterceptionCache.php new file mode 100644 index 0000000000000..68230f3b3c97e --- /dev/null +++ b/dev/tools/Magento/Tools/Di/App/Task/Operation/InterceptionCache.php @@ -0,0 +1,65 @@ +data = $data; + $this->configInterface = $configInterface; + } + + /** + * Flushes interception cached configuration and generates a new one + * + * @return void + */ + public function doOperation() + { + if (empty($this->data)) { + return; + } + + $logWriter = new \Magento\Tools\Di\Compiler\Log\Writer\Quiet(); + $errorWriter = new \Magento\Tools\Di\Compiler\Log\Writer\Console(); + + $log = new \Magento\Tools\Di\Compiler\Log\Log($logWriter, $errorWriter); + + $validator = new \Magento\Framework\Code\Validator(); + $validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity()); + $validator->add(new \Magento\Framework\Code\Validator\ContextAggregation()); + + $directoryCompiler = new \Magento\Tools\Di\Compiler\Directory($log, $validator); + foreach ($this->data as $path) { + if (is_readable($path)) { + $directoryCompiler->compile($path); + } + } + + list($definitions, ) = $directoryCompiler->getResult(); + + $this->configInterface->initialize(array_keys($definitions)); + } +} diff --git a/dev/tools/Magento/Tools/Di/App/Task/OperationException.php b/dev/tools/Magento/Tools/Di/App/Task/OperationException.php new file mode 100644 index 0000000000000..5896bf352ee70 --- /dev/null +++ b/dev/tools/Magento/Tools/Di/App/Task/OperationException.php @@ -0,0 +1,14 @@ + 'Magento\Tools\Di\App\Task\Operation\Area', + self::INTERCEPTION => 'Magento\Tools\Di\App\Task\Operation\Interception', + self::INTERCEPTION_CACHE => 'Magento\Tools\Di\App\Task\Operation\InterceptionCache', + ]; + + /** + * @param \Magento\Framework\ObjectManagerInterface $objectManager + */ + public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager) + { + $this->objectManager = $objectManager; + } + + /** + * Creates operation + * + * @param string $operationAlias + * @param mixed $arguments + * @return OperationInterface + * @throws OperationException + */ + public function create($operationAlias, $arguments = null) + { + if (!array_key_exists($operationAlias, $this->operationsDefinitions)) { + throw new OperationException( + sprintf('Unrecognized operation "%s"', $operationAlias), + OperationException::UNAVAILABLE_OPERATION + ); + } + return $this->objectManager->create($this->operationsDefinitions[$operationAlias], ['data' => $arguments]); + } +} diff --git a/dev/tools/Magento/Tools/Di/App/Task/OperationInterface.php b/dev/tools/Magento/Tools/Di/App/Task/OperationInterface.php new file mode 100644 index 0000000000000..c81638f52c372 --- /dev/null +++ b/dev/tools/Magento/Tools/Di/App/Task/OperationInterface.php @@ -0,0 +1,16 @@ +diContainerConfig; - if ($extendConfig) { + if ($areaCode !== App\Area::AREA_GLOBAL) { $areaConfig->extend($this->configLoader->load($areaCode)); } $config = []; $config['arguments'] = $this->getConfigForScope($definitionsCollection, $areaConfig); + foreach ($config['arguments'] as $key => $value) { + if ($value !== null) { + $config['arguments'][$key] = serialize($value); + } + } foreach ($definitionsCollection->getInstancesNamesList() as $instanceName) { if (!$areaConfig->isShared($instanceName)) { $config['nonShared'][$instanceName] = true; diff --git a/dev/tools/Magento/Tools/Di/Compiler/Config/Writer/Filesystem.php b/dev/tools/Magento/Tools/Di/Compiler/Config/Writer/Filesystem.php index cb256545611de..b50d6a996c8b3 100644 --- a/dev/tools/Magento/Tools/Di/Compiler/Config/Writer/Filesystem.php +++ b/dev/tools/Magento/Tools/Di/Compiler/Config/Writer/Filesystem.php @@ -14,21 +14,16 @@ class Filesystem implements WriterInterface /** * Writes config in storage * - * @param string $areaCode + * @param string $key * @param array $config * @return void */ - public function write($areaCode, array $config) + public function write($key, array $config) { $this->initialize(); - foreach ($config['arguments'] as $key => $value) { - if ($value !== null) { - $config['arguments'][$key] = serialize($value); - } - } $serialized = serialize($config); - file_put_contents(BP . '/var/di/' . $areaCode . '.ser', $serialized); + file_put_contents(BP . '/var/di/' . $key . '.ser', $serialized); } /** diff --git a/dev/tools/Magento/Tools/Di/Compiler/Config/WriterInterface.php b/dev/tools/Magento/Tools/Di/Compiler/Config/WriterInterface.php index faf23c832ef22..0e54e3585f7ad 100644 --- a/dev/tools/Magento/Tools/Di/Compiler/Config/WriterInterface.php +++ b/dev/tools/Magento/Tools/Di/Compiler/Config/WriterInterface.php @@ -12,9 +12,9 @@ interface WriterInterface /** * Writes config in storage * - * @param string $areaCode + * @param string $key * @param array $config * @return void */ - public function write($areaCode, array $config); + public function write($key, array $config); } diff --git a/dev/tools/Magento/Tools/Di/compiler.php b/dev/tools/Magento/Tools/Di/compiler.php index 016251bfa18eb..fc0958c7d77a7 100644 --- a/dev/tools/Magento/Tools/Di/compiler.php +++ b/dev/tools/Magento/Tools/Di/compiler.php @@ -40,8 +40,8 @@ $generationDir = $opt->getOption('generation') ? $opt->getOption('generation') : $rootDir . '/var/generation'; $diDir = $opt->getOption('di') ? $opt->getOption('di') : $rootDir . '/var/di'; $compiledFile = $diDir . '/definitions.php'; - $relationsFile = $diDir . '/relations.php'; - $pluginDefFile = $diDir . '/plugins.php'; + $relationsFile = $diDir . '/relations.ser'; + $pluginDefFile = $diDir . '/plugins.ser'; $compilationDirs = [ $rootDir . '/app/code', diff --git a/lib/internal/Magento/Framework/App/Console/Response.php b/lib/internal/Magento/Framework/App/Console/Response.php index 6e88642a1e662..27c9871811fd6 100644 --- a/lib/internal/Magento/Framework/App/Console/Response.php +++ b/lib/internal/Magento/Framework/App/Console/Response.php @@ -21,6 +21,16 @@ class Response implements \Magento\Framework\App\ResponseInterface */ protected $code = 0; + /** + * Success code + */ + const SUCCESS = 0; + + /** + * Error code + */ + const ERROR = 255; + /** * Text to output on send response * diff --git a/lib/internal/Magento/Framework/Interception/Config/Config.php b/lib/internal/Magento/Framework/Interception/Config/Config.php index 0dff3eeeb4a19..24accda4ca3f5 100644 --- a/lib/internal/Magento/Framework/Interception/Config/Config.php +++ b/lib/internal/Magento/Framework/Interception/Config/Config.php @@ -100,17 +100,19 @@ public function __construct( if ($intercepted !== false) { $this->_intercepted = unserialize($intercepted); } else { - $this->initialize(); + $this->initialize($this->_classDefinitions->getClasses()); } } /** * Initialize interception config * + * @param array $classDefinitions * @return void */ - protected function initialize() + public function initialize($classDefinitions = []) { + $this->_cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [$this->_cacheId]); $config = []; foreach ($this->_scopeList->getAllScopes() as $scope) { $config = array_replace_recursive($config, $this->_reader->read($scope)); @@ -124,7 +126,7 @@ protected function initialize() foreach ($config as $typeName => $typeConfig) { $this->hasPlugins(ltrim($typeName, '\\')); } - foreach ($this->_classDefinitions->getClasses() as $class) { + foreach ($classDefinitions as $class) { $this->hasPlugins($class); } $this->_cache->save(serialize($this->_intercepted), $this->_cacheId); diff --git a/lib/internal/Magento/Framework/Interception/ConfigInterface.php b/lib/internal/Magento/Framework/Interception/ConfigInterface.php index 3b5d180ccaf43..6efec2266037d 100644 --- a/lib/internal/Magento/Framework/Interception/ConfigInterface.php +++ b/lib/internal/Magento/Framework/Interception/ConfigInterface.php @@ -16,4 +16,12 @@ interface ConfigInterface * @return bool */ public function hasPlugins($type); + + /** + * Initialize interception config + * + * @param array $classDefinitions + * @return void + */ + public function initialize($classDefinitions = []); } diff --git a/lib/internal/Magento/Framework/Object.php b/lib/internal/Magento/Framework/Object.php index 508c21c11c3ea..695be22ce6da3 100644 --- a/lib/internal/Magento/Framework/Object.php +++ b/lib/internal/Magento/Framework/Object.php @@ -545,7 +545,7 @@ protected function _underscore($name) if (isset(self::$_underscoreCache[$name])) { return self::$_underscoreCache[$name]; } - $result = strtolower(trim(preg_replace('/([A-Z]+|[0-9]+)/', "_$1", $name), '_')); + $result = strtolower(trim(preg_replace('/([A-Z]|[0-9]+)/', "_$1", $name), '_')); self::$_underscoreCache[$name] = $result; return $result; } diff --git a/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php b/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php index b5b13baec0deb..c71e32ac3cf7a 100644 --- a/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php +++ b/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php @@ -134,7 +134,7 @@ public function createClassDefinition($definitions, $useCompiled = true) */ public function createPluginDefinition() { - $path = $this->_definitionDir . '/plugins.php'; + $path = $this->_definitionDir . '/plugins.ser'; if ($this->_filesystemDriver->isReadable($path)) { return new \Magento\Framework\Interception\Definition\Compiled( $this->_unpack($this->_filesystemDriver->fileGetContents($path)) @@ -151,7 +151,7 @@ public function createPluginDefinition() */ public function createRelations() { - $path = $this->_definitionDir . '/' . 'relations.php'; + $path = $this->_definitionDir . '/' . 'relations.ser'; if ($this->_filesystemDriver->isReadable($path)) { return new \Magento\Framework\ObjectManager\Relations\Compiled( $this->_unpack($this->_filesystemDriver->fileGetContents($path))