-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #31204 [Messenger] ease testing and allow forking the middlew…
…are stack (nicolas-grekas) This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger] ease testing and allow forking the middleware stack | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31179 | License | MIT | Doc PR | - A less radical alternative than #31185 that preserves laziness and addresses the linked issue. Commits ------- 3bdf4b0 [Messenger] ease testing and allow forking the middleware stack
- Loading branch information
Showing
4 changed files
with
121 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Symfony/Component/Messenger/Tests/Middleware/StackMiddlewareTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger\Tests\Middleware; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\MessageBus; | ||
use Symfony\Component\Messenger\Middleware\MiddlewareInterface; | ||
use Symfony\Component\Messenger\Middleware\StackInterface; | ||
|
||
class StackMiddlewareTest extends TestCase | ||
{ | ||
public function testClone() | ||
{ | ||
$middleware1 = $this->getMockBuilder(MiddlewareInterface::class)->getMock(); | ||
$middleware1 | ||
->expects($this->once()) | ||
->method('handle') | ||
->willReturnCallback(function (Envelope $envelope, StackInterface $stack): Envelope { | ||
$fork = clone $stack; | ||
|
||
$stack->next()->handle($envelope, $stack); | ||
$fork->next()->handle($envelope, $fork); | ||
|
||
return $envelope; | ||
}) | ||
; | ||
|
||
$middleware2 = $this->getMockBuilder(MiddlewareInterface::class)->getMock(); | ||
$middleware2 | ||
->expects($this->exactly(2)) | ||
->method('handle') | ||
->willReturnCallback(function (Envelope $envelope, StackInterface $stack): Envelope { | ||
return $envelope; | ||
}) | ||
; | ||
|
||
$bus = new MessageBus([$middleware1, $middleware2]); | ||
|
||
$bus->dispatch(new \stdClass()); | ||
} | ||
} |