Skip to content

Commit 457e5f5

Browse files
committed
MAGETWO-35824: [MX] [Dragons] Code coverage - Sprint 67
MAGETWO-36990: Coverage or refactoring method \Magento\Bundle\Model\Product\Type::save
1 parent f54366a commit 457e5f5

File tree

1 file changed

+88
-5
lines changed

1 file changed

+88
-5
lines changed

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
*/
1717
class TypeTest extends \PHPUnit_Framework_TestCase
1818
{
19+
/**
20+
* @var \Magento\Bundle\Model\Resource\BundleFactory|\PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
private $bundleFactory;
23+
/**
24+
* @var \Magento\Bundle\Model\SelectionFactory|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $bundleModelSelection;
1927
/**
2028
* @var \Magento\Bundle\Model\Product\Type
2129
*/
@@ -96,19 +104,18 @@ protected function setUp()
96104
->setMethods(['convert'])
97105
->disableOriginalConstructor()
98106
->getMockForAbstractClass();
99-
$bundleModelSelection = $this->getMockBuilder('\Magento\Bundle\Model\SelectionFactory')
107+
$this->bundleModelSelection = $this->getMockBuilder('Magento\Bundle\Model\SelectionFactory')
100108
->disableOriginalConstructor()
101109
->getMock();
102-
$bundleFactory = $this->getMockBuilder('\Magento\Bundle\Model\Resource\BundleFactory')
110+
$this->bundleFactory = $this->getMockBuilder('\Magento\Bundle\Model\Resource\BundleFactory')
103111
->disableOriginalConstructor()
104112
->getMock();
105-
106113
$objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
107114
$this->model = $objectHelper->getObject(
108115
'Magento\Bundle\Model\Product\Type',
109116
[
110-
'bundleModelSelection' => $bundleModelSelection,
111-
'bundleFactory' => $bundleFactory,
117+
'bundleModelSelection' => $this->bundleModelSelection,
118+
'bundleFactory' => $this->bundleFactory,
112119
'bundleCollection' => $this->bundleCollection,
113120
'bundleOption' => $this->bundleOptionFactory,
114121
'catalogData' => $this->catalogData,
@@ -2427,4 +2434,80 @@ protected function parentClass($group, $option, $buyRequest, $product)
24272434
->method('getSkipSaleableCheck')
24282435
->willReturn(false);
24292436
}
2437+
2438+
public function testSave()
2439+
{
2440+
$options = [
2441+
'some_option' => ['option_id' => '', 'delete' => false],
2442+
];
2443+
$selections = [
2444+
'some_option' => [
2445+
123 => ['selection_id' => '', 'delete' => false],
2446+
]
2447+
];
2448+
2449+
$resource = $this->getMockBuilder('Magento\Bundle\Model\Resource\Bundle')
2450+
->disableOriginalConstructor()
2451+
->getMock();
2452+
$this->bundleFactory->expects($this->once())
2453+
->method('create')
2454+
->willReturn($resource);
2455+
2456+
$product = $this->getMockBuilder('Magento\Catalog\Model\Product')
2457+
->setMethods(
2458+
[
2459+
// 'getOptions',
2460+
// 'prepareCustomOptions',
2461+
// 'addCustomOption',
2462+
// 'setCartQty',
2463+
// 'setQty',
2464+
// 'getSkipCheckRequiredOption',
2465+
// 'getTypeInstance',
2466+
'getStoreId',
2467+
'getOrigData',
2468+
// 'hasData',
2469+
'getData',
2470+
'getBundleOptionsData',
2471+
'getBundleSelectionsData'
2472+
]
2473+
)
2474+
->disableOriginalConstructor()
2475+
->getMock();
2476+
$product->expects($this->once())
2477+
->method('getBundleOptionsData')
2478+
->willReturn($options);
2479+
$product->expects($this->once())
2480+
->method('getBundleSelectionsData')
2481+
->willReturn($selections);
2482+
$option = $this->getMockBuilder('Magento\Bundle\Model\Resource\Option\Collection')
2483+
->setMethods(['setData', 'setParentId', 'setStoreId', 'isDeleted', 'save', 'getOptionId'])
2484+
->disableOriginalConstructor()
2485+
->getMock();
2486+
$option->expects($this->once())->method('setData')->willReturnSelf();
2487+
$option->expects($this->once())->method('setParentId')->willReturnSelf();
2488+
$option->expects($this->once())->method('setStoreId')->willReturnSelf();
2489+
$this->bundleOptionFactory->expects($this->once())->method('create')->will($this->returnValue($option));
2490+
2491+
$selection = $this->getMockBuilder('Magento\Bundle\Model\Selection')
2492+
->setMethods(['setData', 'setOptionId', 'setParentProductId', 'setWebsiteId', 'save'])
2493+
->disableOriginalConstructor()
2494+
->getMock();
2495+
$selection->expects($this->once())->method('setData')->willReturnSelf();
2496+
$selection->expects($this->once())->method('setOptionId')->willReturnSelf();
2497+
$selection->expects($this->once())->method('setParentProductId')->willReturnSelf();
2498+
$selection->expects($this->once())->method('setWebsiteId')->willReturnSelf();
2499+
$selection->expects($this->once())->method('setParentProductId')->willReturnSelf();
2500+
$this->bundleModelSelection->expects($this->once())->method('create')->willReturn($selection);
2501+
$store = $this->getMockBuilder('Magento\Store\Model\Store')
2502+
->setMethods(['getWebsiteId', '__wakeup'])
2503+
->disableOriginalConstructor()
2504+
->getMock();
2505+
$this->storeManager->expects($this->once())
2506+
->method('getStore')
2507+
->will($this->returnValue($store));
2508+
$store->expects($this->once())
2509+
->method('getWebsiteId')
2510+
->will($this->returnValue(10));
2511+
$this->model->save($product);
2512+
}
24302513
}

0 commit comments

Comments
 (0)