summaryrefslogtreecommitdiffstats
path: root/test/php/Lib/StrikingCommandTransport.php
blob: 5e14ef9ddd613b018703494a766a66096096417d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

namespace Tests\Icinga\Module\Icingadb\Lib;

use Icinga\Application\Config;
use Icinga\Data\ConfigObject;
use Icinga\Module\Icingadb\Command\IcingaApiCommand;
use Icinga\Module\Icingadb\Command\Transport\ApiCommandTransport;
use Icinga\Module\Icingadb\Command\Transport\CommandTransport;
use Icinga\Module\Icingadb\Command\Transport\CommandTransportException;

class StrikingCommandTransport extends CommandTransport
{
    public static function getConfig(): Config
    {
        return Config::fromArray(['endpoint1' => ['host' => 'endpointA'], 'endpoint2' => ['host' => 'endpointB']]);
    }

    public static function createTransport(ConfigObject $config): ApiCommandTransport
    {
        return (new class extends ApiCommandTransport {
            protected function sendCommand(IcingaApiCommand $command)
            {
                throw new CommandTransportException(sprintf('%s strikes!', $this->getHost()));
            }
        })->setHost($config->host);
    }
}