-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MTA-3483: Create pull request and deliver extended functional tests t…
…o mainline
- Loading branch information
Showing
17 changed files
with
275 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/code/Magento/Quote/Model/Product/Plugin/RemoveQuoteItems.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Quote\Model\Product\Plugin; | ||
|
||
class RemoveQuoteItems | ||
{ | ||
/** | ||
* @var \Magento\Quote\Model\Product\QuoteItemsCleanerInterface | ||
*/ | ||
private $quoteItemsCleaner; | ||
|
||
/** | ||
* @param \Magento\Quote\Model\Product\QuoteItemsCleanerInterface $quoteItemsCleaner | ||
*/ | ||
public function __construct(\Magento\Quote\Model\Product\QuoteItemsCleanerInterface $quoteItemsCleaner) | ||
{ | ||
$this->quoteItemsCleaner = $quoteItemsCleaner; | ||
} | ||
|
||
/** | ||
* @param \Magento\Catalog\Model\ResourceModel\Product $subject | ||
* @param \Closure $proceed | ||
* @param \Magento\Catalog\Api\Data\ProductInterface $product | ||
* @return mixed | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
* TODO: reimplement with after plugin | ||
*/ | ||
public function aroundDelete( | ||
\Magento\Catalog\Model\ResourceModel\Product $subject, | ||
\Closure $proceed, | ||
\Magento\Catalog\Api\Data\ProductInterface $product | ||
) { | ||
$result = $proceed($product); | ||
$this->quoteItemsCleaner->execute($product); | ||
return $result; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/code/Magento/Quote/Model/Product/QuoteItemsCleaner.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Quote\Model\Product; | ||
|
||
class QuoteItemsCleaner implements \Magento\Quote\Model\Product\QuoteItemsCleanerInterface | ||
{ | ||
/** | ||
* @var \Magento\Quote\Model\ResourceModel\Quote\Item | ||
*/ | ||
private $itemResource; | ||
|
||
/** | ||
* @param \Magento\Quote\Model\ResourceModel\Quote\Item $itemResource | ||
*/ | ||
public function __construct(\Magento\Quote\Model\ResourceModel\Quote\Item $itemResource) | ||
{ | ||
$this->itemResource = $itemResource; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(\Magento\Catalog\Api\Data\ProductInterface $product) | ||
{ | ||
$this->itemResource->getConnection()->delete( | ||
$this->itemResource->getMainTable(), | ||
'product_id = ' . $product->getId() | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/code/Magento/Quote/Model/Product/QuoteItemsCleanerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Quote\Model\Product; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
|
||
interface QuoteItemsCleanerInterface | ||
{ | ||
/** | ||
* @param ProductInterface $product | ||
* @return void | ||
*/ | ||
public function execute(ProductInterface $product); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/code/Magento/Quote/Test/Unit/Model/Product/Plugin/RemoveQuoteItemsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Quote\Test\Unit\Model\Product\Plugin; | ||
|
||
class RemoveQuoteItemsTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Quote\Model\Product\Plugin\RemoveQuoteItems | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Product\QuoteItemsCleanerInterface | ||
*/ | ||
private $quoteItemsCleanerMock; | ||
|
||
protected function setUp() | ||
{ | ||
$this->quoteItemsCleanerMock = $this->getMock(\Magento\Quote\Model\Product\QuoteItemsCleanerInterface::class); | ||
$this->model = new \Magento\Quote\Model\Product\Plugin\RemoveQuoteItems($this->quoteItemsCleanerMock); | ||
} | ||
|
||
public function testAroundDelete() | ||
{ | ||
$productResourceMock = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false); | ||
$productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class); | ||
$closure = function () use ($productResourceMock) { | ||
return $productResourceMock; | ||
}; | ||
|
||
$this->quoteItemsCleanerMock->expects($this->once())->method('execute')->with($productMock); | ||
$result = $this->model->aroundDelete($productResourceMock, $closure, $productMock); | ||
$this->assertEquals($result, $productResourceMock); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/code/Magento/Quote/Test/Unit/Model/Product/QuoteItemsCleanerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Quote\Test\Unit\Model\Product; | ||
|
||
class QuoteItemsCleanerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Quote\Model\Product\QuoteItemsCleaner | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\ResourceModel\Quote\Item | ||
*/ | ||
private $itemResourceMock; | ||
|
||
protected function setUp() | ||
{ | ||
$this->itemResourceMock = $this->getMock( | ||
\Magento\Quote\Model\ResourceModel\Quote\Item::class, | ||
[], | ||
[], | ||
'', | ||
false | ||
); | ||
$this->model = new \Magento\Quote\Model\Product\QuoteItemsCleaner($this->itemResourceMock); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$tableName = 'table_name'; | ||
$productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class); | ||
$productMock->expects($this->once())->method('getId')->willReturn(1); | ||
|
||
$connectionMock = $this->getMock(\Magento\Framework\DB\Adapter\AdapterInterface::class); | ||
$this->itemResourceMock->expects($this->once())->method('getConnection')->willReturn($connectionMock); | ||
$this->itemResourceMock->expects($this->once())->method('getMainTable')->willReturn($tableName); | ||
|
||
$connectionMock->expects($this->once())->method('delete')->with($tableName, 'product_id = 1'); | ||
$this->model->execute($productMock); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.