|
8 | 8 | use PhpAmqpLib\Exception\AMQPProtocolChannelException;
|
9 | 9 | use RuntimeException;
|
10 | 10 | use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob;
|
| 11 | +use VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Mocks\TestEncryptedJob; |
11 | 12 | use VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Mocks\TestJob;
|
12 | 13 | use VladimirYuldashev\LaravelQueueRabbitMQ\Tests\TestCase as BaseTestCase;
|
13 | 14 |
|
@@ -194,6 +195,103 @@ public function testBulk(): void
|
194 | 195 | $this->assertSame($count, Queue::size());
|
195 | 196 | }
|
196 | 197 |
|
| 198 | + public function testPushEncrypted(): void |
| 199 | + { |
| 200 | + Queue::push(new TestEncryptedJob()); |
| 201 | + |
| 202 | + sleep(1); |
| 203 | + |
| 204 | + $this->assertSame(1, Queue::size()); |
| 205 | + $this->assertNotNull($job = Queue::pop()); |
| 206 | + $this->assertSame(1, $job->attempts()); |
| 207 | + $this->assertInstanceOf(RabbitMQJob::class, $job); |
| 208 | + $this->assertSame(TestEncryptedJob::class, $job->resolveName()); |
| 209 | + $this->assertNotNull($job->getJobId()); |
| 210 | + |
| 211 | + $payload = $job->payload(); |
| 212 | + |
| 213 | + $this->assertSame(TestEncryptedJob::class, $payload['displayName']); |
| 214 | + $this->assertSame('Illuminate\Queue\CallQueuedHandler@call', $payload['job']); |
| 215 | + $this->assertNull($payload['maxTries']); |
| 216 | + $this->assertNull($payload['backoff']); |
| 217 | + $this->assertNull($payload['timeout']); |
| 218 | + $this->assertNull($payload['retryUntil']); |
| 219 | + $this->assertSame($job->getJobId(), $payload['id']); |
| 220 | + |
| 221 | + $job->delete(); |
| 222 | + $this->assertSame(0, Queue::size()); |
| 223 | + } |
| 224 | + |
| 225 | + public function testPushEncryptedAfterCommit(): void |
| 226 | + { |
| 227 | + $transaction = new DatabaseTransactionsManager; |
| 228 | + |
| 229 | + $this->app->singleton('db.transactions', function ($app) use ($transaction) { |
| 230 | + $transaction->begin('FakeDBConnection', 1); |
| 231 | + |
| 232 | + return $transaction; |
| 233 | + }); |
| 234 | + |
| 235 | + TestEncryptedJob::dispatch()->afterCommit(); |
| 236 | + |
| 237 | + sleep(1); |
| 238 | + $this->assertSame(0, Queue::size()); |
| 239 | + $this->assertNull(Queue::pop()); |
| 240 | + |
| 241 | + $transaction->commit('FakeDBConnection', 1, 0); |
| 242 | + |
| 243 | + sleep(1); |
| 244 | + |
| 245 | + $this->assertSame(1, Queue::size()); |
| 246 | + $this->assertNotNull($job = Queue::pop()); |
| 247 | + |
| 248 | + $job->delete(); |
| 249 | + $this->assertSame(0, Queue::size()); |
| 250 | + } |
| 251 | + |
| 252 | + public function testEncryptedLater(): void |
| 253 | + { |
| 254 | + Queue::later(3, new TestEncryptedJob()); |
| 255 | + |
| 256 | + sleep(1); |
| 257 | + |
| 258 | + $this->assertSame(0, Queue::size()); |
| 259 | + $this->assertNull(Queue::pop()); |
| 260 | + |
| 261 | + sleep(3); |
| 262 | + |
| 263 | + $this->assertSame(1, Queue::size()); |
| 264 | + $this->assertNotNull($job = Queue::pop()); |
| 265 | + |
| 266 | + $this->assertInstanceOf(RabbitMQJob::class, $job); |
| 267 | + |
| 268 | + $body = json_decode($job->getRawBody(), true); |
| 269 | + |
| 270 | + $this->assertSame(TestEncryptedJob::class, $body['displayName']); |
| 271 | + $this->assertSame('Illuminate\Queue\CallQueuedHandler@call', $body['job']); |
| 272 | + $this->assertSame(TestEncryptedJob::class, $body['data']['commandName']); |
| 273 | + $this->assertNotNull($job->getJobId()); |
| 274 | + |
| 275 | + $job->delete(); |
| 276 | + $this->assertSame(0, Queue::size()); |
| 277 | + } |
| 278 | + |
| 279 | + public function testEncryptedBulk(): void |
| 280 | + { |
| 281 | + $count = 100; |
| 282 | + $jobs = []; |
| 283 | + |
| 284 | + for ($i = 0; $i < $count; $i++) { |
| 285 | + $jobs[$i] = new TestEncryptedJob($i); |
| 286 | + } |
| 287 | + |
| 288 | + Queue::bulk($jobs); |
| 289 | + |
| 290 | + sleep(1); |
| 291 | + |
| 292 | + $this->assertSame($count, Queue::size()); |
| 293 | + } |
| 294 | + |
197 | 295 | public function testReleaseRaw(): void
|
198 | 296 | {
|
199 | 297 | Queue::pushRaw($payload = Str::random());
|
|
0 commit comments