Skip to content

Commit a871b89

Browse files
committed
fix: tests
1 parent d0d9a3a commit a871b89

File tree

5 files changed

+41
-37
lines changed

5 files changed

+41
-37
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ parameters:
77
- src
88
tmpDir: build/phpstan
99
checkOctaneCompatibility: true
10-
checkModelProperties: true
11-
checkMissingIterableValueType: false
10+
checkModelProperties: true

phpunit.xml.dist

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
55
backupGlobals="false"
6-
backupStaticAttributes="false"
76
bootstrap="vendor/autoload.php"
87
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
128
processIsolation="false"
139
stopOnFailure="false"
1410
executionOrder="random"
1511
failOnWarning="true"
1612
failOnRisky="true"
1713
failOnEmptyTestSuite="true"
1814
beStrictAboutOutputDuringTests="true"
19-
verbose="true"
2015
>
2116
<testsuites>
2217
<testsuite name="palPalani Test Suite">

src/SqsQueueReaderServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private function removeBatchMessages(Job $job, string $connectionName): void
151151

152152
/**
153153
* @param array<string, mixed> $payload
154-
* @return array<int, array<string, mixed>>
154+
* @return list<list<array<string, mixed>>>
155155
*/
156156
private function extractBatchIds(array $payload): array
157157
{

tests/Pest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use palPalani\SqsQueueReader\Tests\TestCase;
6+
7+
uses(TestCase::class)->in(__DIR__);

tests/QueueTest.php

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,45 @@
22

33
declare(strict_types=1);
44

5-
namespace palPalani\SqsQueueReader\Tests;
6-
75
use palPalani\SqsQueueReader\Jobs\DispatcherJob;
86
use palPalani\SqsQueueReader\Sqs\Queue;
97

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();
1118

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);
2521

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+
});
2729

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+
];
3134

32-
$method = new \ReflectionMethod(
33-
Queue::class,
34-
'createPayload'
35-
);
35+
$job = new DispatcherJob($content);
36+
$job->setPlain(true);
3637

37-
$method->setAccessible(true);
38+
$queue = Mockery::mock(Queue::class)
39+
->makePartial()
40+
->shouldAllowMockingProtectedMethods();
3841

39-
$method->invokeArgs($queue, [$job]);
42+
$payload = $queue->createPayload($job);
4043

41-
assertTrue(true);
42-
}
43-
}
44+
expect($payload)->toBeString()
45+
->and(json_decode($payload, true))->toBe($content);
46+
});

0 commit comments

Comments
 (0)