6
6
7
7
namespace Magento \Contact \Test \Unit \Controller \Index ;
8
8
9
+ use Magento \Framework \Controller \ResultFactory ;
10
+ use Magento \Framework \Controller \ResultInterface ;
11
+
9
12
class IndexTest extends \PHPUnit_Framework_TestCase
10
13
{
11
14
/**
@@ -25,7 +28,7 @@ class IndexTest extends \PHPUnit_Framework_TestCase
25
28
* View mock
26
29
* @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject
27
30
*/
28
- protected $ _view ;
31
+ protected $ resultFactory ;
29
32
30
33
/**
31
34
* Url mock
@@ -43,7 +46,7 @@ protected function setUp()
43
46
);
44
47
$ context = $ this ->getMock (
45
48
\Magento \Framework \App \Action \Context::class,
46
- ['getRequest ' , 'getResponse ' , 'getView ' , 'getUrl ' ],
49
+ ['getRequest ' , 'getResponse ' , 'getResultFactory ' , 'getUrl ' ],
47
50
[],
48
51
'' ,
49
52
false
@@ -67,17 +70,17 @@ protected function setUp()
67
70
$ this ->getMockForAbstractClass (\Magento \Framework \App \ResponseInterface::class, [], '' , false )
68
71
));
69
72
70
- $ this ->_view = $ this ->getMock (
71
- \ Magento \ Framework \ App \ViewInterface ::class,
73
+ $ this ->resultFactory = $ this ->getMock (
74
+ ResultFactory ::class,
72
75
[],
73
76
[],
74
77
'' ,
75
78
false
76
79
);
77
80
78
81
$ context ->expects ($ this ->once ())
79
- ->method ('getView ' )
80
- ->will ($ this ->returnValue ($ this ->_view ));
82
+ ->method ('getResultFactory ' )
83
+ ->will ($ this ->returnValue ($ this ->resultFactory ));
81
84
82
85
$ this ->_controller = new \Magento \Contact \Controller \Index \Index (
83
86
$ context ,
@@ -90,12 +93,12 @@ protected function setUp()
90
93
91
94
public function testExecute ()
92
95
{
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 );
98
101
99
- $ this ->_controller ->execute ();
102
+ $ this ->assertSame ( $ resultStub , $ this -> _controller ->execute () );
100
103
}
101
104
}
0 commit comments