-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1462 from brefphp/partial-failures
- Loading branch information
Showing
4 changed files
with
62 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Bref\Test\Event\Sqs; | ||
|
||
use Bref\Context\Context; | ||
use Bref\Event\Sqs\SqsEvent; | ||
use Bref\Event\Sqs\SqsHandler; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SqsHandlerTest extends TestCase | ||
{ | ||
public function test partial failure() | ||
{ | ||
$event = json_decode(file_get_contents(__DIR__ . '/handler.json'), true, 512, JSON_THROW_ON_ERROR); | ||
|
||
// Fails half the messages | ||
$handler = new class extends SqsHandler { | ||
public function handleSqs(SqsEvent $event, Context $context): void | ||
{ | ||
foreach ($event->getRecords() as $record) { | ||
$body = json_decode($record->getBody(), true); | ||
|
||
$isEven = $body['count'] % 2 === 0; | ||
if ($isEven) { | ||
$this->markAsFailed($record); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
$result = $handler->handle($event, Context::fake()); | ||
|
||
self::assertSame($result, [ | ||
'batchItemFailures' => [ | ||
['itemIdentifier' => '2'], | ||
['itemIdentifier' => '4'], | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* @see https://github.com/brefphp/bref/issues/1461 | ||
*/ | ||
public function test response when no failure() | ||
{ | ||
$event = json_decode(file_get_contents(__DIR__ . '/handler.json'), true, 512, JSON_THROW_ON_ERROR); | ||
|
||
$handler = new class extends SqsHandler { | ||
public function handleSqs(SqsEvent $event, Context $context): void | ||
{ | ||
// success (does not call $this->markAsFailed()) | ||
} | ||
}; | ||
|
||
$result = $handler->handle($event, Context::fake()); | ||
|
||
// The response should be null, not an empty array | ||
self::assertNull($result); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.