thenMessageOfInstanceIsPublishedWithRoutingKeyOnBridge()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace TomCizek\AsynchronousRouter\Tests\DependencyInjection;
6
7
use Prooph\ServiceBus\Exception\RuntimeException;
8
use React\Promise\Deferred;
9
use TomCizek\AsynchronousRouter\AsynchronousMessageProducer;
10
use TomCizek\AsynchronousRouter\Tests\DependencyInjection\Fixture\Model\FirstAsynchronousMessageProducerBridge;
11
use TomCizek\AsynchronousRouter\Tests\DependencyInjection\Fixture\Model\FirstMessage;
12
13
class AsynchronousMessageProducerTest extends ContainerTestCase
14
{
15
    public function testInvoke_WithRoutedMessage_ShouldPublishCorrectly()
16
    {
17
        $this->givenContainerWithFixtureFiles(
18
            ['commonServices', 'firstMessageRoute']
19
        );
20
21
        $asynchronousMessageProducer = $this->givenAsynchronousProducerFromContainer(
22
            'prooph_asynchronous_router.firstProducer'
23
        );
24
25
        $this->whenInvokeMessageProcuderWithFirstMessage($asynchronousMessageProducer);
26
27
        $this->thenMessageOfInstanceIsPublishedWithRoutingKeyOnBridge(
28
            FirstMessage::class,
29
            'first_routing_key',
30
            'firstAsynchronousMessageProducerBridge'
31
        );
32
    }
33
34 View Code Duplication
    public function testInvoke_WithNonRoutedMessage_ShouldThrowRuntimeException()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $this->givenContainerWithFixtureFiles(
37
            ['commonServices', 'secondMessageRoute']
38
        );
39
40
        $asynchronousMessageProducer = $this->givenAsynchronousProducerFromContainer(
41
            'prooph_asynchronous_router.secondProducer'
42
        );
43
44
        $this->expectException(RuntimeException::class);
45
46
        $this->whenInvokeMessageProcuderWithFirstMessage($asynchronousMessageProducer);
47
    }
48
49 View Code Duplication
    public function testInvoke_WithDefferedParam_ShouldThrowRuntimeException()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $this->givenContainerWithFixtureFiles(
52
            ['commonServices', 'firstMessageRoute']
53
        );
54
55
        $asynchronousMessageProducer = $this->givenAsynchronousProducerFromContainer(
56
            'prooph_asynchronous_router.firstProducer'
57
        );
58
59
        $this->expectException(RuntimeException::class);
60
61
        $this->whenInvokeMessageProcuderWithDeferredParam($asynchronousMessageProducer);
62
    }
63
64
    protected function givenAsynchronousProducerFromContainer(string $serviceId): AsynchronousMessageProducer
65
    {
66
        /** @var AsynchronousMessageProducer $asynchronousMessageProducer */
67
        $asynchronousMessageProducer = $this->containerBuilder->get($serviceId);
68
69
        return $asynchronousMessageProducer;
70
    }
71
72
    protected function whenInvokeMessageProcuderWithFirstMessage(
73
        AsynchronousMessageProducer $asynchronousMessageProducer
74
    ): void {
75
        $fooMessage = new FirstMessage([]);
76
        $asynchronousMessageProducer($fooMessage);
77
    }
78
79
    protected function whenInvokeMessageProcuderWithDeferredParam(
80
        AsynchronousMessageProducer $asynchronousMessageProducer
81
    ): void {
82
        $fooMessage = new FirstMessage([]);
83
        $asynchronousMessageProducer($fooMessage, new Deferred());
84
    }
85
86
    protected function thenMessageOfInstanceIsPublishedWithRoutingKeyOnBridge(
87
        string $messageInstance,
88
        string $routingKey,
89
        string $bridgeServiceId
90
    ): void {
91
        /** @var FirstAsynchronousMessageProducerBridge $testAsynchronousMessageProducerBridge */
92
        $testAsynchronousMessageProducerBridge = $this->containerBuilder->get($bridgeServiceId);
93
        $published = $testAsynchronousMessageProducerBridge->getPublished();
94
95
        self::assertCount(1, $published);
96
        self::assertNotEmpty($published[0]);
97
        self::assertEquals($routingKey, $published[0]['routingKey']);
98
        self::assertInstanceOf($messageInstance, $published[0]['message']);
99
    }
100
}
101