|
2 | 2 |
|
3 | 3 | declare(strict_types=1);
|
4 | 4 |
|
5 |
| -namespace palPalani\SqsQueueReader\Tests; |
6 |
| - |
7 | 5 | use palPalani\SqsQueueReader\Jobs\DispatcherJob;
|
8 | 6 | use palPalani\SqsQueueReader\Sqs\Queue;
|
9 | 7 |
|
10 |
| -use function PHPUnit\Framework\assertTrue; |
| 8 | +it('can create payload for dispatcher job with default handler', function () { |
| 9 | + $content = [ |
| 10 | + 'test' => 'test', |
| 11 | + ]; |
| 12 | + |
| 13 | + $job = new DispatcherJob($content); |
| 14 | + |
| 15 | + $queue = Mockery::mock(Queue::class) |
| 16 | + ->makePartial() |
| 17 | + ->shouldAllowMockingProtectedMethods(); |
11 | 18 |
|
12 |
| -/** |
13 |
| - * Class QueueTest |
14 |
| - */ |
15 |
| -class QueueTest extends TestCase |
16 |
| -{ |
17 |
| - /** |
18 |
| - * @test |
19 |
| - */ |
20 |
| - public function class_named_is_derived_from_queue_name(): void |
21 |
| - { |
22 |
| - $content = [ |
23 |
| - 'test' => 'test', |
24 |
| - ]; |
| 19 | + $payload = $queue->createPayload($job); |
| 20 | + $decodedPayload = json_decode($payload, true); |
25 | 21 |
|
26 |
| - $job = new DispatcherJob($content); |
| 22 | + expect($payload)->toBeString() |
| 23 | + ->and($decodedPayload)->toBeArray() |
| 24 | + ->and($decodedPayload['job'])->toBe('App\Jobs\SqsHandler@handle') |
| 25 | + ->and($decodedPayload['data'])->toHaveKey('job') |
| 26 | + ->and($decodedPayload['data'])->toHaveKey('data') |
| 27 | + ->and($decodedPayload['data']['data'])->toBe($content); |
| 28 | +}); |
27 | 29 |
|
28 |
| - $queue = $this->getMockBuilder(Queue::class) |
29 |
| - ->disableOriginalConstructor() |
30 |
| - ->getMock(); |
| 30 | +it('can create plain payload for dispatcher job', function () { |
| 31 | + $content = [ |
| 32 | + 'test' => 'test', |
| 33 | + ]; |
31 | 34 |
|
32 |
| - $method = new \ReflectionMethod( |
33 |
| - Queue::class, |
34 |
| - 'createPayload' |
35 |
| - ); |
| 35 | + $job = new DispatcherJob($content); |
| 36 | + $job->setPlain(true); |
36 | 37 |
|
37 |
| - $method->setAccessible(true); |
| 38 | + $queue = Mockery::mock(Queue::class) |
| 39 | + ->makePartial() |
| 40 | + ->shouldAllowMockingProtectedMethods(); |
38 | 41 |
|
39 |
| - $method->invokeArgs($queue, [$job]); |
| 42 | + $payload = $queue->createPayload($job); |
40 | 43 |
|
41 |
| - assertTrue(true); |
42 |
| - } |
43 |
| -} |
| 44 | + expect($payload)->toBeString() |
| 45 | + ->and(json_decode($payload, true))->toBe($content); |
| 46 | +}); |
0 commit comments