28
28
* @author suncat2000 <nikolay.kotovsky@gmail.com>
29
29
*
30
30
* @internal
31
+ *
31
32
* @coversDefaultClass
32
33
*/
33
34
final class DeviceDataCollectorTest extends TestCase
@@ -55,11 +56,11 @@ protected function setUp(): void
55
56
$ this ->request ->query = new ParameterBag ();
56
57
$ this ->request ->cookies = new ParameterBag ();
57
58
$ this ->request ->server = new ServerBag ();
58
- $ this ->request ->expects (static ::any ())->method ('duplicate ' )->willReturn ($ this ->request );
59
+ $ this ->request ->expects (self ::any ())->method ('duplicate ' )->willReturn ($ this ->request );
59
60
60
61
$ this ->requestStack = $ this ->getMockBuilder (RequestStack::class)->disableOriginalConstructor ()->getMock ();
61
- $ this ->requestStack ->expects (static ::any ())
62
- ->method (method_exists (RequestStack::class, 'getMainRequest ' ) ? ' getMainRequest ' : ' getMasterRequest ' )
62
+ $ this ->requestStack ->expects (self ::any ())
63
+ ->method ('getMainRequest ' )
63
64
->willReturn ($ this ->request )
64
65
;
65
66
@@ -83,19 +84,19 @@ public function testCollectCurrentViewMobileIsCurrent(): void
83
84
$ currentView = $ deviceDataCollector ->getCurrentView ();
84
85
$ views = $ deviceDataCollector ->getViews ();
85
86
86
- static ::assertSame ($ deviceView ->getViewType (), $ currentView );
87
- static ::assertSame (DeviceView::VIEW_MOBILE , $ currentView );
88
- static ::assertCount (3 , $ views );
87
+ self ::assertSame ($ deviceView ->getViewType (), $ currentView );
88
+ self ::assertSame (DeviceView::VIEW_MOBILE , $ currentView );
89
+ self ::assertCount (3 , $ views );
89
90
90
91
foreach ($ views as $ view ) {
91
- static ::assertIsArray ($ view );
92
- static ::assertArrayHasKey ('type ' , $ view );
93
- static ::assertArrayHasKey ('label ' , $ view );
94
- static ::assertArrayHasKey ('link ' , $ view );
95
- static ::assertArrayHasKey ('isCurrent ' , $ view );
96
- static ::assertArrayHasKey ('enabled ' , $ view );
92
+ self ::assertIsArray ($ view );
93
+ self ::assertArrayHasKey ('type ' , $ view );
94
+ self ::assertArrayHasKey ('label ' , $ view );
95
+ self ::assertArrayHasKey ('link ' , $ view );
96
+ self ::assertArrayHasKey ('isCurrent ' , $ view );
97
+ self ::assertArrayHasKey ('enabled ' , $ view );
97
98
if (DeviceView::VIEW_MOBILE === $ view ['type ' ]) {
98
- static ::assertTrue ($ view ['isCurrent ' ]);
99
+ self ::assertTrue ($ view ['isCurrent ' ]);
99
100
}
100
101
}
101
102
}
@@ -109,16 +110,16 @@ public function testCollectCurrentViewMobileCanUseTablet(): void
109
110
'action ' => RequestResponseListener::REDIRECT ,
110
111
];
111
112
$ this ->request ->query = new ParameterBag (['param1 ' => 'value1 ' ]);
112
- $ this ->request ->expects (static ::any ())->method ('getSchemeAndHttpHost ' )->willReturn ('http://t.testsite.com ' );
113
- $ this ->request ->expects (static ::any ())->method ('getBaseUrl ' )->willReturn ('/base-url ' );
114
- $ this ->request ->expects (static ::any ())->method ('getPathInfo ' )->willReturn ('/path-info ' );
113
+ $ this ->request ->expects (self ::any ())->method ('getSchemeAndHttpHost ' )->willReturn ('http://t.testsite.com ' );
114
+ $ this ->request ->expects (self ::any ())->method ('getBaseUrl ' )->willReturn ('/base-url ' );
115
+ $ this ->request ->expects (self ::any ())->method ('getPathInfo ' )->willReturn ('/path-info ' );
115
116
$ test = $ this ;
116
- $ this ->request ->expects (static ::any ())->method ('getQueryString ' )->willReturnCallback (function () use ($ test ) {
117
+ $ this ->request ->expects (self ::any ())->method ('getQueryString ' )->willReturnCallback (function () use ($ test ) {
117
118
$ qs = Request::normalizeQueryString ($ test ->request ->server ->get ('QUERY_STRING ' ));
118
119
119
120
return '' === $ qs ? null : $ qs ;
120
121
});
121
- $ this ->request ->expects (static ::any ())->method ('getUri ' )->willReturnCallback (function () use ($ test ) {
122
+ $ this ->request ->expects (self ::any ())->method ('getUri ' )->willReturnCallback (function () use ($ test ) {
122
123
if (null !== $ qs = $ test ->request ->getQueryString ()) {
123
124
$ qs = '? ' .$ qs ;
124
125
}
@@ -134,24 +135,24 @@ public function testCollectCurrentViewMobileCanUseTablet(): void
134
135
$ currentView = $ deviceDataCollector ->getCurrentView ();
135
136
$ views = $ deviceDataCollector ->getViews ();
136
137
137
- static ::assertSame ($ deviceView ->getViewType (), $ currentView );
138
- static ::assertSame (DeviceView::VIEW_MOBILE , $ currentView );
139
- static ::assertCount (3 , $ views );
138
+ self ::assertSame ($ deviceView ->getViewType (), $ currentView );
139
+ self ::assertSame (DeviceView::VIEW_MOBILE , $ currentView );
140
+ self ::assertCount (3 , $ views );
140
141
141
142
foreach ($ views as $ view ) {
142
- static ::assertIsArray ($ view );
143
- static ::assertArrayHasKey ('type ' , $ view );
144
- static ::assertArrayHasKey ('label ' , $ view );
145
- static ::assertArrayHasKey ('link ' , $ view );
146
- static ::assertArrayHasKey ('isCurrent ' , $ view );
147
- static ::assertArrayHasKey ('enabled ' , $ view );
143
+ self ::assertIsArray ($ view );
144
+ self ::assertArrayHasKey ('type ' , $ view );
145
+ self ::assertArrayHasKey ('label ' , $ view );
146
+ self ::assertArrayHasKey ('link ' , $ view );
147
+ self ::assertArrayHasKey ('isCurrent ' , $ view );
148
+ self ::assertArrayHasKey ('enabled ' , $ view );
148
149
if (DeviceView::VIEW_MOBILE === $ view ['type ' ]) {
149
- static ::assertTrue ($ view ['isCurrent ' ]);
150
+ self ::assertTrue ($ view ['isCurrent ' ]);
150
151
}
151
152
if (DeviceView::VIEW_TABLET === $ view ['type ' ]) {
152
- static ::assertFalse ($ view ['isCurrent ' ]);
153
- static ::assertTrue ($ view ['enabled ' ]);
154
- static ::assertSame (
153
+ self ::assertFalse ($ view ['isCurrent ' ]);
154
+ self ::assertTrue ($ view ['enabled ' ]);
155
+ self ::assertSame (
155
156
sprintf (
156
157
'http://t.testsite.com/base-url/path-info?%s=%s¶m1=value1 ' ,
157
158
$ deviceView ->getSwitchParam (),
@@ -172,16 +173,16 @@ public function testCollectCurrentViewFullCanUseMobile(): void
172
173
'action ' => RequestResponseListener::REDIRECT ,
173
174
];
174
175
$ this ->request ->query = new ParameterBag (['param1 ' => 'value1 ' ]);
175
- $ this ->request ->expects (static ::any ())->method ('getSchemeAndHttpHost ' )->willReturn ('http://t.testsite.com ' );
176
- $ this ->request ->expects (static ::any ())->method ('getBaseUrl ' )->willReturn ('/base-url ' );
177
- $ this ->request ->expects (static ::any ())->method ('getPathInfo ' )->willReturn ('/path-info ' );
176
+ $ this ->request ->expects (self ::any ())->method ('getSchemeAndHttpHost ' )->willReturn ('http://t.testsite.com ' );
177
+ $ this ->request ->expects (self ::any ())->method ('getBaseUrl ' )->willReturn ('/base-url ' );
178
+ $ this ->request ->expects (self ::any ())->method ('getPathInfo ' )->willReturn ('/path-info ' );
178
179
$ test = $ this ;
179
- $ this ->request ->expects (static ::any ())->method ('getQueryString ' )->willReturnCallback (function () use ($ test ) {
180
+ $ this ->request ->expects (self ::any ())->method ('getQueryString ' )->willReturnCallback (function () use ($ test ) {
180
181
$ qs = Request::normalizeQueryString ($ test ->request ->server ->get ('QUERY_STRING ' ));
181
182
182
183
return '' === $ qs ? null : $ qs ;
183
184
});
184
- $ this ->request ->expects (static ::any ())->method ('getUri ' )->willReturnCallback (function () use ($ test ) {
185
+ $ this ->request ->expects (self ::any ())->method ('getUri ' )->willReturnCallback (function () use ($ test ) {
185
186
if (null !== $ qs = $ test ->request ->getQueryString ()) {
186
187
$ qs = '? ' .$ qs ;
187
188
}
@@ -197,24 +198,24 @@ public function testCollectCurrentViewFullCanUseMobile(): void
197
198
$ currentView = $ deviceDataCollector ->getCurrentView ();
198
199
$ views = $ deviceDataCollector ->getViews ();
199
200
200
- static ::assertSame ($ deviceView ->getViewType (), $ currentView );
201
- static ::assertSame (DeviceView::VIEW_FULL , $ currentView );
202
- static ::assertCount (3 , $ views );
201
+ self ::assertSame ($ deviceView ->getViewType (), $ currentView );
202
+ self ::assertSame (DeviceView::VIEW_FULL , $ currentView );
203
+ self ::assertCount (3 , $ views );
203
204
204
205
foreach ($ views as $ view ) {
205
- static ::assertIsArray ($ view );
206
- static ::assertArrayHasKey ('type ' , $ view );
207
- static ::assertArrayHasKey ('label ' , $ view );
208
- static ::assertArrayHasKey ('link ' , $ view );
209
- static ::assertArrayHasKey ('isCurrent ' , $ view );
210
- static ::assertArrayHasKey ('enabled ' , $ view );
206
+ self ::assertIsArray ($ view );
207
+ self ::assertArrayHasKey ('type ' , $ view );
208
+ self ::assertArrayHasKey ('label ' , $ view );
209
+ self ::assertArrayHasKey ('link ' , $ view );
210
+ self ::assertArrayHasKey ('isCurrent ' , $ view );
211
+ self ::assertArrayHasKey ('enabled ' , $ view );
211
212
if (DeviceView::VIEW_FULL === $ view ['type ' ]) {
212
- static ::assertTrue ($ view ['isCurrent ' ]);
213
+ self ::assertTrue ($ view ['isCurrent ' ]);
213
214
}
214
215
if (DeviceView::VIEW_MOBILE === $ view ['type ' ]) {
215
- static ::assertFalse ($ view ['isCurrent ' ]);
216
- static ::assertTrue ($ view ['enabled ' ]);
217
- static ::assertSame (
216
+ self ::assertFalse ($ view ['isCurrent ' ]);
217
+ self ::assertTrue ($ view ['enabled ' ]);
218
+ self ::assertSame (
218
219
sprintf (
219
220
'http://t.testsite.com/base-url/path-info?%s=%s¶m1=value1 ' ,
220
221
$ deviceView ->getSwitchParam (),
@@ -235,16 +236,16 @@ public function testCollectCurrentViewFullCantUseMobile(): void
235
236
'action ' => RequestResponseListener::REDIRECT ,
236
237
];
237
238
$ this ->request ->query = new ParameterBag (['param1 ' => 'value1 ' ]);
238
- $ this ->request ->expects (static ::any ())->method ('getSchemeAndHttpHost ' )->willReturn ('http://testsite.com ' );
239
- $ this ->request ->expects (static ::any ())->method ('getBaseUrl ' )->willReturn ('/base-url ' );
240
- $ this ->request ->expects (static ::any ())->method ('getPathInfo ' )->willReturn ('/path-info ' );
239
+ $ this ->request ->expects (self ::any ())->method ('getSchemeAndHttpHost ' )->willReturn ('http://testsite.com ' );
240
+ $ this ->request ->expects (self ::any ())->method ('getBaseUrl ' )->willReturn ('/base-url ' );
241
+ $ this ->request ->expects (self ::any ())->method ('getPathInfo ' )->willReturn ('/path-info ' );
241
242
$ test = $ this ;
242
- $ this ->request ->expects (static ::any ())->method ('getQueryString ' )->willReturnCallback (function () use ($ test ) {
243
+ $ this ->request ->expects (self ::any ())->method ('getQueryString ' )->willReturnCallback (function () use ($ test ) {
243
244
$ qs = Request::normalizeQueryString ($ test ->request ->server ->get ('QUERY_STRING ' ));
244
245
245
246
return '' === $ qs ? null : $ qs ;
246
247
});
247
- $ this ->request ->expects (static ::any ())->method ('getUri ' )->willReturnCallback (function () use ($ test ) {
248
+ $ this ->request ->expects (self ::any ())->method ('getUri ' )->willReturnCallback (function () use ($ test ) {
248
249
if (null !== $ qs = $ test ->request ->getQueryString ()) {
249
250
$ qs = '? ' .$ qs ;
250
251
}
@@ -260,24 +261,24 @@ public function testCollectCurrentViewFullCantUseMobile(): void
260
261
$ currentView = $ deviceDataCollector ->getCurrentView ();
261
262
$ views = $ deviceDataCollector ->getViews ();
262
263
263
- static ::assertSame ($ deviceView ->getViewType (), $ currentView );
264
- static ::assertSame (DeviceView::VIEW_FULL , $ currentView );
265
- static ::assertCount (3 , $ views );
264
+ self ::assertSame ($ deviceView ->getViewType (), $ currentView );
265
+ self ::assertSame (DeviceView::VIEW_FULL , $ currentView );
266
+ self ::assertCount (3 , $ views );
266
267
267
268
foreach ($ views as $ view ) {
268
- static ::assertIsArray ($ view );
269
- static ::assertArrayHasKey ('type ' , $ view );
270
- static ::assertArrayHasKey ('label ' , $ view );
271
- static ::assertArrayHasKey ('link ' , $ view );
272
- static ::assertArrayHasKey ('isCurrent ' , $ view );
273
- static ::assertArrayHasKey ('enabled ' , $ view );
269
+ self ::assertIsArray ($ view );
270
+ self ::assertArrayHasKey ('type ' , $ view );
271
+ self ::assertArrayHasKey ('label ' , $ view );
272
+ self ::assertArrayHasKey ('link ' , $ view );
273
+ self ::assertArrayHasKey ('isCurrent ' , $ view );
274
+ self ::assertArrayHasKey ('enabled ' , $ view );
274
275
if (DeviceView::VIEW_FULL === $ view ['type ' ]) {
275
- static ::assertTrue ($ view ['isCurrent ' ]);
276
+ self ::assertTrue ($ view ['isCurrent ' ]);
276
277
}
277
278
if (DeviceView::VIEW_MOBILE === $ view ['type ' ]) {
278
- static ::assertFalse ($ view ['isCurrent ' ]);
279
- static ::assertFalse ($ view ['enabled ' ]);
280
- static ::assertSame (
279
+ self ::assertFalse ($ view ['isCurrent ' ]);
280
+ self ::assertFalse ($ view ['enabled ' ]);
281
+ self ::assertSame (
281
282
sprintf (
282
283
'http://testsite.com/base-url/path-info?%s=%s¶m1=value1 ' ,
283
284
$ deviceView ->getSwitchParam (),
@@ -294,13 +295,13 @@ public function testReset(): void
294
295
$ deviceView = new DeviceView ($ this ->requestStack );
295
296
$ deviceDataCollector = new DeviceDataCollector ($ deviceView );
296
297
$ deviceDataCollector ->reset ();
297
- static ::assertSame ([], $ deviceDataCollector ->getData ());
298
+ self ::assertSame ([], $ deviceDataCollector ->getData ());
298
299
}
299
300
300
301
public function testGetNameValue (): void
301
302
{
302
303
$ deviceView = new DeviceView ($ this ->requestStack );
303
304
$ deviceDataCollector = new DeviceDataCollector ($ deviceView );
304
- static ::assertSame ('device.collector ' , $ deviceDataCollector ->getName ());
305
+ self ::assertSame ('device.collector ' , $ deviceDataCollector ->getName ());
305
306
}
306
307
}
0 commit comments