From d7aeaebd748c7d7745448b56913e9731a2e82976 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 23 May 2020 00:49:08 +0200 Subject: [PATCH] Parse and render anonymous classes correctly on php 8 --- Middleware/TraceableMiddleware.php | 3 +-- Tests/Middleware/TraceableMiddlewareTest.php | 19 +++++++++++-------- composer.json | 3 ++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Middleware/TraceableMiddleware.php b/Middleware/TraceableMiddleware.php index f0400c3c..bedade31 100644 --- a/Middleware/TraceableMiddleware.php +++ b/Middleware/TraceableMiddleware.php @@ -78,8 +78,7 @@ public function next(): MiddlewareInterface if ($this->stack === $nextMiddleware = $this->stack->next()) { $this->currentEvent = 'Tail'; } else { - $class = \get_class($nextMiddleware); - $this->currentEvent = sprintf('"%s"', 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class); + $this->currentEvent = sprintf('"%s"', get_debug_type($nextMiddleware)); } $this->currentEvent .= sprintf(' on "%s"', $this->busName); diff --git a/Tests/Middleware/TraceableMiddlewareTest.php b/Tests/Middleware/TraceableMiddlewareTest.php index 54be5775..3bc64675 100644 --- a/Tests/Middleware/TraceableMiddlewareTest.php +++ b/Tests/Middleware/TraceableMiddlewareTest.php @@ -30,14 +30,16 @@ public function testHandle() $busId = 'command_bus'; $envelope = new Envelope(new DummyMessage('Hello')); - $middleware = $this->getMockBuilder(MiddlewareInterface::class)->getMock(); - $middleware->expects($this->once()) - ->method('handle') - ->with($envelope, $this->anything()) - ->willReturnCallback(function ($envelope, StackInterface $stack) { + $middleware = new class() implements MiddlewareInterface { + public $calls = 0; + + public function handle(Envelope $envelope, StackInterface $stack): Envelope + { + ++$this->calls; + return $stack->next()->handle($envelope, $stack); - }) - ; + } + }; $stopwatch = $this->createMock(Stopwatch::class); $stopwatch->expects($this->once())->method('isStarted')->willReturn(true); @@ -51,7 +53,7 @@ public function testHandle() $stopwatch->expects($this->exactly(2)) ->method('stop') ->withConsecutive( - [$this->matches('"%sMiddlewareInterface%s" on "command_bus"')], + ['"Symfony\Component\Messenger\Middleware\MiddlewareInterface@anonymous" on "command_bus"'], ['Tail on "command_bus"'] ) ; @@ -59,6 +61,7 @@ public function testHandle() $traced = new TraceableMiddleware($stopwatch, $busId); $traced->handle($envelope, new StackMiddleware(new \ArrayIterator([null, $middleware]))); + $this->assertSame(1, $middleware->calls); } public function testHandleWithException() diff --git a/composer.json b/composer.json index dfe66f10..4d818a49 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ ], "require": { "php": ">=7.1.3", - "psr/log": "~1.0" + "psr/log": "~1.0", + "symfony/polyfill-php80": "^1.15" }, "require-dev": { "doctrine/dbal": "^2.6",