8
8
9
9
use \Magento \Setup \Controller \Session ;
10
10
11
- /**
12
- * Unit test for \Magento\Setup\Controller\Session.
13
- */
14
11
class SessionTest extends \PHPUnit \Framework \TestCase
15
12
{
16
13
/**
@@ -19,18 +16,15 @@ class SessionTest extends \PHPUnit\Framework\TestCase
19
16
private $ objectManager ;
20
17
21
18
/**
22
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\ObjectManagerProvider
19
+ * @var \PHPUnit_Framework_MockObject_MockObject| \Magento\Setup\Model\ObjectManagerProvider
23
20
*/
24
21
private $ objectManagerProvider ;
25
22
26
23
/**
27
- * @var \PHPUnit_Framework_MockObject_MockObject|\ Zend\ServiceManager\ServiceManager
24
+ * @var \Zend\ServiceManager\ServiceManager
28
25
*/
29
26
private $ serviceManager ;
30
27
31
- /**
32
- * @inheritdoc
33
- */
34
28
public function setUp ()
35
29
{
36
30
$ objectManager =
@@ -47,40 +41,37 @@ public function setUp()
47
41
*/
48
42
public function testUnloginAction ()
49
43
{
50
- $ this ->objectManagerProvider ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->objectManager );
51
- $ deployConfigMock = $ this ->createPartialMock (\Magento \Framework \App \DeploymentConfig::class, ['isAvailable ' ]);
52
- $ deployConfigMock ->expects ($ this ->once ())->method ('isAvailable ' )->willReturn (true );
53
-
54
- $ sessionMock = $ this ->createPartialMock (
55
- \Magento \Backend \Model \Auth \Session::class,
56
- ['prolong ' , 'isSessionExists ' ]
44
+ $ this ->objectManagerProvider ->expects ($ this ->once ())->method ('get ' )->will (
45
+ $ this ->returnValue ($ this ->objectManager )
57
46
);
58
- $ sessionMock ->expects ($ this ->once ())->method ('isSessionExists ' )->willReturn (false );
47
+ $ deployConfigMock =
48
+ $ this ->createPartialMock (\Magento \Framework \App \DeploymentConfig::class, ['isAvailable ' ]);
49
+ $ deployConfigMock ->expects ($ this ->once ())->method ('isAvailable ' )->will ($ this ->returnValue (true ));
59
50
60
51
$ stateMock = $ this ->createPartialMock (\Magento \Framework \App \State::class, ['setAreaCode ' ]);
61
52
$ stateMock ->expects ($ this ->once ())->method ('setAreaCode ' );
62
53
63
- $ sessionConfigMock = $ this ->createPartialMock (
64
- \Magento \Backend \Model \Session \AdminConfig::class,
65
- ['setCookiePath ' ]
66
- );
54
+ $ sessionConfigMock =
55
+ $ this ->createPartialMock (\Magento \Backend \Model \Session \AdminConfig::class, ['setCookiePath ' ]);
67
56
$ sessionConfigMock ->expects ($ this ->once ())->method ('setCookiePath ' );
68
57
$ urlMock = $ this ->createMock (\Magento \Backend \Model \Url::class);
69
58
70
59
$ returnValueMap = [
71
- [\Magento \Backend \Model \Auth \Session::class, $ sessionMock ],
72
60
[\Magento \Framework \App \State::class, $ stateMock ],
73
61
[\Magento \Backend \Model \Session \AdminConfig::class, $ sessionConfigMock ],
74
- [\Magento \Backend \Model \Url::class, $ urlMock ],
62
+ [\Magento \Backend \Model \Url::class, $ urlMock ]
75
63
];
76
64
77
- $ this ->serviceManager ->expects ($ this ->once ())->method ('get ' )->willReturn ( $ deployConfigMock );
65
+ $ this ->serviceManager ->expects ($ this ->once ())->method ('get ' )->will ( $ this -> returnValue ( $ deployConfigMock) );
78
66
79
67
$ this ->objectManager ->expects ($ this ->atLeastOnce ())
80
68
->method ('get ' )
81
- ->willReturnMap ( $ returnValueMap );
69
+ ->will ( $ this -> returnValueMap ( $ returnValueMap ) );
82
70
83
- $ this ->objectManager ->expects ($ this ->once ())->method ('create ' )->willReturn ($ sessionMock );
71
+ $ sessionMock = $ this ->createPartialMock (\Magento \Backend \Model \Auth \Session::class, ['prolong ' ]);
72
+ $ this ->objectManager ->expects ($ this ->once ())
73
+ ->method ('create ' )
74
+ ->will ($ this ->returnValue ($ sessionMock ));
84
75
$ controller = new Session ($ this ->serviceManager , $ this ->objectManagerProvider );
85
76
$ urlMock ->expects ($ this ->once ())->method ('getBaseUrl ' );
86
77
$ controller ->prolongAction ();
@@ -96,25 +87,4 @@ public function testIndexAction()
96
87
$ viewModel = $ controller ->unloginAction ();
97
88
$ this ->assertInstanceOf (\Zend \View \Model \ViewModel::class, $ viewModel );
98
89
}
99
-
100
- /**
101
- * @covers \Magento\Setup\Controller\SystemConfig::prolongAction
102
- */
103
- public function testProlongActionWithExistingSession ()
104
- {
105
- $ this ->objectManagerProvider ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->objectManager );
106
- $ deployConfigMock = $ this ->createPartialMock (\Magento \Framework \App \DeploymentConfig::class, ['isAvailable ' ]);
107
- $ deployConfigMock ->expects ($ this ->once ())->method ('isAvailable ' )->willReturn (true );
108
- $ sessionMock = $ this ->createPartialMock (
109
- \Magento \Backend \Model \Auth \Session::class,
110
- ['prolong ' , 'isSessionExists ' ]
111
- );
112
- $ sessionMock ->expects ($ this ->once ())->method ('isSessionExists ' )->willReturn (true );
113
-
114
- $ this ->serviceManager ->expects ($ this ->once ())->method ('get ' )->willReturn ($ deployConfigMock );
115
- $ this ->objectManager ->expects ($ this ->once ())->method ('get ' )->willReturn ($ sessionMock );
116
-
117
- $ controller = new Session ($ this ->serviceManager , $ this ->objectManagerProvider );
118
- $ this ->assertEquals (new \Zend \View \Model \JsonModel (['success ' => true ]), $ controller ->prolongAction ());
119
- }
120
90
}
0 commit comments