33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
67
78namespace Magento \Review \Test \Unit \Block \Adminhtml ;
89
910use 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 ;
1019
20+ /**
21+ * Unit Test For Main Block
22+ *
23+ * Class \Magento\Review\Test\Unit\Block\Adminhtml\MainTest
24+ */
1125class MainTest extends \PHPUnit \Framework \TestCase
1226{
1327 /**
14- * @var \Magento\Review\Block\Adminhtml\Main
28+ * @var MainBlock
1529 */
1630 protected $ model ;
1731
1832 /**
19- * @var \Magento\Framework\App\ RequestInterface|\PHPUnit_Framework_MockObject_MockObject
33+ * @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
2034 */
2135 protected $ request ;
2236
2337 /**
24- * @var \Magento\Customer\Api\ CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
38+ * @var CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
2539 */
2640 protected $ customerRepository ;
2741
2842 /**
29- * @var \Magento\Customer\Helper\View |\PHPUnit_Framework_MockObject_MockObject
43+ * @var ViewHelper |\PHPUnit_Framework_MockObject_MockObject
3044 */
3145 protected $ customerViewHelper ;
3246
47+ /**
48+ * @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
49+ */
50+ protected $ collectionFactory ;
51+
3352 public function testConstruct ()
3453 {
3554 $ 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);
3959
4060 $ this ->customerRepository ->expects ($ this ->once ())
4161 ->method ('getById ' )
@@ -44,8 +64,8 @@ public function testConstruct()
4464 $ this ->customerViewHelper ->expects ($ this ->once ())
4565 ->method ('getCustomerName ' )
4666 ->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);
4969 $ this ->request ->expects ($ this ->at (0 ))
5070 ->method ('getParam ' )
5171 ->with ('customerId ' , false )
@@ -54,14 +74,21 @@ public function testConstruct()
5474 ->method ('getParam ' )
5575 ->with ('productId ' , false )
5676 ->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 ));
5783
5884 $ objectManagerHelper = new ObjectManagerHelper ($ this );
5985 $ this ->model = $ objectManagerHelper ->getObject (
60- \ Magento \ Review \ Block \ Adminhtml \Main ::class,
86+ MainBlock ::class,
6187 [
6288 'request ' => $ this ->request ,
6389 'customerRepository ' => $ this ->customerRepository ,
64- 'customerViewHelper ' => $ this ->customerViewHelper
90+ 'customerViewHelper ' => $ this ->customerViewHelper ,
91+ 'productCollectionFactory ' => $ this ->collectionFactory
6592 ]
6693 );
6794 }
0 commit comments