Skip to content

Commit

Permalink
[Stopwatch] fix wrong nullable type
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Jul 28, 2019
1 parent 44e6250 commit e7426ca
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion UPGRADE-5.0.md
Expand Up @@ -480,7 +480,7 @@ Serializer
Stopwatch
---------

* Removed support of passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead.
* Removed support for passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead.

Translation
-----------
Expand Down
Expand Up @@ -41,6 +41,9 @@ protected function beforeDispatch(string $eventName, $event)
break;
case KernelEvents::TERMINATE:
$token = $event->getResponse()->headers->get('X-Debug-Token');
if (null === $token) {
break;
}
// There is a very special case when using built-in AppCache class as kernel wrapper, in the case
// of an ESI request leading to a `stale` response [B] inside a `fresh` cached response [A].
// In this case, `$token` contains the [B] debug token, but the open `stopwatch` section ID
Expand All @@ -65,12 +68,18 @@ protected function afterDispatch(string $eventName, $event)
break;
case KernelEvents::RESPONSE:
$token = $event->getResponse()->headers->get('X-Debug-Token');
if (null === $token) {
break;
}
$this->stopwatch->stopSection($token);
break;
case KernelEvents::TERMINATE:
// In the special case described in the `preDispatch` method above, the `$token` section
// does not exist, then closing it throws an exception which must be caught.
$token = $event->getResponse()->headers->get('X-Debug-Token');
if (null === $token) {
break;
}
try {
$this->stopwatch->stopSection($token);
} catch (\LogicException $e) {
Expand Down
Expand Up @@ -62,15 +62,13 @@ public function testStopwatchCheckControllerOnRequestEvent()
public function testStopwatchStopControllerOnRequestEvent()
{
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
->setMethods(['isStarted', 'stop', 'stopSection'])
->setMethods(['isStarted', 'stop'])
->getMock();
$stopwatch->expects($this->once())
->method('isStarted')
->willReturn(true);
$stopwatch->expects($this->once())
->method('stop');
$stopwatch->expects($this->once())
->method('stopSection');

$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Stopwatch/CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.0.0
-----

* Removed support for passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead.

4.4.0
-----

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Stopwatch/Stopwatch.php
Expand Up @@ -81,7 +81,7 @@ public function openSection(string $id = null)
*
* @throws \LogicException When there's no started section to be stopped
*/
public function stopSection(?string $id)
public function stopSection(string $id)
{
$this->stop('__section__');

Expand Down

0 comments on commit e7426ca

Please sign in to comment.