From 7d0e8a06bb336c1324e85bf508e83a20fefd039d Mon Sep 17 00:00:00 2001
From: Cari Spruiell <cspruiell@ebay.com>
Date: Wed, 22 Apr 2015 15:14:39 -0500
Subject: [PATCH] MAGETWO-36376: Magento\Quote\Api\GuestCartItemRepository

 - removed delete methods from non-guest versions CartItemRepositoryInterface and Repository
---
 .../Quote/Api/CartItemRepositoryInterface.php |  9 ----
 .../Quote/Model/Quote/Item/Repository.php     | 15 +------
 .../GuestCart/GuestCartItemRepositoryTest.php | 11 -----
 .../Unit/Model/Quote/Item/RepositoryTest.php  | 44 ++-----------------
 4 files changed, 4 insertions(+), 75 deletions(-)

diff --git a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php
index e2ef0aa8102..96787607500 100644
--- a/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php
+++ b/app/code/Magento/Quote/Api/CartItemRepositoryInterface.php
@@ -27,15 +27,6 @@ interface CartItemRepositoryInterface
      */
     public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem);
 
-    /**
-     * Delete cart item
-     *
-     * @param \Magento\Quote\Api\Data\CartItemInterface $cartItem
-     * @return void
-     * @throws \Magento\Framework\Exception\CouldNotSaveException
-     */
-    public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem);
-
     /**
      * Removes the specified item from the specified cart.
      *
diff --git a/app/code/Magento/Quote/Model/Quote/Item/Repository.php b/app/code/Magento/Quote/Model/Quote/Item/Repository.php
index 0a4374e2e55..35b928ecb37 100644
--- a/app/code/Magento/Quote/Model/Quote/Item/Repository.php
+++ b/app/code/Magento/Quote/Model/Quote/Item/Repository.php
@@ -107,10 +107,8 @@ class Repository implements \Magento\Quote\Api\CartItemRepositoryInterface
     /**
      * {@inheritdoc}
      */
-    public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem)
+    public function deleteById($cartId, $itemId)
     {
-        $cartId = $cartItem->getQuoteId();
-        $itemId = $cartItem->getItemId();
         /**
          * Quote.
          *
@@ -129,18 +127,7 @@ class Repository implements \Magento\Quote\Api\CartItemRepositoryInterface
         } catch (\Exception $e) {
             throw new CouldNotSaveException(__('Could not remove item from quote'));
         }
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function deleteById($cartId, $itemId)
-    {
-        $item = $this->itemDataFactory->create()
-            ->setQuoteId($cartId)
-            ->setItemId($itemId);
 
-        $this->delete($item);
         return true;
     }
 
diff --git a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php
index 37b54ee8010..9535e3c1c74 100644
--- a/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php
+++ b/app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCartItemRepositoryTest.php
@@ -130,15 +130,4 @@ class GuestCartItemRepositoryTest extends \PHPUnit_Framework_TestCase
             ->willReturn(true);
         $this->assertTrue($this->guestCartItemRepository->deleteById($this->maskedCartId, $itemId));
     }
-
-    /**
-     * @return void
-     */
-    public function testDelete()
-    {
-        $this->cartItemRepositoryMock->expects($this->once())
-            ->method('delete')
-            ->with($this->quoteItemMock);
-        $this->guestCartItemRepository->delete($this->quoteItemMock);
-    }
 }
diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php
index 754c1bd1e46..9081537f279 100644
--- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php
+++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/RepositoryTest.php
@@ -7,7 +7,7 @@
 
 namespace Magento\Quote\Test\Unit\Model\Quote\Item;
 
-use \Magento\Quote\Model\Quote\Item\Repository;
+use Magento\Quote\Model\Quote\Item\Repository;
 
 class RepositoryTest extends \PHPUnit_Framework_TestCase
 {
@@ -292,15 +292,13 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
     {
         $cartId = 11;
         $itemId = 5;
-        $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
-        $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);
         $this->quoteRepositoryMock->expects($this->once())
             ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
         $this->quoteMock->expects($this->once())
             ->method('getItemById')->with($itemId)->will($this->returnValue(false));
         $this->quoteMock->expects($this->never())->method('removeItem');
 
-        $this->repository->delete($this->dataMock);
+        $this->repository->deleteById($cartId, $itemId);
     }
 
     /**
@@ -312,8 +310,6 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
     {
         $cartId = 11;
         $itemId = 5;
-        $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
-        $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);
         $this->quoteRepositoryMock->expects($this->once())
             ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
         $this->quoteMock->expects($this->once())
@@ -328,27 +324,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
             ->with($this->quoteMock)
             ->willThrowException($exception);
 
-        $this->repository->delete($this->dataMock);
-    }
-
-    /**
-     * @return void
-     */
-    public function testDelete()
-    {
-        $cartId = 11;
-        $itemId = 5;
-        $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
-        $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);
-        $this->quoteRepositoryMock->expects($this->once())
-            ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
-        $this->quoteMock->expects($this->once())
-            ->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock));
-        $this->quoteMock->expects($this->once())->method('removeItem');
-        $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
-        $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
-
-        $this->repository->delete($this->dataMock);
+        $this->repository->deleteById($cartId, $itemId);
     }
 
     /**
@@ -363,13 +339,6 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
             ->with($customerId)
             ->will($this->returnValue($this->quoteMock));
         $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
-        $this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock);
-        $this->dataMock->expects($this->once())->method('setQuoteId')
-            ->with($cartId)->willReturn($this->dataMock);
-        $this->dataMock->expects($this->once())->method('setItemId')
-            ->with($itemId)->willReturn($this->dataMock);
-        $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
-        $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);
         $this->quoteRepositoryMock->expects($this->once())
             ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
         $this->quoteMock->expects($this->once())
@@ -424,13 +393,6 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
     {
         $cartId = 11;
         $itemId = 5;
-        $this->itemDataFactoryMock->expects($this->once())->method('create')->willReturn($this->dataMock);
-        $this->dataMock->expects($this->once())->method('setQuoteId')
-            ->with($cartId)->willReturn($this->dataMock);
-        $this->dataMock->expects($this->once())->method('setItemId')
-            ->with($itemId)->willReturn($this->dataMock);
-        $this->dataMock->expects($this->once())->method('getQuoteId')->willReturn($cartId);
-        $this->dataMock->expects($this->once())->method('getItemId')->willReturn($itemId);
         $this->quoteRepositoryMock->expects($this->once())
             ->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
         $this->quoteMock->expects($this->once())
-- 
GitLab