feat: process a specific message from the queue#106
Open
podoko wants to merge 1 commit into
Open
Conversation
Allow passing a callable or a message class-string to `process()` to handle a single matching message instead of the whole queue. Closes zenstruck#72 zenstruck#72
nikophil
requested changes
Jul 8, 2026
nikophil
left a comment
Member
There was a problem hiding this comment.
while I like the idea, I'm not sure about the implementation: we should not store the filter like any other configuration.
I think the right thing to do here is some kind of decorator:
final class TestTransport implements TransportInterface
{
public function process(int|callable|string $numberOrFilter = -1): self
{
// ...
if (\is_int($numberOrFilter)) {
$number = $numberOrFilter;
$receiver = $this;
} else {
$number = 1;
$receiver = new FilteredReceiver($this, EnvelopeFilter::normalize($numberOrFilter));
}
$worker = new Worker([$this->name => $receiver], $this->bus, $this->dispatcher);
// ...
}
public function get(): iterable
{
return $this->getMatching(null);
}
/** @internal */
public function getMatching(?callable $filter): iterable
{
// ... basically everything which is currently in `TestTransport::get()`
}
}
/** @internal */
final class FilteredReceiver implements ReceiverInterface
{
/** @param \Closure(Envelope):bool $filter */
public function __construct(
private readonly TestTransport $decorated,
private readonly \Closure $filter,
) {}
public function get(): iterable
{
return $this->decorated->getMatching($this->filter);
}
// ... other method from ReceiverInterface should defer to $decorated
}
nikophil
reviewed
Jul 8, 2026
| * | ||
| * @return callable(Envelope):bool | ||
| */ | ||
| public static function normalize(callable|string $filter): callable |
Member
There was a problem hiding this comment.
please, don't use a static method, but make this class concrete and invokable.
Then, then method TestTransport::getMatching() I am talking in the other comment will look like this:
/** @internal */
public function getMatching(?EnvelopeFilter $filter): iterable
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello, I needed the same feature as described in #72 so I tried to implement it.
This pr aims at allowing tests to process a specific message present in a queue when many are present but only the behavior of a specific one is being tested
Closes #72