15
15
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
16
16
use Symfony \Bundle \WebProfilerBundle \Controller \ProfilerController ;
17
17
use Symfony \Bundle \WebProfilerBundle \Csp \ContentSecurityPolicyHandler ;
18
+ use Symfony \Bundle \WebProfilerBundle \Csp \NonceGenerator ;
18
19
use Symfony \Bundle \WebProfilerBundle \Tests \Functional \WebProfilerBundleKernel ;
19
20
use Symfony \Component \HttpFoundation \Request ;
20
21
use Symfony \Component \HttpFoundation \Response ;
24
25
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
25
26
use Symfony \Component \HttpKernel \Profiler \Profile ;
26
27
use Symfony \Component \HttpKernel \Profiler \Profiler ;
28
+ use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
27
29
use Twig \Environment ;
28
30
use Twig \Loader \LoaderInterface ;
29
31
use Twig \Loader \SourceContextLoaderInterface ;
@@ -35,8 +37,8 @@ public function testHomeActionWithProfilerDisabled()
35
37
$ this ->expectException (NotFoundHttpException::class);
36
38
$ this ->expectExceptionMessage ('The profiler must be enabled. ' );
37
39
38
- $ urlGenerator = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ Generator \ UrlGeneratorInterface::class)-> getMock ( );
39
- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
40
+ $ urlGenerator = $ this ->createMock ( UrlGeneratorInterface::class);
41
+ $ twig = $ this ->createMock (Environment::class);
40
42
41
43
$ controller = new ProfilerController ($ urlGenerator , null , $ twig , []);
42
44
$ controller ->homeAction ();
@@ -111,8 +113,8 @@ public function testToolbarActionWithProfilerDisabled()
111
113
$ this ->expectException (NotFoundHttpException::class);
112
114
$ this ->expectExceptionMessage ('The profiler must be enabled. ' );
113
115
114
- $ urlGenerator = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ Generator \ UrlGeneratorInterface::class)-> getMock ( );
115
- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
116
+ $ urlGenerator = $ this ->createMock ( UrlGeneratorInterface::class);
117
+ $ twig = $ this ->createMock (Environment::class);
116
118
117
119
$ controller = new ProfilerController ($ urlGenerator , null , $ twig , []);
118
120
$ controller ->toolbarAction (Request::create ('/_wdt/foo-token ' ), null );
@@ -123,12 +125,9 @@ public function testToolbarActionWithProfilerDisabled()
123
125
*/
124
126
public function testToolbarActionWithEmptyToken ($ token )
125
127
{
126
- $ urlGenerator = $ this ->getMockBuilder (\Symfony \Component \Routing \Generator \UrlGeneratorInterface::class)->getMock ();
127
- $ twig = $ this ->getMockBuilder (Environment::class)->disableOriginalConstructor ()->getMock ();
128
- $ profiler = $ this
129
- ->getMockBuilder (Profiler::class)
130
- ->disableOriginalConstructor ()
131
- ->getMock ();
128
+ $ urlGenerator = $ this ->createMock (UrlGeneratorInterface::class);
129
+ $ twig = $ this ->createMock (Environment::class);
130
+ $ profiler = $ this ->createMock (Profiler::class);
132
131
133
132
$ controller = new ProfilerController ($ urlGenerator , $ profiler , $ twig , []);
134
133
@@ -150,12 +149,9 @@ public function getEmptyTokenCases()
150
149
*/
151
150
public function testOpeningDisallowedPaths ($ path , $ isAllowed )
152
151
{
153
- $ urlGenerator = $ this ->getMockBuilder (\Symfony \Component \Routing \Generator \UrlGeneratorInterface::class)->getMock ();
154
- $ twig = $ this ->getMockBuilder (Environment::class)->disableOriginalConstructor ()->getMock ();
155
- $ profiler = $ this
156
- ->getMockBuilder (Profiler::class)
157
- ->disableOriginalConstructor ()
158
- ->getMock ();
152
+ $ urlGenerator = $ this ->createMock (UrlGeneratorInterface::class);
153
+ $ twig = $ this ->createMock (Environment::class);
154
+ $ profiler = $ this ->createMock (Profiler::class);
159
155
160
156
$ controller = new ProfilerController ($ urlGenerator , $ profiler , $ twig , [], null , __DIR__ .'/../.. ' );
161
157
@@ -186,11 +182,8 @@ public function getOpenFileCases()
186
182
*/
187
183
public function testReturns404onTokenNotFound ($ withCsp )
188
184
{
189
- $ twig = $ this ->getMockBuilder (Environment::class)->disableOriginalConstructor ()->getMock ();
190
- $ profiler = $ this
191
- ->getMockBuilder (Profiler::class)
192
- ->disableOriginalConstructor ()
193
- ->getMock ();
185
+ $ twig = $ this ->createMock (Environment::class);
186
+ $ profiler = $ this ->createMock (Profiler::class);
194
187
195
188
$ profiler
196
189
->expects ($ this ->exactly (2 ))
@@ -214,8 +207,8 @@ public function testSearchBarActionWithProfilerDisabled()
214
207
$ this ->expectException (NotFoundHttpException::class);
215
208
$ this ->expectExceptionMessage ('The profiler must be enabled. ' );
216
209
217
- $ urlGenerator = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ Generator \ UrlGeneratorInterface::class)-> getMock ( );
218
- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
210
+ $ urlGenerator = $ this ->createMock ( UrlGeneratorInterface::class);
211
+ $ twig = $ this ->createMock (Environment::class);
219
212
220
213
$ controller = new ProfilerController ($ urlGenerator , null , $ twig , []);
221
214
$ controller ->searchBarAction (Request::create ('/_profiler/search_bar ' ));
@@ -240,11 +233,8 @@ public function testSearchBarActionDefaultPage()
240
233
*/
241
234
public function testSearchResultsAction ($ withCsp )
242
235
{
243
- $ twig = $ this ->getMockBuilder (Environment::class)->disableOriginalConstructor ()->getMock ();
244
- $ profiler = $ this
245
- ->getMockBuilder (Profiler::class)
246
- ->disableOriginalConstructor ()
247
- ->getMock ();
236
+ $ twig = $ this ->createMock (Environment::class);
237
+ $ profiler = $ this ->createMock (Profiler::class);
248
238
249
239
$ controller = $ this ->createController ($ profiler , $ twig , $ withCsp );
250
240
@@ -306,8 +296,8 @@ public function testSearchActionWithProfilerDisabled()
306
296
$ this ->expectException (NotFoundHttpException::class);
307
297
$ this ->expectExceptionMessage ('The profiler must be enabled. ' );
308
298
309
- $ urlGenerator = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ Generator \ UrlGeneratorInterface::class)-> getMock ( );
310
- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
299
+ $ urlGenerator = $ this ->createMock ( UrlGeneratorInterface::class);
300
+ $ twig = $ this ->createMock (Environment::class);
311
301
312
302
$ controller = new ProfilerController ($ urlGenerator , null , $ twig , []);
313
303
$ controller ->searchBarAction (Request::create ('/_profiler/search ' ));
@@ -345,8 +335,8 @@ public function testPhpinfoActionWithProfilerDisabled()
345
335
$ this ->expectException (NotFoundHttpException::class);
346
336
$ this ->expectExceptionMessage ('The profiler must be enabled. ' );
347
337
348
- $ urlGenerator = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ Generator \ UrlGeneratorInterface::class)-> getMock ( );
349
- $ twig = $ this ->getMockBuilder (Environment::class)-> disableOriginalConstructor ()-> getMock ( );
338
+ $ urlGenerator = $ this ->createMock ( UrlGeneratorInterface::class);
339
+ $ twig = $ this ->createMock (Environment::class);
350
340
351
341
$ controller = new ProfilerController ($ urlGenerator , null , $ twig , []);
352
342
$ controller ->phpinfoAction (Request::create ('/_profiler/phpinfo ' ));
@@ -464,10 +454,10 @@ public function defaultPanelProvider(): \Generator
464
454
465
455
private function createController ($ profiler , $ twig , $ withCSP , array $ templates = []): ProfilerController
466
456
{
467
- $ urlGenerator = $ this ->getMockBuilder (\ Symfony \ Component \ Routing \ Generator \ UrlGeneratorInterface::class)-> getMock ( );
457
+ $ urlGenerator = $ this ->createMock ( UrlGeneratorInterface::class);
468
458
469
459
if ($ withCSP ) {
470
- $ nonceGenerator = $ this ->getMockBuilder (\ Symfony \ Bundle \ WebProfilerBundle \ Csp \ NonceGenerator::class)-> getMock ( );
460
+ $ nonceGenerator = $ this ->createMock ( NonceGenerator::class);
471
461
$ nonceGenerator ->method ('generate ' )->willReturn ('dummy_nonce ' );
472
462
473
463
return new ProfilerController ($ urlGenerator , $ profiler , $ twig , $ templates , new ContentSecurityPolicyHandler ($ nonceGenerator ));
0 commit comments