-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PBC-1677: Adjust ValidationMiddlewarePlugin to only throw exceptions …
…on received messages (#10217) PBC-1677 Fixed MessageBroker ValidationMiddlewarePlugin to only throw exceptions on received messages
- Loading branch information
1 parent
9a64abc
commit d444f24
Showing
5 changed files
with
225 additions
and
1 deletion.
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
112 changes: 112 additions & 0 deletions
112
...t/Zed/MessageBroker/Communication/Plugin/MessageBroker/ValidationMiddlewarePluginTest.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,112 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerTest\Zed\MessageBroker\Communication\Plugin\MessageBroker; | ||
|
||
use Codeception\Test\Unit; | ||
use SprykerTest\Zed\MessageBroker\MessageBrokerCommunicationTester; | ||
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; | ||
use Symfony\Component\Messenger\Stamp\ReceivedStamp; | ||
|
||
/** | ||
* Auto-generated group annotations | ||
* | ||
* @group SprykerTest | ||
* @group Zed | ||
* @group MessageBroker | ||
* @group Communication | ||
* @group Plugin | ||
* @group MessageBroker | ||
* @group ValidationMiddlewarePluginTest | ||
* Add your own group annotations below this line | ||
*/ | ||
class ValidationMiddlewarePluginTest extends Unit | ||
{ | ||
/** | ||
* @var \SprykerTest\Zed\MessageBroker\MessageBrokerCommunicationTester | ||
*/ | ||
protected MessageBrokerCommunicationTester $tester; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testValidationMiddlewarePluginCantHandleReceivedMessageWillThrowException(): void | ||
{ | ||
// Arrange | ||
$envelope = $this->tester->haveEnvelopeWithReceivedStamp(); | ||
|
||
$validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanNotHandleAMessage(); | ||
|
||
$stackMock = $this->tester->createStackMockWithNeverCalledNextMethod(); | ||
|
||
// Expectation | ||
$this->expectException(UnrecoverableMessageHandlingException::class); | ||
|
||
// Act | ||
$validationMiddlewarePlugin->handle($envelope, $stackMock); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testValidationMiddlewarePluginCantHandleSentMessageWillReturnUnhandledEnvelope(): void | ||
{ | ||
// Arrange | ||
$envelope = $this->tester->haveEnvelope(); | ||
|
||
$validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanNotHandleAMessage(); | ||
|
||
$stackMock = $this->tester->createStackMockWithNeverCalledNextMethod(); | ||
|
||
// Act | ||
$handledEnvelope = $validationMiddlewarePlugin->handle($envelope, $stackMock); | ||
|
||
// Assert | ||
$this->assertSame($envelope, $handledEnvelope); | ||
$this->assertCount(0, $handledEnvelope->all()); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testValidationMiddlewarePluginCanHandleSentMessageWillReturnEnvelope(): void | ||
{ | ||
// Arrange | ||
$envelope = $this->tester->haveEnvelope(); | ||
|
||
$validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanHandleAMessage(); | ||
|
||
$stackMock = $this->tester->createStackMockWithOnceCalledNextMethod($envelope); | ||
|
||
// Act | ||
$handledEnvelope = $validationMiddlewarePlugin->handle($envelope, $stackMock); | ||
|
||
// Assert | ||
$this->assertSame($envelope, $handledEnvelope); | ||
$this->assertCount(0, $handledEnvelope->all()); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testValidationMiddlewarePluginCanHandleReceivedMessageWillReturnEnvelope(): void | ||
{ | ||
// Arrange | ||
$envelope = $this->tester->haveEnvelopeWithReceivedStamp(); | ||
|
||
$validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanHandleAMessage(true); | ||
|
||
$stackMock = $this->tester->createStackMockWithOnceCalledNextMethod($envelope); | ||
|
||
// Act | ||
$handledEnvelope = $validationMiddlewarePlugin->handle($envelope, $stackMock); | ||
|
||
// Assert | ||
$this->assertSame($envelope, $handledEnvelope); | ||
$this->assertCount(1, $handledEnvelope->all(ReceivedStamp::class)); | ||
} | ||
} |
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