3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magento \Review \Test \Unit \Block \Adminhtml ;
8
9
9
10
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
11
+ use Magento \Customer \Api \CustomerRepositoryInterface ;
12
+ use Magento \Customer \Helper \View as ViewHelper ;
13
+ use Magento \Customer \Api \Data \CustomerInterface ;
14
+ use Magento \Framework \App \RequestInterface ;
15
+ use Magento \Review \Block \Adminhtml \Main as MainBlock ;
16
+ use Magento \Framework \DataObject ;
17
+ use Magento \Catalog \Model \ResourceModel \Product \Collection ;
18
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
10
19
20
+ /**
21
+ * Unit Test For Main Block
22
+ *
23
+ * Class \Magento\Review\Test\Unit\Block\Adminhtml\MainTest
24
+ */
11
25
class MainTest extends \PHPUnit \Framework \TestCase
12
26
{
13
27
/**
14
- * @var \Magento\Review\Block\Adminhtml\Main
28
+ * @var MainBlock
15
29
*/
16
30
protected $ model ;
17
31
18
32
/**
19
- * @var \Magento\Framework\App\ RequestInterface|\PHPUnit_Framework_MockObject_MockObject
33
+ * @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
20
34
*/
21
35
protected $ request ;
22
36
23
37
/**
24
- * @var \Magento\Customer\Api\ CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
38
+ * @var CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
25
39
*/
26
40
protected $ customerRepository ;
27
41
28
42
/**
29
- * @var \Magento\Customer\Helper\View |\PHPUnit_Framework_MockObject_MockObject
43
+ * @var ViewHelper |\PHPUnit_Framework_MockObject_MockObject
30
44
*/
31
45
protected $ customerViewHelper ;
32
46
47
+ /**
48
+ * @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
49
+ */
50
+ protected $ collectionFactory ;
51
+
33
52
public function testConstruct ()
34
53
{
35
54
$ this ->customerRepository = $ this
36
- ->getMockForAbstractClass (\Magento \Customer \Api \CustomerRepositoryInterface::class);
37
- $ this ->customerViewHelper = $ this ->createMock (\Magento \Customer \Helper \View::class);
38
- $ dummyCustomer = $ this ->getMockForAbstractClass (\Magento \Customer \Api \Data \CustomerInterface::class);
55
+ ->getMockForAbstractClass (CustomerRepositoryInterface::class);
56
+ $ this ->customerViewHelper = $ this ->createMock (ViewHelper::class);
57
+ $ this ->collectionFactory = $ this ->createMock (CollectionFactory::class);
58
+ $ dummyCustomer = $ this ->getMockForAbstractClass (CustomerInterface::class);
39
59
40
60
$ this ->customerRepository ->expects ($ this ->once ())
41
61
->method ('getById ' )
@@ -44,8 +64,8 @@ public function testConstruct()
44
64
$ this ->customerViewHelper ->expects ($ this ->once ())
45
65
->method ('getCustomerName ' )
46
66
->with ($ dummyCustomer )
47
- ->will ($ this ->returnValue (new \ Magento \ Framework \ DataObject ()));
48
- $ this ->request = $ this ->getMockForAbstractClass (\ Magento \ Framework \ App \ RequestInterface::class);
67
+ ->will ($ this ->returnValue (new DataObject ()));
68
+ $ this ->request = $ this ->getMockForAbstractClass (RequestInterface::class);
49
69
$ this ->request ->expects ($ this ->at (0 ))
50
70
->method ('getParam ' )
51
71
->with ('customerId ' , false )
@@ -54,14 +74,21 @@ public function testConstruct()
54
74
->method ('getParam ' )
55
75
->with ('productId ' , false )
56
76
->will ($ this ->returnValue (false ));
77
+ $ productCollection = $ this ->getMockBuilder (Collection::class)
78
+ ->disableOriginalConstructor ()
79
+ ->getMock ();
80
+ $ this ->collectionFactory ->expects ($ this ->once ())
81
+ ->method ('create ' )
82
+ ->will ($ this ->returnValue ($ productCollection ));
57
83
58
84
$ objectManagerHelper = new ObjectManagerHelper ($ this );
59
85
$ this ->model = $ objectManagerHelper ->getObject (
60
- \ Magento \ Review \ Block \ Adminhtml \Main ::class,
86
+ MainBlock ::class,
61
87
[
62
88
'request ' => $ this ->request ,
63
89
'customerRepository ' => $ this ->customerRepository ,
64
- 'customerViewHelper ' => $ this ->customerViewHelper
90
+ 'customerViewHelper ' => $ this ->customerViewHelper ,
91
+ 'productCollectionFactory ' => $ this ->collectionFactory
65
92
]
66
93
);
67
94
}
0 commit comments