1 | <?php |
||
26 | class AMQPMessageIteratorTest extends TestCase |
||
27 | { |
||
28 | public function testShouldImplementMessageIteratorInterface(): void |
||
34 | |||
35 | /** |
||
36 | * @doesNotPerformAssertions |
||
37 | */ |
||
38 | public function testCouldBeConstructedWithContextAsFirstArgument(): void |
||
39 | { |
||
40 | new AMQPMessageIterator($this->createMock(AmqpConsumer::class)); |
||
41 | } |
||
42 | |||
43 | public function testShouldIterateOverThreeMessagesAndExit(): void |
||
44 | { |
||
45 | $firstMessage = new AmqpMessage('{"body": {"value": "theFirstMessageBody"}, "type": "aType", "state": "aState"}'); |
||
46 | $secondMessage = new AmqpMessage('{"body": {"value": "theSecondMessageBody"}, "type": "aType", "state": "aState"}'); |
||
47 | $thirdMessage = new AmqpMessage('{"body": {"value": "theThirdMessageBody"}, "type": "aType", "state": "aState"}'); |
||
48 | |||
49 | $consumerMock = $this->createMock(AmqpConsumer::class); |
||
50 | $consumerMock |
||
51 | ->expects($this->exactly(4)) |
||
52 | ->method('receive') |
||
53 | ->willReturnOnConsecutiveCalls($firstMessage, $secondMessage, $thirdMessage, null); |
||
54 | |||
55 | $iterator = new AMQPMessageIterator($consumerMock); |
||
56 | |||
57 | $values = []; |
||
58 | foreach ($iterator as $message) { |
||
59 | /* @var Message $message */ |
||
60 | |||
61 | $this->assertInstanceOf(Message::class, $message); |
||
62 | $this->assertInstanceOf(\Interop\Amqp\AmqpMessage::class, $message->getValue('interopMessage')); |
||
63 | |||
64 | $values[] = $message->getValue('value'); |
||
65 | } |
||
66 | |||
67 | $this->assertSame(['theFirstMessageBody', 'theSecondMessageBody', 'theThirdMessageBody'], $values); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param mixed $queueName |
||
72 | * |
||
73 | * @return AmqpConsumer|\PHPUnit_Framework_MockObject_MockObject |
||
74 | */ |
||
75 | private function createConsumerStub($queueName = null) |
||
|
|||
76 | { |
||
77 | $queue = $this->createMock(AmqpQueue::class); |
||
78 | $queue |
||
79 | ->method('getQueueName') |
||
80 | ->willReturn($queueName) |
||
81 | ; |
||
82 | |||
83 | $consumer = $this->createMock(AmqpConsumer::class); |
||
84 | $consumer |
||
85 | ->method('getQueue') |
||
86 | ->willReturn($queue) |
||
87 | ; |
||
88 | |||
89 | return $consumer; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return AMQPChannel|\PHPUnit_Framework_MockObject_MockObject|AMQPChannel |
||
94 | */ |
||
95 | private function createChannelMock() |
||
99 | } |
||
100 |