-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: have
TestTransport
additional receiver interfaces
- `ListableReceiverInterface` - `MessageCountAwareInterface`
- Loading branch information
Showing
3 changed files
with
69 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,19 @@ | |
use Symfony\Component\Messenger\MessageBusInterface; | ||
use Symfony\Component\Messenger\Stamp\DelayStamp; | ||
use Symfony\Component\Messenger\Stamp\RedeliveryStamp; | ||
use Symfony\Component\Messenger\Transport\Receiver\ListableReceiverInterface; | ||
use Symfony\Component\Messenger\Transport\Receiver\MessageCountAwareInterface; | ||
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; | ||
use Symfony\Component\Messenger\Transport\TransportInterface; | ||
use Symfony\Component\Messenger\Worker; | ||
use Zenstruck\Assert; | ||
use Zenstruck\Messenger\Test\Stamp\AvailableAtStamp; | ||
use Zenstruck\Messenger\Test\TestEnvelope; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class TestTransport implements TransportInterface | ||
final class TestTransport implements TransportInterface, ListableReceiverInterface, MessageCountAwareInterface | ||
{ | ||
private const DEFAULT_OPTIONS = [ | ||
'intercept' => true, | ||
|
@@ -279,6 +282,24 @@ public function reject(Envelope $envelope): void | |
$this->collectMessage(self::$rejected, $envelope); | ||
} | ||
|
||
public function all(?int $limit = null): iterable | ||
{ | ||
return \array_map( | ||
fn(TestEnvelope $envelope) => $envelope->envelope, | ||
\array_slice($this->queue()->all(), 0, $limit), | ||
); | ||
} | ||
|
||
public function find(mixed $id): ?Envelope | ||
{ | ||
throw new \BadMethodCallException('Not supported.'); | ||
} | ||
|
||
public function getMessageCount(): int | ||
{ | ||
return $this->queue()->count(); | ||
} | ||
|
||
/** | ||
* @param Envelope|object|array{headers?:mixed[],body:string} $what object: will be wrapped in envelope | ||
* array: will be decoded into envelope | ||
|
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