66
77namespace Magento \ConfigurableProduct \Test \Unit \Controller \Adminhtml \Product ;
88
9+ use Magento \Framework \Controller \ResultFactory ;
910use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
1011
1112class AddAttributeTest extends \PHPUnit_Framework_TestCase
1213{
14+ /** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
15+ private $ resultFactory ;
16+
1317 /** @var \Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute */
1418 protected $ controller ;
1519
@@ -45,35 +49,39 @@ protected function setUp()
4549 {
4650 $ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
4751
48- $ this ->context = $ this ->getMockBuilder (' \Magento\Backend\App\Action\Context ' )
52+ $ this ->context = $ this ->getMockBuilder (\Magento \Backend \App \Action \Context::class )
4953 ->disableOriginalConstructor ()
5054 ->getMock ();
51- $ this ->request = $ this ->getMock ('Magento\Framework\App\RequestInterface ' );
55+ $ this ->request = $ this ->getMock (\Magento \Framework \App \RequestInterface::class);
56+ $ this ->resultFactory = $ this ->getMock (\Magento \Framework \Controller \ResultFactory::class, [], [], '' , false );
5257 $ this ->response = $ this ->getMock (
53- ' \Magento\Framework\App\ResponseInterface ' ,
58+ \Magento \Framework \App \ResponseInterface::class ,
5459 [
5560 'sendResponse ' ,
5661 'setBody '
5762 ]
5863 );
59- $ this ->productBuilder = $ this ->getMockBuilder (' \Magento\Catalog\Controller\Adminhtml\Product\Builder ' )
64+ $ this ->productBuilder = $ this ->getMockBuilder (\Magento \Catalog \Controller \Adminhtml \Product \Builder::class )
6065 ->disableOriginalConstructor ()
6166 ->setMethods (['build ' ])
6267 ->getMock ();
63- $ this ->view = $ this ->getMock (' \Magento\Framework\App\ViewInterface ' );
68+ $ this ->view = $ this ->getMock (\Magento \Framework \App \ViewInterface::class );
6469
6570 $ this ->context ->expects ($ this ->any ())
6671 ->method ('getRequest ' )
6772 ->will ($ this ->returnValue ($ this ->request ));
6873 $ this ->context ->expects ($ this ->any ())
6974 ->method ('getResponse ' )
7075 ->will ($ this ->returnValue ($ this ->response ));
76+ $ this ->context ->expects ($ this ->any ())
77+ ->method ('getResultFactory ' )
78+ ->will ($ this ->returnValue ($ this ->resultFactory ));
7179 $ this ->context ->expects ($ this ->any ())
7280 ->method ('getView ' )
7381 ->will ($ this ->returnValue ($ this ->view ));
7482
7583 $ this ->controller = $ this ->objectManagerHelper ->getObject (
76- ' \Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute ' ,
84+ \Magento \ConfigurableProduct \Controller \Adminhtml \Product \AddAttribute::class ,
7785 [
7886 'context ' => $ this ->context ,
7987 'productBuilder ' => $ this ->productBuilder
@@ -83,22 +91,16 @@ protected function setUp()
8391
8492 public function testExecute ()
8593 {
86- $ product = $ this ->getMockBuilder (' \Magento\Catalog\Model\Product ' )
94+ $ product = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class )
8795 ->disableOriginalConstructor ()
8896 ->setMethods (['_wakeup ' , 'getId ' ])
8997 ->getMock ();
90- $ layout = $ this ->getMock ('\Magento\Framework\View\LayoutInterface ' );
91- $ block = $ this ->getMockBuilder (
92- 'Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created '
93- )
94- ->disableOriginalConstructor ()
95- ->setMethods (['setIndex ' , 'toHtml ' ])
96- ->getMock ();
9798
9899 $ this ->productBuilder ->expects ($ this ->once ())->method ('build ' )->with ($ this ->request )->willReturn ($ product );
99- $ this ->view ->expects ($ this ->once ())->method ('getLayout ' )->willReturn ($ layout );
100- $ layout ->expects ($ this ->once ())->method ('createBlock ' )->willReturn ($ block );
100+ $ resultLayout = $ this ->getMock (\Magento \Framework \View \Result \Layout::class, [], [], '' , false );
101+ $ this ->resultFactory ->expects ($ this ->once ())->method ('create ' )->with (ResultFactory::TYPE_LAYOUT )
102+ ->willReturn ($ resultLayout );
101103
102- $ this ->controller ->execute ();
104+ $ this ->assertInstanceOf (\ Magento \ Framework \ View \ Result \Layout::class, $ this -> controller ->execute () );
103105 }
104106}
0 commit comments