1
- <?php
1
+ <?php declare (strict_types= 1 );
2
2
/**
3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
7
namespace Magento \Authorization \Test \Unit \Model ;
8
8
9
- use \Magento \Authorization \Model \CompositeUserContext ;
10
-
9
+ use Magento \Authorization \Model \CompositeUserContext ;
11
10
use Magento \Framework \ObjectManager \Helper \Composite as CompositeHelper ;
12
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
12
14
- class CompositeUserContextTest extends \PHPUnit \Framework \TestCase
13
+ use PHPUnit \Framework \MockObject \MockObject ;
14
+ use PHPUnit \Framework \TestCase ;
15
+
16
+ class CompositeUserContextTest extends TestCase
15
17
{
16
18
/**
17
19
* @var CompositeUserContext
@@ -28,19 +30,18 @@ class CompositeUserContextTest extends \PHPUnit\Framework\TestCase
28
30
*/
29
31
protected $ objectManager ;
30
32
31
- protected function setUp ()
33
+ protected function setUp (): void
32
34
{
33
35
$ this ->objectManager = new ObjectManager ($ this );
34
36
$ this ->compositeHelperMock = $ this ->getMockBuilder (\Magento \Framework \ObjectManager \Helper \Composite::class)
35
37
->disableOriginalConstructor ()
36
38
->setMethods (['filterAndSortDeclaredComponents ' ])
37
39
->getMock ();
38
40
$ this ->compositeHelperMock
39
- ->expects ($ this ->any ())
40
41
->method ('filterAndSortDeclaredComponents ' )
41
42
->will ($ this ->returnArgument (0 ));
42
43
$ this ->userContext = $ this ->objectManager ->getObject (
43
- \ Magento \ Authorization \ Model \ CompositeUserContext::class,
44
+ CompositeUserContext::class,
44
45
['compositeHelper ' => $ this ->compositeHelperMock ]
45
46
);
46
47
}
@@ -55,7 +56,7 @@ public function testConstructor()
55
56
],
56
57
];
57
58
$ model = $ this ->objectManager ->getObject (
58
- \ Magento \ Authorization \ Model \ CompositeUserContext::class,
59
+ CompositeUserContext::class,
59
60
['compositeHelper ' => $ this ->compositeHelperMock , 'userContexts ' => $ contexts ]
60
61
);
61
62
$ this ->verifyUserContextIsAdded ($ model , $ userContextMock );
@@ -65,18 +66,18 @@ public function testGetUserId()
65
66
{
66
67
$ expectedUserId = 1 ;
67
68
$ expectedUserType = 'Customer ' ;
68
- $ userContextMock = $ this ->getMockBuilder (\ Magento \ Authorization \ Model \ CompositeUserContext::class)
69
+ $ userContextMock = $ this ->getMockBuilder (CompositeUserContext::class)
69
70
->disableOriginalConstructor ()->setMethods (['getUserId ' , 'getUserType ' ])->getMock ();
70
- $ userContextMock ->expects ( $ this -> any ())-> method ('getUserId ' )->will ($ this ->returnValue ($ expectedUserId ));
71
- $ userContextMock ->expects ( $ this -> any ())-> method ('getUserType ' )->will ($ this ->returnValue ($ expectedUserType ));
71
+ $ userContextMock ->method ('getUserId ' )->will ($ this ->returnValue ($ expectedUserId ));
72
+ $ userContextMock ->method ('getUserType ' )->will ($ this ->returnValue ($ expectedUserType ));
72
73
$ contexts = [
73
74
[
74
75
'sortOrder ' => 10 ,
75
76
'type ' => $ userContextMock ,
76
77
],
77
78
];
78
79
$ this ->userContext = $ this ->objectManager ->getObject (
79
- \ Magento \ Authorization \ Model \ CompositeUserContext::class,
80
+ CompositeUserContext::class,
80
81
['compositeHelper ' => $ this ->compositeHelperMock , 'userContexts ' => $ contexts ]
81
82
);
82
83
$ actualUserId = $ this ->userContext ->getUserId ();
@@ -87,18 +88,18 @@ public function testGetUserType()
87
88
{
88
89
$ expectedUserId = 1 ;
89
90
$ expectedUserType = 'Customer ' ;
90
- $ userContextMock = $ this ->getMockBuilder (\ Magento \ Authorization \ Model \ CompositeUserContext::class)
91
+ $ userContextMock = $ this ->getMockBuilder (CompositeUserContext::class)
91
92
->disableOriginalConstructor ()->setMethods (['getUserId ' , 'getUserType ' ])->getMock ();
92
- $ userContextMock ->expects ( $ this -> any ())-> method ('getUserId ' )->will ($ this ->returnValue ($ expectedUserId ));
93
- $ userContextMock ->expects ( $ this -> any ())-> method ('getUserType ' )->will ($ this ->returnValue ($ expectedUserType ));
93
+ $ userContextMock ->method ('getUserId ' )->will ($ this ->returnValue ($ expectedUserId ));
94
+ $ userContextMock ->method ('getUserType ' )->will ($ this ->returnValue ($ expectedUserType ));
94
95
$ contexts = [
95
96
[
96
97
'sortOrder ' => 10 ,
97
98
'type ' => $ userContextMock ,
98
99
],
99
100
];
100
101
$ this ->userContext = $ this ->objectManager ->getObject (
101
- \ Magento \ Authorization \ Model \ CompositeUserContext::class,
102
+ CompositeUserContext::class,
102
103
['compositeHelper ' => $ this ->compositeHelperMock , 'userContexts ' => $ contexts ]
103
104
);
104
105
$ actualUserType = $ this ->userContext ->getUserType ();
@@ -109,7 +110,7 @@ public function testUserContextCaching()
109
110
{
110
111
$ expectedUserId = 1 ;
111
112
$ expectedUserType = 'Customer ' ;
112
- $ userContextMock = $ this ->getMockBuilder (\ Magento \ Authorization \ Model \ CompositeUserContext::class)
113
+ $ userContextMock = $ this ->getMockBuilder (CompositeUserContext::class)
113
114
->disableOriginalConstructor ()->setMethods (['getUserId ' , 'getUserType ' ])->getMock ();
114
115
$ userContextMock ->expects ($ this ->exactly (3 ))->method ('getUserType ' )
115
116
->will ($ this ->returnValue ($ expectedUserType ));
@@ -122,7 +123,7 @@ public function testUserContextCaching()
122
123
],
123
124
];
124
125
$ this ->userContext = $ this ->objectManager ->getObject (
125
- \ Magento \ Authorization \ Model \ CompositeUserContext::class,
126
+ CompositeUserContext::class,
126
127
['compositeHelper ' => $ this ->compositeHelperMock , 'userContexts ' => $ contexts ]
127
128
);
128
129
$ this ->userContext ->getUserId ();
@@ -134,9 +135,9 @@ public function testUserContextCaching()
134
135
public function testEmptyUserContext ()
135
136
{
136
137
$ expectedUserId = null ;
137
- $ userContextMock = $ this ->getMockBuilder (\ Magento \ Authorization \ Model \ CompositeUserContext::class)
138
+ $ userContextMock = $ this ->getMockBuilder (CompositeUserContext::class)
138
139
->disableOriginalConstructor ()->setMethods (['getUserId ' ])->getMock ();
139
- $ userContextMock ->expects ( $ this -> any ())-> method ('getUserId ' )
140
+ $ userContextMock ->method ('getUserId ' )
140
141
->will ($ this ->returnValue ($ expectedUserId ));
141
142
$ contexts = [
142
143
[
@@ -145,7 +146,7 @@ public function testEmptyUserContext()
145
146
],
146
147
];
147
148
$ this ->userContext = $ this ->objectManager ->getObject (
148
- \ Magento \ Authorization \ Model \ CompositeUserContext::class,
149
+ CompositeUserContext::class,
149
150
['compositeHelper ' => $ this ->compositeHelperMock , 'userContexts ' => $ contexts ]
150
151
);
151
152
$ actualUserId = $ this ->userContext ->getUserId ();
@@ -155,15 +156,15 @@ public function testEmptyUserContext()
155
156
/**
156
157
* @param int|null $userId
157
158
* @param string|null $userType
158
- * @return \PHPUnit_Framework_MockObject_MockObject
159
+ * @return MockObject
159
160
*/
160
161
protected function createUserContextMock ($ userId = null , $ userType = null )
161
162
{
162
- $ useContextMock = $ this ->getMockBuilder (\ Magento \ Authorization \ Model \ CompositeUserContext::class)
163
+ $ useContextMock = $ this ->getMockBuilder (CompositeUserContext::class)
163
164
->disableOriginalConstructor ()->setMethods (['getUserId ' , 'getUserType ' ])->getMock ();
164
165
if ($ userId !== null && $ userType !== null ) {
165
- $ useContextMock ->expects ( $ this -> any ())-> method ('getUserId ' )->will ($ this ->returnValue ($ userId ));
166
- $ useContextMock ->expects ( $ this -> any ())-> method ('getUserType ' )->will ($ this ->returnValue ($ userType ));
166
+ $ useContextMock ->method ('getUserId ' )->will ($ this ->returnValue ($ userId ));
167
+ $ useContextMock ->method ('getUserType ' )->will ($ this ->returnValue ($ userType ));
167
168
}
168
169
return $ useContextMock ;
169
170
}
@@ -175,7 +176,7 @@ protected function createUserContextMock($userId = null, $userType = null)
175
176
protected function verifyUserContextIsAdded ($ model , $ userContextMock )
176
177
{
177
178
$ userContext = new \ReflectionProperty (
178
- \ Magento \ Authorization \ Model \ CompositeUserContext::class,
179
+ CompositeUserContext::class,
179
180
'userContexts '
180
181
);
181
182
$ userContext ->setAccessible (true );
0 commit comments