|
10 | 10 | use Enqueue\Dbal\DbalContext; |
11 | 11 | use Enqueue\Dbal\DbalDestination; |
12 | 12 | use Enqueue\Dbal\DbalMessage; |
| 13 | +use Enqueue\Dbal\DbalProducer; |
13 | 14 | use Enqueue\Test\ClassExtensionTrait; |
14 | 15 | use Interop\Queue\InvalidMessageException; |
15 | 16 | use Interop\Queue\PsrConsumer; |
@@ -67,70 +68,58 @@ public function testRejectShouldThrowIfInstanceOfMessageIsInvalid() |
67 | 68 | $consumer->reject(new InvalidMessage()); |
68 | 69 | } |
69 | 70 |
|
70 | | - public function testRejectShouldInsertNewMessageOnRequeue() |
| 71 | + public function testShouldDoNothingOnReject() |
71 | 72 | { |
72 | | - $expectedMessage = [ |
73 | | - 'body' => 'theBody', |
74 | | - 'headers' => '[]', |
75 | | - 'properties' => '[]', |
76 | | - 'priority' => 0, |
77 | | - 'queue' => 'queue', |
78 | | - 'redelivered' => true, |
79 | | - ]; |
| 73 | + $queue = new DbalDestination('queue'); |
80 | 74 |
|
81 | | - $dbal = $this->createConnectionMock(); |
82 | | - $dbal |
83 | | - ->expects($this->once()) |
84 | | - ->method('insert') |
85 | | - ->with('tableName', $this->equalTo($expectedMessage)) |
86 | | - ->will($this->returnValue(1)) |
87 | | - ; |
| 75 | + $message = new DbalMessage(); |
| 76 | + $message->setBody('theBody'); |
88 | 77 |
|
89 | 78 | $context = $this->createContextMock(); |
90 | 79 | $context |
91 | | - ->expects($this->once()) |
92 | | - ->method('getDbalConnection') |
93 | | - ->will($this->returnValue($dbal)) |
94 | | - ; |
95 | | - $context |
96 | | - ->expects($this->once()) |
97 | | - ->method('getTableName') |
98 | | - ->will($this->returnValue('tableName')) |
| 80 | + ->expects($this->never()) |
| 81 | + ->method('createProducer') |
99 | 82 | ; |
100 | 83 |
|
101 | | - $message = new DbalMessage(); |
102 | | - $message->setBody('theBody'); |
| 84 | + $consumer = new DbalConsumer($context, $queue); |
103 | 85 |
|
104 | | - $consumer = new DbalConsumer($context, new DbalDestination('queue')); |
105 | | - $consumer->reject($message, true); |
| 86 | + $consumer->reject($message); |
106 | 87 | } |
107 | 88 |
|
108 | | - public function testRejectShouldThrowIfMessageWasNotInserted() |
| 89 | + public function testRejectShouldReSendMessageToSameQueueOnRequeue() |
109 | 90 | { |
110 | | - $dbal = $this->createConnectionMock(); |
111 | | - $dbal |
| 91 | + $queue = new DbalDestination('queue'); |
| 92 | + |
| 93 | + $message = new DbalMessage(); |
| 94 | + $message->setBody('theBody'); |
| 95 | + |
| 96 | + $producerMock = $this->createProducerMock(); |
| 97 | + $producerMock |
112 | 98 | ->expects($this->once()) |
113 | | - ->method('insert') |
114 | | - ->willReturn(0) |
| 99 | + ->method('send') |
| 100 | + ->with($this->identicalTo($queue), $this->identicalTo($message)) |
115 | 101 | ; |
116 | 102 |
|
117 | 103 | $context = $this->createContextMock(); |
118 | 104 | $context |
119 | 105 | ->expects($this->once()) |
120 | | - ->method('getDbalConnection') |
121 | | - ->will($this->returnValue($dbal)) |
| 106 | + ->method('createProducer') |
| 107 | + ->will($this->returnValue($producerMock)) |
122 | 108 | ; |
123 | 109 |
|
124 | | - $message = new DbalMessage(); |
125 | | - $message->setBody('theBody'); |
126 | | - |
127 | | - $this->expectException(\LogicException::class); |
128 | | - $this->expectExceptionMessage('Expected record was inserted but it is not. message:'); |
| 110 | + $consumer = new DbalConsumer($context, $queue); |
129 | 111 |
|
130 | | - $consumer = new DbalConsumer($context, new DbalDestination('queue')); |
131 | 112 | $consumer->reject($message, true); |
132 | 113 | } |
133 | 114 |
|
| 115 | + /** |
| 116 | + * @return DbalProducer|\PHPUnit_Framework_MockObject_MockObject |
| 117 | + */ |
| 118 | + private function createProducerMock() |
| 119 | + { |
| 120 | + return $this->createMock(DbalProducer::class); |
| 121 | + } |
| 122 | + |
134 | 123 | /** |
135 | 124 | * @return \PHPUnit_Framework_MockObject_MockObject|Connection |
136 | 125 | */ |
|
0 commit comments