66
77namespace Magento \Contact \Test \Unit \Controller \Index ;
88
9+ use Magento \Framework \Controller \ResultFactory ;
10+ use Magento \Framework \Controller \ResultInterface ;
11+
912class IndexTest extends \PHPUnit_Framework_TestCase
1013{
1114 /**
@@ -25,7 +28,7 @@ class IndexTest extends \PHPUnit_Framework_TestCase
2528 * View mock
2629 * @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject
2730 */
28- protected $ _view ;
31+ protected $ resultFactory ;
2932
3033 /**
3134 * Url mock
@@ -43,7 +46,7 @@ protected function setUp()
4346 );
4447 $ context = $ this ->getMock (
4548 \Magento \Framework \App \Action \Context::class,
46- ['getRequest ' , 'getResponse ' , 'getView ' , 'getUrl ' ],
49+ ['getRequest ' , 'getResponse ' , 'getResultFactory ' , 'getUrl ' ],
4750 [],
4851 '' ,
4952 false
@@ -67,17 +70,17 @@ protected function setUp()
6770 $ this ->getMockForAbstractClass (\Magento \Framework \App \ResponseInterface::class, [], '' , false )
6871 ));
6972
70- $ this ->_view = $ this ->getMock (
71- \ Magento \ Framework \ App \ViewInterface ::class,
73+ $ this ->resultFactory = $ this ->getMock (
74+ ResultFactory ::class,
7275 [],
7376 [],
7477 '' ,
7578 false
7679 );
7780
7881 $ context ->expects ($ this ->once ())
79- ->method ('getView ' )
80- ->will ($ this ->returnValue ($ this ->_view ));
82+ ->method ('getResultFactory ' )
83+ ->will ($ this ->returnValue ($ this ->resultFactory ));
8184
8285 $ this ->_controller = new \Magento \Contact \Controller \Index \Index (
8386 $ context ,
@@ -90,12 +93,12 @@ protected function setUp()
9093
9194 public function testExecute ()
9295 {
93- $ this -> _view -> expects ( $ this ->once ())
94- -> method ( ' loadLayout ' );
95-
96- $ this -> _view -> expects ( $ this -> once () )
97- ->method ( ' renderLayout ' );
96+ $ resultStub = $ this ->getMockForAbstractClass (ResultInterface::class);
97+ $ this -> resultFactory -> expects ( $ this -> once ())
98+ -> method ( ' create ' )
99+ -> with (ResultFactory:: TYPE_PAGE )
100+ ->willReturn ( $ resultStub );
98101
99- $ this ->_controller ->execute ();
102+ $ this ->assertSame ( $ resultStub , $ this -> _controller ->execute () );
100103 }
101104}
0 commit comments