Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartakusMd committed Nov 25, 2024
1 parent c95802a commit f3a1b6a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"symfony/process": "^6.4|^7.0",
"symfony/scheduler": "^6.4|^7.0",
"symfony/security-bundle": "^6.4|^7.0",
"symfony/serializer": "^6.4|^7.0",
"symfony/var-dumper": "^6.4|^7.0",
"zenstruck/console-test": "^1.5",
"zenstruck/foundry": "^2.2",
Expand Down
28 changes: 17 additions & 11 deletions tests/Unit/EventListener/HandleMonitorStampListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
namespace Zenstruck\Messenger\Monitor\Tests\Unit\EventListener;

use PHPUnit\Framework\TestCase;
use RuntimeException;
use stdClass;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
use Symfony\Component\Messenger\Stamp\HandledStamp;
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Zenstruck\Messenger\Monitor\EventListener\HandleMonitorStampListener;
use Zenstruck\Messenger\Monitor\History\Model\Results;
use Zenstruck\Messenger\Monitor\History\ResultNormalizer;
Expand All @@ -32,17 +36,18 @@ final class HandleMonitorStampListenerTest extends TestCase
*/
public function handles_success(): void
{
$envelope = new Envelope(new \stdClass(), [
$envelope = new Envelope(new stdClass(), [
(new MonitorStamp())->markReceived('foo'),
new HandledStamp('handler', 'return'),
]);
$storage = $this->createMock(Storage::class);
$storage->expects($this->once())->method('save')->with(
$this->isInstanceOf(Envelope::class),
$this->arrayHasKey('body'),
$this->isInstanceOf(Results::class),
);

$listener = new HandleMonitorStampListener($storage, new ResultNormalizer(__DIR__));
$listener = new HandleMonitorStampListener($storage, new ResultNormalizer(__DIR__), Serializer::create());

$listener->handleSuccess($event = new WorkerMessageHandledEvent($envelope, 'foo'));

Expand All @@ -57,27 +62,28 @@ public function handles_success_invalid(): void
$storage = $this->createMock(Storage::class);
$storage->expects($this->never())->method('save');

$listener = new HandleMonitorStampListener($storage, new ResultNormalizer(__DIR__));
$listener = new HandleMonitorStampListener($storage, new ResultNormalizer(__DIR__), Serializer::create());

$listener->handleSuccess(new WorkerMessageHandledEvent(new Envelope(new \stdClass()), 'foo'));
$listener->handleSuccess(new WorkerMessageHandledEvent(new Envelope(new \stdClass(), [new MonitorStamp()]), 'foo'));
$listener->handleSuccess(new WorkerMessageHandledEvent(new Envelope(new stdClass()), 'foo'));
$listener->handleSuccess(new WorkerMessageHandledEvent(new Envelope(new stdClass(), [new MonitorStamp()]), 'foo'));
}

/**
* @test
*/
public function handles_failure(): void
{
$envelope = new Envelope(new \stdClass(), [(new MonitorStamp())->markReceived('foo')]);
$exception = new \RuntimeException();
$envelope = new Envelope(new stdClass(), [(new MonitorStamp())->markReceived('foo')]);
$exception = new RuntimeException();
$storage = $this->createMock(Storage::class);
$storage->expects($this->once())->method('save')->with(
$this->isInstanceOf(Envelope::class),
$this->arrayHasKey('body'),
$this->isInstanceOf(Results::class),
$exception,
);

$listener = new HandleMonitorStampListener($storage, new ResultNormalizer(__DIR__));
$listener = new HandleMonitorStampListener($storage, new ResultNormalizer(__DIR__), Serializer::create());

$listener->handleFailure($event = new WorkerMessageFailedEvent($envelope, 'foo', $exception));

Expand All @@ -92,9 +98,9 @@ public function handles_failure_invalid(): void
$storage = $this->createMock(Storage::class);
$storage->expects($this->never())->method('save');

$listener = new HandleMonitorStampListener($storage, new ResultNormalizer(__DIR__));
$listener = new HandleMonitorStampListener($storage, new ResultNormalizer(__DIR__), Serializer::create());

$listener->handleFailure(new WorkerMessageFailedEvent(new Envelope(new \stdClass()), 'foo', new \RuntimeException()));
$listener->handleFailure(new WorkerMessageFailedEvent(new Envelope(new \stdClass(), [new MonitorStamp()]), 'foo', new \RuntimeException()));
$listener->handleFailure(new WorkerMessageFailedEvent(new Envelope(new stdClass()), 'foo', new RuntimeException()));
$listener->handleFailure(new WorkerMessageFailedEvent(new Envelope(new stdClass(), [new MonitorStamp()]), 'foo', new RuntimeException()));
}
}
2 changes: 1 addition & 1 deletion tests/Unit/History/Model/ProcessedMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function partial_seconds(): void
$stamp = $stamp->markFinished();

$envelope = new Envelope(new \stdClass(), [$stamp]);
$message = new class($envelope, new Results([])) extends ProcessedMessage {
$message = new class($envelope, [], new Results([])) extends ProcessedMessage {
public function id(): string|int|\Stringable|null
{
return null;
Expand Down

0 comments on commit f3a1b6a

Please sign in to comment.