Skip to content

Commit 2e455ae

Browse files
author
Tang, Yu(ytang1)
committed
Merge pull request #138 from magento-fearless-kiwis/FearlessKiwis-MAGETWO-32905-Refactor-API-Framework
[FearlessKiwis] S42-B: Remove immutability requirement
2 parents cef92a1 + da45599 commit 2e455ae

File tree

288 files changed

+3079
-5114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

288 files changed

+3079
-5114
lines changed

app/code/Magento/Bundle/Model/Plugin/BundleLoadOptions.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ class BundleLoadOptions
1515
protected $productOptionList;
1616

1717
/**
18-
* @var \Magento\Framework\Api\AttributeDataBuilder
18+
* @var \Magento\Framework\Api\AttributeValueFactory
1919
*/
20-
protected $customAttributeBuilder;
20+
protected $customAttributeFactory;
2121

2222
/**
2323
* @param \Magento\Bundle\Model\Product\OptionList $productOptionList
24-
* @param \Magento\Framework\Api\AttributeDataBuilder $customAttributeBuilder
24+
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
2525
*/
2626
public function __construct(
2727
\Magento\Bundle\Model\Product\OptionList $productOptionList,
28-
\Magento\Framework\Api\AttributeDataBuilder $customAttributeBuilder
28+
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
2929
) {
3030
$this->productOptionList = $productOptionList;
31-
$this->customAttributeBuilder = $customAttributeBuilder;
31+
$this->customAttributeFactory = $customAttributeFactory;
3232
}
3333

3434
/**
@@ -50,10 +50,9 @@ public function aroundLoad(
5050
if ($product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
5151
return $product;
5252
}
53-
$customAttribute = $this->customAttributeBuilder
53+
$customAttribute = $this->customAttributeFactory->create()
5454
->setAttributeCode('bundle_product_options')
55-
->setValue($this->productOptionList->getItems($product))
56-
->create();
55+
->setValue($this->productOptionList->getItems($product));
5756
$attributes = array_merge($product->getCustomAttributes(), ['bundle_product_options' => $customAttribute]);
5857
$product->setData('custom_attributes', $attributes);
5958
return $product;

app/code/Magento/Bundle/Test/Unit/Model/OptionRepositoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected function setUp()
6969
$this->productRepositoryMock = $this->getMock('\Magento\Catalog\Api\ProductRepositoryInterface');
7070
$this->typeMock = $this->getMock('\Magento\Bundle\Model\Product\Type', [], [], '', false);
7171
$this->optionFactoryMock = $this->getMockBuilder('\Magento\Bundle\Api\Data\OptionInterfaceFactory')
72+
->disableOriginalConstructor()
7273
->setMethods(['create'])
7374
->getMock();
7475
$this->dataObjectHelperMock = $this->getMockBuilder('\Magento\Framework\Api\DataObjectHelper')

app/code/Magento/Bundle/Test/Unit/Model/Plugin/BundleLoadOptionsTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class BundleLoadOptionsTest extends \PHPUnit_Framework_TestCase
2121
/**
2222
* @var \PHPUnit_Framework_MockObject_MockObject
2323
*/
24-
protected $attributeBuilderMock;
24+
protected $attributeFactoryMock;
2525

2626
protected function setUp()
2727
{
2828
$this->optionListMock = $this->getMock('\Magento\Bundle\Model\Product\OptionList', [], [], '', false);
29-
$this->attributeBuilderMock = $this->getMock('\Magento\Framework\Api\AttributeDataBuilder', [], [], '', false);
29+
$this->attributeFactoryMock = $this->getMock('\Magento\Framework\Api\AttributeValueFactory', [], [], '', false);
3030
$this->model = new \Magento\Bundle\Model\Plugin\BundleLoadOptions(
3131
$this->optionListMock,
32-
$this->attributeBuilderMock
32+
$this->attributeFactoryMock
3333
);
3434
}
3535

@@ -69,16 +69,16 @@ public function testAroundLoad()
6969
->method('getItems')
7070
->with($productMock)
7171
->willReturn([$optionMock]);
72-
$this->attributeBuilderMock->expects($this->once())
72+
$customAttributeMock = $this->getMock('\Magento\Framework\Api\AttributeValue', [], [], '', false);
73+
$customAttributeMock->expects($this->once())
7374
->method('setAttributeCode')
7475
->with('bundle_product_options')
7576
->willReturnSelf();
76-
$this->attributeBuilderMock->expects($this->once())
77+
$customAttributeMock->expects($this->once())
7778
->method('setValue')
7879
->with([$optionMock])
7980
->willReturnSelf();
80-
$customAttributeMock = $this->getMock('\Magento\Framework\Api\AttributeValue', [], [], '', false);
81-
$this->attributeBuilderMock->expects($this->once())->method('create')->willReturn($customAttributeMock);
81+
$this->attributeFactoryMock->expects($this->once())->method('create')->willReturn($customAttributeMock);
8282

8383
$productAttributeMock = $this->getMock('\Magento\Framework\Api\AttributeValue', [], [], '', false);
8484
$productMock->expects($this->once())->method('getCustomAttributes')->willReturn([$productAttributeMock]);

app/code/Magento/Catalog/Api/Data/CategoryAttributeSearchResultsInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ interface CategoryAttributeSearchResultsInterface extends \Magento\Framework\Api
1414
* @return \Magento\Catalog\Api\Data\CategoryAttributeInterface[]
1515
*/
1616
public function getItems();
17+
18+
/**
19+
* Set attributes list.
20+
*
21+
* @param \Magento\Catalog\Api\Data\CategoryAttributeInterface[] $items
22+
* @return $this
23+
*/
24+
public function setItems(array $items = null);
1725
}

0 commit comments

Comments
 (0)