Skip to content

Commit

Permalink
Merge pull request #1100 from romm/fix/add-iterable-commands
Browse files Browse the repository at this point in the history
Allow to add commands stored in an iterable
  • Loading branch information
irazasyed authored Jan 30, 2024
2 parents 1f2fd16 + 43614e5 commit 54cf193
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Commands/CommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public function getCommands(): array
/**
* Add a list of commands.
*
* @param list<CommandInterface|class-string<CommandInterface>> $commands
* @param iterable<CommandInterface|class-string<CommandInterface>> $commands
*
* @throws TelegramSDKException
*/
public function addCommands(array $commands): self
public function addCommands(iterable $commands): self
{
foreach ($commands as $command) {
$this->addCommand($command);
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Commands/CommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
expect($result)->toHaveCount(4);
});

it('can add multiple commands contained in an iterator to the bus', function () {
$iterator = new ArrayIterator($this->commandGenerator(4)->all());

$this->bus->addCommands($iterator);
$result = $this->bus->getCommands();

expect($result)->toHaveCount(4);
});

it('throws an exception if a no class exists for the name supplied as a command')
->tap(fn () => $this->bus->addCommand('badcommand'))
->throws(TelegramSDKException::class);
Expand Down

0 comments on commit 54cf193

Please sign in to comment.