|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Icinga\Module\Icingadb\Command\Transport; |
| 4 | + |
| 5 | +use Icinga\Module\Icingadb\Command\Object\AddCommentCommand; |
| 6 | +use Icinga\Module\Icingadb\Command\Transport\CommandTransportException; |
| 7 | +use Icinga\Module\Icingadb\Model\Host; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use Tests\Icinga\Module\Icingadb\Lib\StrikingCommandTransport; |
| 10 | + |
| 11 | +class CommandTransportTest extends TestCase |
| 12 | +{ |
| 13 | + public function testFallbackHandling() |
| 14 | + { |
| 15 | + $this->expectException(CommandTransportException::class); |
| 16 | + $this->expectExceptionMessage('endpointB strikes!'); |
| 17 | + |
| 18 | + (new StrikingCommandTransport())->send( |
| 19 | + (new AddCommentCommand()) |
| 20 | + ->setExpireTime(42) |
| 21 | + ->setAuthor('GLaDOS') |
| 22 | + ->setComment('The cake is a lie') |
| 23 | + ->setObjects(new \CallbackFilterIterator(new \ArrayIterator([ |
| 24 | + (new Host())->setProperties(['name' => 'host1']), |
| 25 | + (new Host())->setProperties(['name' => 'host2']), |
| 26 | + ]), function ($host) { |
| 27 | + return $host->name === 'host2'; |
| 28 | + })) |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + public function testGeneratorsAreNotSupported() |
| 33 | + { |
| 34 | + $this->expectException(\InvalidArgumentException::class); |
| 35 | + $this->expectExceptionMessage('Generators are not supported'); |
| 36 | + |
| 37 | + (new StrikingCommandTransport())->send( |
| 38 | + (new AddCommentCommand()) |
| 39 | + ->setExpireTime(42) |
| 40 | + ->setAuthor('GLaDOS') |
| 41 | + ->setComment('The cake is a lie') |
| 42 | + ->setObjects((function () { |
| 43 | + yield (new Host())->setProperties(['name' => 'host1']); |
| 44 | + yield (new Host())->setProperties(['name' => 'host2']); |
| 45 | + })()) |
| 46 | + ); |
| 47 | + } |
| 48 | +} |
0 commit comments