Skip to content

Commit

Permalink
test: prove HandlerArgumentsStamp is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Sep 12, 2024
1 parent 60bc93d commit a90d501
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [8.1, 8.2, 8.3]
php: [8.3]
deps: [highest]
symfony: [5.4.*, 6.3.*, 6.4.*, 7.0.*]
symfony: [ 7.1.* ]
include:
- php: 8.1
deps: lowest
Expand All @@ -23,7 +23,7 @@ jobs:
- php: 8.1
symfony: 7.0.*
steps:
- uses: zenstruck/.github@php-test-symfony
- uses: zenstruck/.github/actions/php-test-symfony@main
with:
php: ${{ matrix.php }}
symfony: ${{ matrix.symfony }}
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/Messenger/MessageA.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ final class MessageA
{
public bool $fail;

public string|null $additionalArgument = null;

public function __construct(bool $fail = false)
{
$this->fail = $fail;
Expand Down
4 changes: 3 additions & 1 deletion tests/Fixture/Messenger/MessageAHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ final class MessageAHandler
/** @var MessageA[] */
public array $messages = [];

public function __invoke(MessageA $message): void
public function __invoke(MessageA $message, string|null $additionalArgument = null): void
{
if ($message->fail) {
throw new \RuntimeException('handling failed...');
}

$message->additionalArgument = $additionalArgument;

$this->messages[] = $message;
}
}
22 changes: 22 additions & 0 deletions tests/InteractsWithMessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\DelayStamp;
use Symfony\Component\Messenger\Stamp\HandlerArgumentsStamp;
use Symfony\Component\Messenger\Stamp\SerializerStamp;
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Zenstruck\Assert;
Expand Down Expand Up @@ -903,6 +904,27 @@ public function can_enable_retries_without_delay_stamp(): void
$this->transport('async')->process()->rejected()->assertContains(MessageA::class, 4);
}

/**
* @test
*/
public function can_add_handler_argument(): void
{
if (!class_exists(HandlerArgumentsStamp::class)) {
self::markTestSkipped('Needs symfony/messenger 6.2.');
}

self::bootKernel();

self::getContainer()->get(MessageBusInterface::class)->dispatch(
$message = new MessageA(),
[new HandlerArgumentsStamp(['someAdditionalArgument'])]
);

$this->transport('async')->process()->acknowledged()->assertContains(MessageA::class, 1);

self::assertSame('someAdditionalArgument', $message->additionalArgument);
}

/**
* @test
*/
Expand Down

0 comments on commit a90d501

Please sign in to comment.