Skip to content

Commit 9a90620

Browse files
Merge branch '4.4' into 5.1
* 4.4: Use createMock() and use import instead of FQCN
2 parents acd72fb + 6cde986 commit 9a90620

File tree

5 files changed

+41
-47
lines changed

5 files changed

+41
-47
lines changed

Tests/Controller/ProfilerControllerTest.php

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1616
use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController;
1717
use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
18+
use Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator;
1819
use Symfony\Bundle\WebProfilerBundle\Tests\Functional\WebProfilerBundleKernel;
1920
use Symfony\Component\HttpFoundation\Request;
2021
use Symfony\Component\HttpFoundation\Response;
@@ -24,6 +25,7 @@
2425
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2526
use Symfony\Component\HttpKernel\Profiler\Profile;
2627
use Symfony\Component\HttpKernel\Profiler\Profiler;
28+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2729
use Twig\Environment;
2830
use Twig\Loader\LoaderInterface;
2931
use Twig\Loader\SourceContextLoaderInterface;
@@ -35,8 +37,8 @@ public function testHomeActionWithProfilerDisabled()
3537
$this->expectException(NotFoundHttpException::class);
3638
$this->expectExceptionMessage('The profiler must be enabled.');
3739

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);
4042

4143
$controller = new ProfilerController($urlGenerator, null, $twig, []);
4244
$controller->homeAction();
@@ -111,8 +113,8 @@ public function testToolbarActionWithProfilerDisabled()
111113
$this->expectException(NotFoundHttpException::class);
112114
$this->expectExceptionMessage('The profiler must be enabled.');
113115

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);
116118

117119
$controller = new ProfilerController($urlGenerator, null, $twig, []);
118120
$controller->toolbarAction(Request::create('/_wdt/foo-token'), null);
@@ -123,12 +125,9 @@ public function testToolbarActionWithProfilerDisabled()
123125
*/
124126
public function testToolbarActionWithEmptyToken($token)
125127
{
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);
132131

133132
$controller = new ProfilerController($urlGenerator, $profiler, $twig, []);
134133

@@ -150,12 +149,9 @@ public function getEmptyTokenCases()
150149
*/
151150
public function testOpeningDisallowedPaths($path, $isAllowed)
152151
{
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);
159155

160156
$controller = new ProfilerController($urlGenerator, $profiler, $twig, [], null, __DIR__.'/../..');
161157

@@ -186,11 +182,8 @@ public function getOpenFileCases()
186182
*/
187183
public function testReturns404onTokenNotFound($withCsp)
188184
{
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);
194187

195188
$profiler
196189
->expects($this->exactly(2))
@@ -214,8 +207,8 @@ public function testSearchBarActionWithProfilerDisabled()
214207
$this->expectException(NotFoundHttpException::class);
215208
$this->expectExceptionMessage('The profiler must be enabled.');
216209

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);
219212

220213
$controller = new ProfilerController($urlGenerator, null, $twig, []);
221214
$controller->searchBarAction(Request::create('/_profiler/search_bar'));
@@ -240,11 +233,8 @@ public function testSearchBarActionDefaultPage()
240233
*/
241234
public function testSearchResultsAction($withCsp)
242235
{
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);
248238

249239
$controller = $this->createController($profiler, $twig, $withCsp);
250240

@@ -306,8 +296,8 @@ public function testSearchActionWithProfilerDisabled()
306296
$this->expectException(NotFoundHttpException::class);
307297
$this->expectExceptionMessage('The profiler must be enabled.');
308298

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);
311301

312302
$controller = new ProfilerController($urlGenerator, null, $twig, []);
313303
$controller->searchBarAction(Request::create('/_profiler/search'));
@@ -345,8 +335,8 @@ public function testPhpinfoActionWithProfilerDisabled()
345335
$this->expectException(NotFoundHttpException::class);
346336
$this->expectExceptionMessage('The profiler must be enabled.');
347337

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);
350340

351341
$controller = new ProfilerController($urlGenerator, null, $twig, []);
352342
$controller->phpinfoAction(Request::create('/_profiler/phpinfo'));
@@ -464,10 +454,10 @@ public function defaultPanelProvider(): \Generator
464454

465455
private function createController($profiler, $twig, $withCSP, array $templates = []): ProfilerController
466456
{
467-
$urlGenerator = $this->getMockBuilder(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)->getMock();
457+
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
468458

469459
if ($withCSP) {
470-
$nonceGenerator = $this->getMockBuilder(\Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator::class)->getMock();
460+
$nonceGenerator = $this->createMock(NonceGenerator::class);
471461
$nonceGenerator->method('generate')->willReturn('dummy_nonce');
472462

473463
return new ProfilerController($urlGenerator, $profiler, $twig, $templates, new ContentSecurityPolicyHandler($nonceGenerator));

Tests/Csp/ContentSecurityPolicyHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
16+
use Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator;
1617
use Symfony\Component\HttpFoundation\Request;
1718
use Symfony\Component\HttpFoundation\Response;
1819

@@ -210,7 +211,7 @@ private function createResponse(array $headers = [])
210211

211212
private function mockNonceGenerator($value)
212213
{
213-
$generator = $this->getMockBuilder(\Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator::class)->getMock();
214+
$generator = $this->createMock(NonceGenerator::class);
214215

215216
$generator->expects($this->any())
216217
->method('generate')

Tests/DependencyInjection/WebProfilerExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function setUp(): void
5252
{
5353
parent::setUp();
5454

55-
$this->kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
55+
$this->kernel = $this->createMock(KernelInterface::class);
5656

5757
$this->container = new ContainerBuilder();
5858
$this->container->register('error_handler.error_renderer.html', HtmlErrorRenderer::class)->setPublic(true);

Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
use Symfony\Component\HttpFoundation\HeaderBag;
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpFoundation\Response;
19+
use Symfony\Component\HttpFoundation\Session\Session;
1920
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2021
use Symfony\Component\HttpKernel\HttpKernelInterface;
22+
use Symfony\Component\HttpKernel\Kernel;
2123
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
24+
use Twig\Environment;
2225

2326
class WebDebugToolbarListenerTest extends TestCase
2427
{
@@ -310,7 +313,7 @@ protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'h
310313
$request->headers = new HeaderBag();
311314

312315
if ($hasSession) {
313-
$session = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\Session::class)->disableOriginalConstructor()->getMock();
316+
$session = $this->createMock(Session::class);
314317
$request->expects($this->any())
315318
->method('getSession')
316319
->willReturn($session);
@@ -321,7 +324,7 @@ protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'h
321324

322325
protected function getTwigMock($render = 'WDT')
323326
{
324-
$templating = $this->getMockBuilder(\Twig\Environment::class)->disableOriginalConstructor()->getMock();
327+
$templating = $this->createMock(Environment::class);
325328
$templating->expects($this->any())
326329
->method('render')
327330
->willReturn($render);
@@ -331,11 +334,11 @@ protected function getTwigMock($render = 'WDT')
331334

332335
protected function getUrlGeneratorMock()
333336
{
334-
return $this->getMockBuilder(UrlGeneratorInterface::class)->getMock();
337+
return $this->createMock(UrlGeneratorInterface::class);
335338
}
336339

337340
protected function getKernelMock()
338341
{
339-
return $this->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class)->disableOriginalConstructor()->getMock();
342+
return $this->createMock(Kernel::class);
340343
}
341344
}

Tests/Profiler/TemplateManagerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
1515
use Symfony\Bundle\WebProfilerBundle\Tests\TestCase;
16+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1617
use Symfony\Component\HttpKernel\Profiler\Profile;
18+
use Symfony\Component\HttpKernel\Profiler\Profiler;
1719
use Twig\Environment;
1820
use Twig\Loader\LoaderInterface;
1921

@@ -30,7 +32,7 @@ class TemplateManagerTest extends TestCase
3032
protected $twigEnvironment;
3133

3234
/**
33-
* @var \Symfony\Component\HttpKernel\Profiler\Profiler
35+
* @var Profiler
3436
*/
3537
protected $profiler;
3638

@@ -56,7 +58,7 @@ protected function setUp(): void
5658

5759
public function testGetNameOfInvalidTemplate()
5860
{
59-
$this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class);
61+
$this->expectException(NotFoundHttpException::class);
6062
$this->templateManager->getName(new Profile('token'), 'notexistingpanel');
6163
}
6264

@@ -97,12 +99,12 @@ public function profileHasCollectorCallback($panel)
9799

98100
protected function mockProfile()
99101
{
100-
return $this->getMockBuilder(Profile::class)->disableOriginalConstructor()->getMock();
102+
return $this->createMock(Profile::class);
101103
}
102104

103105
protected function mockTwigEnvironment()
104106
{
105-
$this->twigEnvironment = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
107+
$this->twigEnvironment = $this->createMock(Environment::class);
106108

107109
$loader = $this->createMock(LoaderInterface::class);
108110
$loader
@@ -117,9 +119,7 @@ protected function mockTwigEnvironment()
117119

118120
protected function mockProfiler()
119121
{
120-
$this->profiler = $this->getMockBuilder(\Symfony\Component\HttpKernel\Profiler\Profiler::class)
121-
->disableOriginalConstructor()
122-
->getMock();
122+
$this->profiler = $this->createMock(Profiler::class);
123123

124124
return $this->profiler;
125125
}

0 commit comments

Comments
 (0)