Commit fb17f3a
committed
bug #64128 [Messenger] Fix "--fetch-size" option rejecting valid values (xeno-suter)
This PR was merged into the 8.1 branch.
Discussion
----------
[Messenger] Fix "--fetch-size" option rejecting valid values
| Q | A
| ------------- | ---
| Branch? | 8.1
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | -
| License | MIT
The `--fetch-size` option, added in 8.1 (#63662), is currently unusable for its intended purpose: any value greater than 1 throws an `InvalidArgumentException`.
In `ConsumeMessagesCommand::execute()` the validation reads:
```php
if (1 < $fetchSize = (int) $input->getOption('fetch-size')) {
throw new \InvalidArgumentException(\sprintf('The "--fetch-size" option must be a positive integer, "%s" given.', ...));
}
```
The condition is inverted. It triggers on the valid range (`> 1`) and silently accepts `0` and negative values. The error message ("must be a positive integer") confirms the intent was the opposite: reject values `< 1`.
Since `Worker::run()` caps `fetch_size` with `max(1, ...)`, the bug is purely in the command layer, but it makes `messenger:consume --fetch-size=8` unusable from the CLI.
Before:
```console
$ bin/console messenger:consume async --fetch-size=8
In ConsumeMessagesCommand.php line 317:
The "--fetch-size" option must be a positive integer, "8" given.
```
After: the command runs and the receiver is asked for batches of 8.
This PR flips the comparison to `1 > $fetchSize` and adds two tests in `ConsumeMessagesCommandTest`:
- `testRunWithFetchSizeOption` runs the command with `--fetch-size=8` and asserts the receiver actually saw the fetch size (regression test; fails on 8.1 without this patch).
- `testRunWithInvalidFetchSizeOption` keeps the existing rejection behaviour for `--fetch-size=0`.
Commits
-------
69b03d0 [Messenger] Fix "--fetch-size" option rejecting valid values2 files changed
+48-1Lines changed: 48 additions & 1 deletion
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- src/Symfony/Component/Messenger
- Command
- Tests/Command
Expand file treeCollapse file tree
Open diff view settings
Collapse file
src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
312 | 312 | |
313 | 313 | |
314 | 314 | |
315 | | - |
| 315 | + |
316 | 316 | |
317 | 317 | |
318 | 318 | |
|
Collapse file
src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php+47Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
30 | 30 | |
31 | 31 | |
32 | 32 | |
| 33 | + |
33 | 34 | |
34 | 35 | |
35 | 36 | |
| ||
176 | 177 | |
177 | 178 | |
178 | 179 | |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
179 | 226 | |
180 | 227 | |
181 | 228 | |
|
0 commit comments