Skip to content

Commit 39e92e9

Browse files
committed
MAGETWO-57685: Around plugins refactoring: refactor and fix/cover with unit tests
1 parent 010156f commit 39e92e9

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

app/code/Magento/Quote/Model/Product/Plugin/RemoveQuoteItems.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ public function __construct(\Magento\Quote\Model\Product\QuoteItemsCleanerInterf
2222

2323
/**
2424
* @param \Magento\Catalog\Model\ResourceModel\Product $subject
25-
* @param \Closure $proceed
25+
* @param \Magento\Catalog\Model\ResourceModel\Product $result
2626
* @param \Magento\Catalog\Api\Data\ProductInterface $product
27-
* @return mixed
27+
* @return \Magento\Catalog\Model\ResourceModel\Product
2828
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
29-
* TODO: reimplement with after plugin
3029
*/
31-
public function aroundDelete(
30+
public function afterDelete(
3231
\Magento\Catalog\Model\ResourceModel\Product $subject,
33-
\Closure $proceed,
32+
\Magento\Catalog\Model\ResourceModel\Product $result,
3433
\Magento\Catalog\Api\Data\ProductInterface $product
3534
) {
36-
$result = $proceed($product);
3735
$this->quoteItemsCleaner->execute($product);
3836
return $result;
3937
}

app/code/Magento/Quote/Test/Unit/Model/Product/Plugin/RemoveQuoteItemsTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ protected function setUp()
2323
$this->model = new \Magento\Quote\Model\Product\Plugin\RemoveQuoteItems($this->quoteItemsCleanerMock);
2424
}
2525

26-
public function testAroundDelete()
26+
public function testAfterDelete()
2727
{
2828
$productResourceMock = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false);
2929
$productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class);
30-
$closure = function () use ($productResourceMock) {
31-
return $productResourceMock;
32-
};
3330

3431
$this->quoteItemsCleanerMock->expects($this->once())->method('execute')->with($productMock);
35-
$result = $this->model->aroundDelete($productResourceMock, $closure, $productMock);
32+
$result = $this->model->afterDelete($productResourceMock, $productResourceMock, $productMock);
3633
$this->assertEquals($result, $productResourceMock);
3734
}
3835
}

0 commit comments

Comments
 (0)