Skip to content

Commit f721b69

Browse files
committed
Product image builder - Override attributes when builder used multiple times
Simplify getting mocks in unit tests
1 parent 9f0b1af commit f721b69

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

app/code/Magento/Catalog/Test/Unit/Block/Product/ImageBuilderTest.php

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,16 @@ class ImageBuilderTest extends \PHPUnit\Framework\TestCase
2929

3030
protected function setUp()
3131
{
32-
$this->helperFactory = $this->getMockBuilder(\Magento\Catalog\Helper\ImageFactory::class)
33-
->disableOriginalConstructor()
34-
->setMethods(['create'])
35-
->getMock();
32+
$this->helperFactory = $this->createPartialMock(\Magento\Catalog\Helper\ImageFactory::class, ['create']);
3633

37-
$this->imageFactory = $this->getMockBuilder(ImageFactory::class)
38-
->disableOriginalConstructor()
39-
->setMethods(['create'])
40-
->getMock();
34+
$this->imageFactory = $this->createPartialMock(ImageFactory::class, ['create']);
4135

4236
$this->model = new ImageBuilder($this->helperFactory, $this->imageFactory);
4337
}
4438

4539
public function testSetProduct()
4640
{
47-
$productMock = $this->getMockBuilder(Product::class)
48-
->disableOriginalConstructor()
49-
->getMock();
41+
$productMock = $this->createMock(Product::class);
5042

5143
$this->assertInstanceOf(
5244
ImageBuilder::class,
@@ -83,13 +75,9 @@ public function testCreate($data, $expected)
8375
{
8476
$imageId = 'test_image_id';
8577

86-
$productMock = $this->getMockBuilder(Product::class)
87-
->disableOriginalConstructor()
88-
->getMock();
78+
$productMock = $this->createMock(Product::class);
8979

90-
$helperMock = $this->getMockBuilder(Image::class)
91-
->disableOriginalConstructor()
92-
->getMock();
80+
$helperMock = $this->createMock(Image::class);
9381
$helperMock->expects($this->once())
9482
->method('init')
9583
->with($productMock, $imageId)
@@ -118,9 +106,7 @@ public function testCreate($data, $expected)
118106
->method('create')
119107
->willReturn($helperMock);
120108

121-
$imageMock = $this->getMockBuilder(\Magento\Catalog\Block\Product\Image::class)
122-
->disableOriginalConstructor()
123-
->getMock();
109+
$imageMock = $this->createMock(\Magento\Catalog\Block\Product\Image::class);
124110

125111
$this->imageFactory->expects($this->once())
126112
->method('create')
@@ -144,13 +130,9 @@ public function testCreateMultipleCalls($data)
144130

145131
$imageId = 'test_image_id';
146132

147-
$productMock = $this->getMockBuilder(Product::class)
148-
->disableOriginalConstructor()
149-
->getMock();
133+
$productMock = $this->createMock(Product::class);
150134

151-
$helperMock = $this->getMockBuilder(Image::class)
152-
->disableOriginalConstructor()
153-
->getMock();
135+
$helperMock = $this->createMock(Image::class);
154136
$helperMock->expects($this->exactly(2))
155137
->method('init')
156138
->with($productMock, $imageId)
@@ -188,9 +170,7 @@ public function testCreateMultipleCalls($data)
188170
->method('create')
189171
->willReturn($helperMock);
190172

191-
$imageMock = $this->getMockBuilder(\Magento\Catalog\Block\Product\Image::class)
192-
->disableOriginalConstructor()
193-
->getMock();
173+
$imageMock = $this->createMock(\Magento\Catalog\Block\Product\Image::class);
194174

195175
$this->imageFactory->expects($this->at(0))
196176
->method('create')

0 commit comments

Comments
 (0)