Skip to content

Commit 4e80560

Browse files
author
Yu Tang
committed
MAGETWO-28256: Bundle Integration API Refactoring
- Fix unit test error
1 parent 6d0f88b commit 4e80560

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class BundleSaveOptionsTest extends \PHPUnit_Framework_TestCase
4343
*/
4444
protected $productBundleOptionsMock;
4545

46+
/**
47+
* @var \PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
protected $productInterfaceFactoryMock;
50+
4651
/**
4752
* @var \Closure
4853
*/
@@ -62,7 +67,12 @@ protected function setUp()
6267
$this->closureMock = function () {
6368
return $this->productMock;
6469
};
65-
$this->plugin = new BundleSaveOptions($this->productOptionRepositoryMock);
70+
$this->productInterfaceFactoryMock = $this->getMockBuilder('Magento\Catalog\Api\Data\ProductInterfaceFactory')
71+
->disableOriginalConstructor()->getMock();
72+
$this->plugin = new BundleSaveOptions(
73+
$this->productOptionRepositoryMock,
74+
$this->productInterfaceFactoryMock
75+
);
6676
$this->productExtensionMock = $this->getMock(
6777
'Magento\Catalog\Api\Data\ProductExtension',
6878
['getBundleProductOptions'],
@@ -122,16 +132,30 @@ public function testAroundSaveWhenProductIsBundleWithOptions()
122132

123133
$this->productOptionRepositoryMock->expects($this->once())->method('save')->with($this->productMock, $option);
124134

125-
$this->productMock->expects($this->once())->method('getSku')
135+
$this->productMock->expects($this->exactly(2))->method('getSku')
126136
->will($this->returnValue($productSku));
127137

128138
$this->productOptionRepositoryMock->expects($this->once())
129139
->method('getList')
130140
->with($productSku)
131141
->will($this->returnValue([]));
132142

143+
$newProductMock = $this->getMockBuilder('Magento\Catalog\Api\Data\ProductInterface')
144+
->disableOriginalConstructor()->getMock();
145+
$newProductMock->expects($this->once())
146+
->method('setSku')
147+
->with($productSku)
148+
->willReturnSelf();
149+
$this->productInterfaceFactoryMock->expects($this->once())
150+
->method('create')
151+
->willReturn($newProductMock);
152+
$this->productRepositoryMock->expects($this->once())
153+
->method('save')
154+
->with($newProductMock)
155+
->willReturn($newProductMock);
156+
133157
$this->assertEquals(
134-
$this->productMock,
158+
$newProductMock,
135159
$this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock)
136160
);
137161
}
@@ -170,7 +194,7 @@ public function testAroundSaveWhenProductIsBundleWithOptionsAndExistingOptions()
170194
$this->productExtensionMock->expects($this->once())
171195
->method('getBundleProductOptions')
172196
->willReturn([$bundleOptionExisting, $bundleOptionNew]);
173-
$this->productMock->expects($this->once())->method('getSku')
197+
$this->productMock->expects($this->exactly(2))->method('getSku')
174198
->will($this->returnValue($productSku));
175199

176200
$this->productOptionRepositoryMock->expects($this->once())
@@ -193,8 +217,22 @@ public function testAroundSaveWhenProductIsBundleWithOptionsAndExistingOptions()
193217
->method('delete')
194218
->with($existingOption2);
195219

220+
$newProductMock = $this->getMockBuilder('Magento\Catalog\Api\Data\ProductInterface')
221+
->disableOriginalConstructor()->getMock();
222+
$newProductMock->expects($this->once())
223+
->method('setSku')
224+
->with($productSku)
225+
->willReturnSelf();
226+
$this->productInterfaceFactoryMock->expects($this->once())
227+
->method('create')
228+
->willReturn($newProductMock);
229+
$this->productRepositoryMock->expects($this->once())
230+
->method('save')
231+
->with($newProductMock)
232+
->willReturn($newProductMock);
233+
196234
$this->assertEquals(
197-
$this->productMock,
235+
$newProductMock,
198236
$this->plugin->aroundSave($this->productRepositoryMock, $this->closureMock, $this->productMock)
199237
);
200238
}

0 commit comments

Comments
 (0)