Issues (3641)

MessageBroker/ValidationMiddlewarePluginTest.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerTest\Zed\MessageBroker\Communication\Plugin\MessageBroker;
9
10
use Codeception\Test\Unit;
11
use SprykerTest\Zed\MessageBroker\MessageBrokerCommunicationTester;
12
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
13
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
14
15
/**
16
 * Auto-generated group annotations
17
 *
18
 * @group SprykerTest
19
 * @group Zed
20
 * @group MessageBroker
21
 * @group Communication
22
 * @group Plugin
23
 * @group MessageBroker
24
 * @group ValidationMiddlewarePluginTest
25
 * Add your own group annotations below this line
26
 */
27
class ValidationMiddlewarePluginTest extends Unit
28
{
29
    /**
30
     * @var \SprykerTest\Zed\MessageBroker\MessageBrokerCommunicationTester
31
     */
32
    protected MessageBrokerCommunicationTester $tester;
33
34
    /**
35
     * @return void
36
     */
37
    public function testValidationMiddlewarePluginCantHandleReceivedMessageWillThrowException(): void
38
    {
39
        // Arrange
40
        $envelope = $this->tester->haveEnvelopeWithReceivedStamp();
41
42
        $validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanNotHandleAMessage();
43
44
        $stackMock = $this->tester->createStackMockWithNeverCalledNextMethod();
45
46
        // Expectation
47
        $this->expectException(UnrecoverableMessageHandlingException::class);
48
49
        // Act
50
        $validationMiddlewarePlugin->handle($envelope, $stackMock);
51
    }
52
53
    /**
54
     * @return void
55
     */
56
    public function testValidationMiddlewarePluginCantHandleSentMessageWillReturnUnhandledEnvelope(): void
57
    {
58
        // Arrange
59
        $envelope = $this->tester->haveEnvelope();
60
61
        $validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanNotHandleAMessage();
62
63
        $stackMock = $this->tester->createStackMockWithNeverCalledNextMethod();
64
65
        // Act
66
        $handledEnvelope = $validationMiddlewarePlugin->handle($envelope, $stackMock);
67
68
        // Assert
69
        $this->assertSame($envelope, $handledEnvelope);
70
        $this->assertCount(0, $handledEnvelope->all());
71
    }
72
73
    /**
74
     * @return void
75
     */
76
    public function testValidationMiddlewarePluginCanHandleSentMessageWillReturnEnvelope(): void
77
    {
78
        // Arrange
79
        $envelope = $this->tester->haveEnvelope();
80
81
        $validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanHandleAMessage();
82
83
        $stackMock = $this->tester->createStackMockWithOnceCalledNextMethod($envelope);
84
85
        // Act
86
        $handledEnvelope = $validationMiddlewarePlugin->handle($envelope, $stackMock);
87
88
        // Assert
89
        $this->assertSame($envelope, $handledEnvelope);
90
        $this->assertCount(0, $handledEnvelope->all());
91
    }
92
93
    /**
94
     * @return void
95
     */
96
    public function testValidationMiddlewarePluginCanHandleReceivedMessageWillReturnEnvelope(): void
97
    {
98
        // Arrange
99
        $envelope = $this->tester->haveEnvelopeWithReceivedStamp();
100
101
        $validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanHandleAMessage(true);
0 ignored issues
show
The call to SprykerTest\Zed\MessageB...ThatCanHandleAMessage() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
        /** @scrutinizer ignore-call */ 
102
        $validationMiddlewarePlugin = $this->tester->createValidationMiddlewarePluginThatCanHandleAMessage(true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
102
103
        $stackMock = $this->tester->createStackMockWithOnceCalledNextMethod($envelope);
104
105
        // Act
106
        $handledEnvelope = $validationMiddlewarePlugin->handle($envelope, $stackMock);
107
108
        // Assert
109
        $this->assertSame($envelope, $handledEnvelope);
110
        $this->assertCount(1, $handledEnvelope->all(ReceivedStamp::class));
111
    }
112
}
113