Completed
Push — master ( f129a6...32f3bd )
by Tomáš
02:23
created

AsynchronousMessageProducerTest::willFailWith()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace TomCizek\SymfonyProoph\Tests\AsynchronousMessages;
4
5
use Mockery;
6
use Prooph\Common\Messaging\Message;
7
use Prooph\Common\Messaging\NoOpMessageConverter;
8
use Prooph\ServiceBus\Exception\RuntimeException;
9
use Ramsey\Uuid\Uuid;
10
use React\Promise\Deferred;
11
use TomCizek\SymfonyProoph\AsynchronousMessages\AsynchronousMessageProducer;
12
use TomCizek\SymfonyProoph\Tests\AsynchronousMessages\FakeImplementations\TestAsynchronousMessageProducerBridge;
13
use TomCizek\SymfonyProoph\Tests\EventSourcing\FakeImplementations\TestAggregateCreated;
14
15
class AsynchronousMessageProducerTest extends AbstractAsynchronousMessagesTestCase
16
{
17
	const TEST_PRODUCER_ROUTE_KEY = 'producerRouteKey';
18
19
	/** @var TestAsynchronousMessageProducerBridge */
20
	private $testProducerBridge;
21
22
	/** @var AsynchronousMessageProducer */
23
	private $testProducer;
24
25
	public function setUp()
26
	{
27
		parent::setUp();
28
		$this->givenTestProducerBridge();
29
		$this->givenAsynchronousMessageProducer();
30
	}
31
32
	public function testInvoke_WithDeferredParam_ShouldThrowRuntimeException()
33
	{
34
		$testMessage = $this->givenTestMessage();
35
		$deffered = $this->givenMockedDeffered();
36
37
		$this->willThrowException(RuntimeException::class);
38
39
		$this->whenInvokeProducerWith($testMessage, $deffered);
40
	}
41
42
	public function testInvoke_WithoutRoutes_ShouldThrowRuntimeException()
43
	{
44
		$testMessage = $this->givenTestMessage();
45
46
		$this->willThrowException(RuntimeException::class);
47
48
		$this->whenInvokeProducerWith($testMessage);
49
	}
50
51
	public function testInvoke_WithProperRoute_ShouldPublishExpectedMessageToExpectedProducerRouteKey()
52
	{
53
		$this->givenTestProducerHasInjectedTestRoute();
54
55
		$testMessage = $this->givenTestMessage();
56
57
		$this->whenInvokeProducerWith($testMessage);
58
59
		$this->thenShouldPublishExpectedMessageToExpectedProducerRouteKey(self::TEST_PRODUCER_ROUTE_KEY);
60
	}
61
62
	private function givenTestProducerBridge(): void
63
	{
64
		$this->testProducerBridge = new TestAsynchronousMessageProducerBridge();
65
	}
66
67
	private function givenAsynchronousMessageProducer(): void
68
	{
69
		$messageConverter = new NoOpMessageConverter();
70
		$this->testProducer = new AsynchronousMessageProducer($this->testProducerBridge, $messageConverter);
71
	}
72
73
	private function givenMockedDeffered(): Deferred
74
	{
75
		$deffered = Mockery::mock('React\Promise\Deferred');
76
		assert($deffered instanceof Deferred);
0 ignored issues
show
Bug introduced by
The class React\Promise\Deferred does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
77
78
		return $deffered;
79
	}
80
81
	private function givenTestProducerHasInjectedTestRoute()
82
	{
83
		$this->testProducer->injectRoutes(
84
			[
85
				TestAggregateCreated::class => self::TEST_PRODUCER_ROUTE_KEY,
86
			]
87
		);
88
	}
89
90
	private function givenTestMessage(): Message
91
	{
92
		return TestAggregateCreated::create(Uuid::uuid4());
93
	}
94
95
	private function whenInvokeProducerWith(Message $message, Deferred $deferred = null): void
96
	{
97
		$producer = $this->testProducer;
98
		$producer($message, $deferred);
99
	}
100
101
	protected function getPublishedEventsFromTestBridge(): array
102
	{
103
		return $this->testProducerBridge->getPublished();
104
	}
105
}
106