Skip to content

Commit 1e8ce1d

Browse files
committed
test: Command transmission fallback handling
refs #950
1 parent 4293461 commit 1e8ce1d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Tests\Icinga\Module\Icingadb\Lib;
4+
5+
use Icinga\Application\Config;
6+
use Icinga\Data\ConfigObject;
7+
use Icinga\Module\Icingadb\Command\IcingaApiCommand;
8+
use Icinga\Module\Icingadb\Command\Transport\ApiCommandTransport;
9+
use Icinga\Module\Icingadb\Command\Transport\CommandTransport;
10+
use Icinga\Module\Icingadb\Command\Transport\CommandTransportException;
11+
12+
class StrikingCommandTransport extends CommandTransport
13+
{
14+
public static function getConfig(): Config
15+
{
16+
return Config::fromArray(['endpoint1' => [], 'endpoint2' => []]);
17+
}
18+
19+
public static function createTransport(ConfigObject $config): ApiCommandTransport
20+
{
21+
return new class extends ApiCommandTransport {
22+
protected function sendCommand(IcingaApiCommand $command)
23+
{
24+
throw new CommandTransportException('This transport strikes!');
25+
}
26+
};
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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('This transport strikes!');
17+
18+
(new StrikingCommandTransport())->send(
19+
(new AddCommentCommand())
20+
->setExpireTime(42)
21+
->setAuthor('GLaDOS')
22+
->setComment('The cake is a lie')
23+
->setObjects((function () {
24+
foreach (['host1', 'host2'] as $host) {
25+
yield (new Host())->setProperties(['name' => $host]);
26+
}
27+
})())
28+
);
29+
}
30+
}

0 commit comments

Comments
 (0)