public function testGetPaymentIsDeleted() { $this->quote->setId(1); $payment = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', ['setQuote', 'isDeleted', 'getId', '__wakeup'], [], '', false); $payment->expects($this->exactly(2))->method('setQuote'); $payment->expects($this->once())->method('isDeleted')->willReturn(true); $payment->expects($this->once())->method('getId')->willReturn(1); $quotePaymentCollectionMock = $this->getMock('Magento\\Quote\\Model\\Resource\\Quote\\Payment\\Collection', ['setQuoteFilter', 'getFirstItem'], [], '', false); $quotePaymentCollectionMock->expects($this->once())->method('setQuoteFilter')->with(1)->will($this->returnSelf()); $quotePaymentCollectionMock->expects($this->once())->method('getFirstItem')->willReturn($payment); $this->quotePaymentCollectionFactoryMock->expects($this->once())->method('create')->willReturn($quotePaymentCollectionMock); $this->paymentFactoryMock->expects($this->once())->method('create')->willReturn($payment); $this->assertInstanceOf('\\Magento\\Quote\\Model\\Quote\\Payment', $this->quote->getPayment()); }
/** * @return \Magento\Quote\Model\Quote\Payment */ public function getPayment() { if (null === $this->_currentPayment || !$this->_currentPayment) { $this->_currentPayment = $this->_quotePaymentCollectionFactory->create()->setQuoteFilter($this->getId())->getFirstItem(); } if ($payment = $this->_currentPayment) { if ($this->getId()) { $payment->setQuote($this); } if (!$payment->isDeleted()) { return $payment; } } $payment = $this->_quotePaymentFactory->create(); $this->addPayment($payment); return $payment; }