Skip to content

Commit 4b28c24

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: Use createMock() instead of a getter [ErrorHandler] Fix strpos error when trying to call a method without a name use proper keys to not override appended files Fix console logger according to PSR-3
2 parents d9ce6aa + 2a5eeaa commit 4b28c24

File tree

2 files changed

+20
-44
lines changed

2 files changed

+20
-44
lines changed

Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testHtmlRedirectionIsIntercepted($statusCode, $hasSession)
6565
{
6666
$response = new Response('Some content', $statusCode);
6767
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
68-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
68+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
6969

7070
$listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
7171
$listener->onKernelResponse($event);
@@ -78,7 +78,7 @@ public function testNonHtmlRedirectionIsNotIntercepted()
7878
{
7979
$response = new Response('Some content', '301');
8080
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
81-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'json', true), HttpKernelInterface::MASTER_REQUEST, $response);
81+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'json', true), HttpKernelInterface::MASTER_REQUEST, $response);
8282

8383
$listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
8484
$listener->onKernelResponse($event);
@@ -92,7 +92,7 @@ public function testToolbarIsInjected()
9292
$response = new Response('<html><head></head><body></body></html>');
9393
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
9494

95-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
95+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
9696

9797
$listener = new WebDebugToolbarListener($this->getTwigMock());
9898
$listener->onKernelResponse($event);
@@ -108,7 +108,7 @@ public function testToolbarIsNotInjectedOnNonHtmlContentType()
108108
$response = new Response('<html><head></head><body></body></html>');
109109
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
110110
$response->headers->set('Content-Type', 'text/xml');
111-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
111+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
112112

113113
$listener = new WebDebugToolbarListener($this->getTwigMock());
114114
$listener->onKernelResponse($event);
@@ -124,7 +124,7 @@ public function testToolbarIsNotInjectedOnContentDispositionAttachment()
124124
$response = new Response('<html><head></head><body></body></html>');
125125
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
126126
$response->headers->set('Content-Disposition', 'attachment; filename=test.html');
127-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html'), HttpKernelInterface::MASTER_REQUEST, $response);
127+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'html'), HttpKernelInterface::MASTER_REQUEST, $response);
128128

129129
$listener = new WebDebugToolbarListener($this->getTwigMock());
130130
$listener->onKernelResponse($event);
@@ -140,7 +140,7 @@ public function testToolbarIsNotInjectedOnRedirection($statusCode, $hasSession)
140140
{
141141
$response = new Response('<html><head></head><body></body></html>', $statusCode);
142142
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
143-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
143+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response);
144144

145145
$listener = new WebDebugToolbarListener($this->getTwigMock());
146146
$listener->onKernelResponse($event);
@@ -165,7 +165,7 @@ public function testToolbarIsNotInjectedWhenThereIsNoNoXDebugTokenResponseHeader
165165
{
166166
$response = new Response('<html><head></head><body></body></html>');
167167

168-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
168+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
169169

170170
$listener = new WebDebugToolbarListener($this->getTwigMock());
171171
$listener->onKernelResponse($event);
@@ -181,7 +181,7 @@ public function testToolbarIsNotInjectedWhenOnSubRequest()
181181
$response = new Response('<html><head></head><body></body></html>');
182182
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
183183

184-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::SUB_REQUEST, $response);
184+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::SUB_REQUEST, $response);
185185

186186
$listener = new WebDebugToolbarListener($this->getTwigMock());
187187
$listener->onKernelResponse($event);
@@ -197,7 +197,7 @@ public function testToolbarIsNotInjectedOnIncompleteHtmlResponses()
197197
$response = new Response('<div>Some content</div>');
198198
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
199199

200-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
200+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
201201

202202
$listener = new WebDebugToolbarListener($this->getTwigMock());
203203
$listener->onKernelResponse($event);
@@ -213,7 +213,7 @@ public function testToolbarIsNotInjectedOnXmlHttpRequests()
213213
$response = new Response('<html><head></head><body></body></html>');
214214
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
215215

216-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(true), HttpKernelInterface::MASTER_REQUEST, $response);
216+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(true), HttpKernelInterface::MASTER_REQUEST, $response);
217217

218218
$listener = new WebDebugToolbarListener($this->getTwigMock());
219219
$listener->onKernelResponse($event);
@@ -229,7 +229,7 @@ public function testToolbarIsNotInjectedOnNonHtmlRequests()
229229
$response = new Response('<html><head></head><body></body></html>');
230230
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
231231

232-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'json'), HttpKernelInterface::MASTER_REQUEST, $response);
232+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(false, 'json'), HttpKernelInterface::MASTER_REQUEST, $response);
233233

234234
$listener = new WebDebugToolbarListener($this->getTwigMock());
235235
$listener->onKernelResponse($event);
@@ -242,15 +242,15 @@ public function testXDebugUrlHeader()
242242
$response = new Response();
243243
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
244244

245-
$urlGenerator = $this->getUrlGeneratorMock();
245+
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
246246
$urlGenerator
247247
->expects($this->once())
248248
->method('generate')
249249
->with('_profiler', ['token' => 'xxxxxxxx'], UrlGeneratorInterface::ABSOLUTE_URL)
250250
->willReturn('http://mydomain.com/_profiler/xxxxxxxx')
251251
;
252252

253-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
253+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
254254

255255
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
256256
$listener->onKernelResponse($event);
@@ -263,15 +263,15 @@ public function testThrowingUrlGenerator()
263263
$response = new Response();
264264
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
265265

266-
$urlGenerator = $this->getUrlGeneratorMock();
266+
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
267267
$urlGenerator
268268
->expects($this->once())
269269
->method('generate')
270270
->with('_profiler', ['token' => 'xxxxxxxx'])
271271
->willThrowException(new \Exception('foo'))
272272
;
273273

274-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
274+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
275275

276276
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
277277
$listener->onKernelResponse($event);
@@ -284,15 +284,15 @@ public function testThrowingErrorCleanup()
284284
$response = new Response();
285285
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
286286

287-
$urlGenerator = $this->getUrlGeneratorMock();
287+
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
288288
$urlGenerator
289289
->expects($this->once())
290290
->method('generate')
291291
->with('_profiler', ['token' => 'xxxxxxxx'])
292292
->willThrowException(new \Exception("This\nmultiline\r\ntabbed text should\tcome out\r on\n \ta single plain\r\nline"))
293293
;
294294

295-
$event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
295+
$event = new ResponseEvent($this->createMock(Kernel::class), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);
296296

297297
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator);
298298
$listener->onKernelResponse($event);
@@ -331,14 +331,4 @@ protected function getTwigMock($render = 'WDT')
331331

332332
return $templating;
333333
}
334-
335-
protected function getUrlGeneratorMock()
336-
{
337-
return $this->createMock(UrlGeneratorInterface::class);
338-
}
339-
340-
protected function getKernelMock()
341-
{
342-
return $this->createMock(Kernel::class);
343-
}
344334
}

Tests/Profiler/TemplateManagerTest.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
use Twig\Loader\LoaderInterface;
2121

2222
/**
23-
* Test for TemplateManager class.
24-
*
2523
* @author Artur Wielogórski <wodor@wodor.net>
2624
*/
2725
class TemplateManagerTest extends TestCase
@@ -37,23 +35,23 @@ class TemplateManagerTest extends TestCase
3735
protected $profiler;
3836

3937
/**
40-
* @var \Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager
38+
* @var TemplateManager
4139
*/
4240
protected $templateManager;
4341

4442
protected function setUp(): void
4543
{
4644
parent::setUp();
4745

48-
$profiler = $this->mockProfiler();
46+
$this->profiler = $this->createMock(Profiler::class);
4947
$twigEnvironment = $this->mockTwigEnvironment();
5048
$templates = [
5149
'data_collector.foo' => ['foo', '@Foo/Collector/foo.html.twig'],
5250
'data_collector.bar' => ['bar', '@Foo/Collector/bar.html.twig'],
5351
'data_collector.baz' => ['baz', '@Foo/Collector/baz.html.twig'],
5452
];
5553

56-
$this->templateManager = new TemplateManager($profiler, $twigEnvironment, $templates);
54+
$this->templateManager = new TemplateManager($this->profiler, $twigEnvironment, $templates);
5755
}
5856

5957
public function testGetNameOfInvalidTemplate()
@@ -97,11 +95,6 @@ public function profileHasCollectorCallback($panel)
9795
}
9896
}
9997

100-
protected function mockProfile()
101-
{
102-
return $this->createMock(Profile::class);
103-
}
104-
10598
protected function mockTwigEnvironment()
10699
{
107100
$this->twigEnvironment = $this->createMock(Environment::class);
@@ -116,13 +109,6 @@ protected function mockTwigEnvironment()
116109

117110
return $this->twigEnvironment;
118111
}
119-
120-
protected function mockProfiler()
121-
{
122-
$this->profiler = $this->createMock(Profiler::class);
123-
124-
return $this->profiler;
125-
}
126112
}
127113

128114
class ProfileDummy extends Profile

0 commit comments

Comments
 (0)