5
5
*/
6
6
namespace Magento \Catalog \Test \Unit \Model \Product ;
7
7
8
+ use Magento \Catalog \Api \Data \ProductExtension ;
8
9
use Magento \Catalog \Api \Data \ProductInterface ;
9
10
use Magento \Catalog \Model \Attribute \ScopeOverriddenValue ;
10
11
use Magento \Catalog \Model \Product ;
11
12
use Magento \Catalog \Model \Product \Copier ;
13
+ use Magento \Catalog \Model \Product \CopyConstructorInterface ;
14
+ use Magento \Catalog \Model \Product \Option \Repository ;
15
+ use Magento \Catalog \Model \ProductFactory ;
16
+ use Magento \CatalogInventory \Api \Data \StockItemInterface ;
17
+ use Magento \Framework \EntityManager \EntityMetadata ;
18
+ use Magento \Framework \EntityManager \MetadataPool ;
19
+ use PHPUnit \Framework \MockObject \MockObject ;
12
20
13
21
/**
14
22
* Test for Magento\Catalog\Model\Product\Copier class.
18
26
class CopierTest extends \PHPUnit \Framework \TestCase
19
27
{
20
28
/**
21
- * @var \PHPUnit_Framework_MockObject_MockObject
29
+ * @var MockObject
22
30
*/
23
- protected $ optionRepositoryMock ;
31
+ private $ optionRepositoryMock ;
24
32
25
33
/**
26
34
* @var Copier
27
35
*/
28
- protected $ _model ;
36
+ private $ _model ;
29
37
30
38
/**
31
- * @var \PHPUnit_Framework_MockObject_MockObject
39
+ * @var MockObject
32
40
*/
33
- protected $ copyConstructorMock ;
41
+ private $ copyConstructorMock ;
34
42
35
43
/**
36
- * @var \PHPUnit_Framework_MockObject_MockObject
44
+ * @var MockObject
37
45
*/
38
- protected $ productFactoryMock ;
46
+ private $ productFactoryMock ;
39
47
40
48
/**
41
- * @var \PHPUnit_Framework_MockObject_MockObject
49
+ * @var MockObject
42
50
*/
43
- protected $ productMock ;
51
+ private $ productMock ;
44
52
45
53
/**
46
- * @var \PHPUnit_Framework_MockObject_MockObject
54
+ * @var MockObject
47
55
*/
48
- protected $ metadata ;
56
+ private $ metadata ;
49
57
50
58
/**
51
- * @var ScopeOverriddenValue|\PHPUnit_Framework_MockObject_MockObject
59
+ * @var ScopeOverriddenValue|MockObject
52
60
*/
53
61
private $ scopeOverriddenValue ;
54
62
63
+ /**
64
+ * @ingeritdoc
65
+ */
55
66
protected function setUp ()
56
67
{
57
- $ this ->copyConstructorMock = $ this ->createMock (\Magento \Catalog \Model \Product \CopyConstructorInterface::class);
58
- $ this ->productFactoryMock = $ this ->createPartialMock (
59
- \Magento \Catalog \Model \ProductFactory::class,
60
- ['create ' ]
61
- );
62
- $ this ->optionRepositoryMock = $ this ->createMock (
63
- \Magento \Catalog \Model \Product \Option \Repository::class
64
- );
65
- $ this ->optionRepositoryMock ;
68
+ $ this ->metadata = $ this ->createMock (EntityMetadata::class);
69
+ $ metadataPool = $ this ->createMock (MetadataPool::class);
70
+
71
+ $ this ->copyConstructorMock = $ this ->createMock (CopyConstructorInterface::class);
72
+ $ this ->productFactoryMock = $ this ->createPartialMock (ProductFactory::class, ['create ' ]);
73
+ $ this ->optionRepositoryMock = $ this ->createMock (Repository::class);
66
74
$ this ->productMock = $ this ->createMock (Product::class);
67
- $ this ->productMock ->expects ($ this ->any ())->method ('getEntityId ' )->willReturn (1 );
68
75
$ this ->scopeOverriddenValue = $ this ->createMock (ScopeOverriddenValue::class);
69
76
70
- $ this ->metadata = $ this ->getMockBuilder (\Magento \Framework \EntityManager \EntityMetadata::class)
71
- ->disableOriginalConstructor ()
72
- ->getMock ();
73
- $ metadataPool = $ this ->getMockBuilder (\Magento \Framework \EntityManager \MetadataPool::class)
74
- ->disableOriginalConstructor ()
75
- ->getMock ();
76
- $ metadataPool ->expects ($ this ->any ())->method ('getMetadata ' )->willReturn ($ this ->metadata );
77
+ $ this ->productMock ->expects ($ this ->any ())
78
+ ->method ('getEntityId ' )
79
+ ->willReturn (1 );
80
+ $ metadataPool ->expects ($ this ->any ())
81
+ ->method ('getMetadata ' )
82
+ ->willReturn ($ this ->metadata );
77
83
78
84
$ this ->_model = new Copier (
79
85
$ this ->copyConstructorMock ,
@@ -95,9 +101,8 @@ protected function setUp()
95
101
*/
96
102
public function testCopy ()
97
103
{
98
- $ stockItem = $ this ->getMockBuilder (\Magento \CatalogInventory \Api \Data \StockItemInterface::class)
99
- ->getMock ();
100
- $ extensionAttributes = $ this ->getMockBuilder (\Magento \Catalog \Api \Data \ProductExtension::class)
104
+ $ stockItem = $ this ->createMock (StockItemInterface::class);
105
+ $ extensionAttributes = $ this ->getMockBuilder (ProductExtension::class)
101
106
->setMethods (['getStockItem ' , 'setData ' ])
102
107
->getMock ();
103
108
$ extensionAttributes
@@ -179,6 +184,9 @@ public function testCopy()
179
184
'setUrlKey ' ,
180
185
'setStoreId ' ,
181
186
'getStoreIds ' ,
187
+ 'setMetaTitle ' ,
188
+ 'setMetaKeyword ' ,
189
+ 'setMetaDescription '
182
190
]
183
191
);
184
192
$ this ->productFactoryMock ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ duplicateMock ));
@@ -216,7 +224,6 @@ public function testCopy()
216
224
$ this ->optionRepositoryMock ->expects ($ this ->once ())
217
225
->method ('duplicate ' )
218
226
->with ($ this ->productMock , $ duplicateMock );
219
- $ resourceMock ->expects ($ this ->once ())->method ('duplicate ' )->with (1 , 2 );
220
227
221
228
$ this ->assertEquals ($ duplicateMock , $ this ->_model ->copy ($ this ->productMock ));
222
229
}
0 commit comments