From bf4b0cc022140e913942952015a11a0486d89547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 21 Dec 2020 19:37:54 +0100 Subject: [PATCH 1/2] [Messenger] Fix stopwach usage if it has been reset --- .../Middleware/TraceableMiddleware.php | 2 +- .../Middleware/TraceableMiddlewareTest.php | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Messenger/Middleware/TraceableMiddleware.php b/src/Symfony/Component/Messenger/Middleware/TraceableMiddleware.php index bedade318f..f391cfe6d0 100644 --- a/src/Symfony/Component/Messenger/Middleware/TraceableMiddleware.php +++ b/src/Symfony/Component/Messenger/Middleware/TraceableMiddleware.php @@ -71,7 +71,7 @@ class TraceableStack implements StackInterface */ public function next(): MiddlewareInterface { - if (null !== $this->currentEvent) { + if (null !== $this->currentEvent && $this->stopwatch->isStarted($this->currentEvent)) { $this->stopwatch->stop($this->currentEvent); } diff --git a/src/Symfony/Component/Messenger/Tests/Middleware/TraceableMiddlewareTest.php b/src/Symfony/Component/Messenger/Tests/Middleware/TraceableMiddlewareTest.php index 3bc64675d9..0370d86726 100644 --- a/src/Symfony/Component/Messenger/Tests/Middleware/TraceableMiddlewareTest.php +++ b/src/Symfony/Component/Messenger/Tests/Middleware/TraceableMiddlewareTest.php @@ -42,7 +42,7 @@ class TraceableMiddlewareTest extends MiddlewareTestCase }; $stopwatch = $this->createMock(Stopwatch::class); - $stopwatch->expects($this->once())->method('isStarted')->willReturn(true); + $stopwatch->expects($this->exactly(2))->method('isStarted')->willReturn(true); $stopwatch->expects($this->exactly(2)) ->method('start') ->withConsecutive( @@ -91,4 +91,36 @@ class TraceableMiddlewareTest extends MiddlewareTestCase $traced = new TraceableMiddleware($stopwatch, $busId); $traced->handle(new Envelope(new DummyMessage('Hello')), new StackMiddleware(new \ArrayIterator([null, $middleware]))); } + + public function testHandleWhenStopwatchHasBeenReset() + { + $busId = 'command_bus'; + $envelope = new Envelope(new DummyMessage('Hello')); + + $stopwatch = new Stopwatch(); + + $middleware = new class($stopwatch) implements MiddlewareInterface { + public $calls = 0; + private $stopwatch; + + public function __construct(Stopwatch $stopwatch) + { + $this->stopwatch = $stopwatch; + } + + public function handle(Envelope $envelope, StackInterface $stack): Envelope + { + $this->stopwatch->reset(); + + ++$this->calls; + + return $stack->next()->handle($envelope, $stack); + } + }; + + $traced = new TraceableMiddleware($stopwatch, $busId); + + $traced->handle($envelope, new StackMiddleware(new \ArrayIterator([null, $middleware]))); + $this->assertSame(1, $middleware->calls); + } } From cd0db690f836c32c4d57cfce4fdebec2526ac15a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 28 Dec 2020 22:45:17 +0100 Subject: [PATCH 2/2] [ProxyManagerBridge] Fix tests --- .../Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php index 324304f683..1dee20d7a3 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php @@ -2,8 +2,7 @@ class SunnyInterface_%s implements \ProxyManager\Proxy\VirtualProxyInterface, \Symfony\Bridge\ProxyManager\Tests\LazyProxy\PhpDumper\DummyInterface, \Symfony\Bridge\ProxyManager\Tests\LazyProxy\PhpDumper\SunnyInterface { - - private $valueHolder%s = null; +%w private $valueHolder%s = null; private $initializer%s = null; @@ -96,7 +95,7 @@ class SunnyInterface_%s implements \ProxyManager\Proxy\VirtualProxyInterface, \S $targetObject = $this->valueHolder%s; - $targetObject->$name = $value; return $targetObject->$name; + $targetObject->$name = $value;%wreturn $targetObject->$name; } public function __isset($name) @@ -158,7 +157,5 @@ class SunnyInterface_%s implements \ProxyManager\Proxy\VirtualProxyInterface, \S public function getWrappedValueHolderValue()%S { return $this->valueHolder%s; - } - - + }%w }