summaryrefslogtreecommitdiffstats
path: root/test/php/library/Icingadb/Command/Transport/CommandTransportTest.php
blob: 63a1b6689ecac2c9d3d0ddcf45313a3cad5f132a (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

namespace Tests\Icinga\Module\Icingadb\Command\Transport;

use Icinga\Module\Icingadb\Command\Object\AddCommentCommand;
use Icinga\Module\Icingadb\Command\Transport\CommandTransportException;
use Icinga\Module\Icingadb\Model\Host;
use PHPUnit\Framework\TestCase;
use Tests\Icinga\Module\Icingadb\Lib\StrikingCommandTransport;

class CommandTransportTest extends TestCase
{
    public function testFallbackHandling()
    {
        $this->expectException(CommandTransportException::class);
        $this->expectExceptionMessage('endpointB strikes!');

        (new StrikingCommandTransport())->send(
            (new AddCommentCommand())
                ->setExpireTime(42)
                ->setAuthor('GLaDOS')
                ->setComment('The cake is a lie')
                ->setObjects(new \CallbackFilterIterator(new \ArrayIterator([
                    (new Host())->setProperties(['name' => 'host1']),
                    (new Host())->setProperties(['name' => 'host2']),
                ]), function ($host) {
                    return $host->name === 'host2';
                }))
        );
    }

    public function testGeneratorsAreNotSupported()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Generators are not supported');

        (new StrikingCommandTransport())->send(
            (new AddCommentCommand())
                ->setExpireTime(42)
                ->setAuthor('GLaDOS')
                ->setComment('The cake is a lie')
                ->setObjects((function () {
                    yield (new Host())->setProperties(['name' => 'host1']);
                    yield (new Host())->setProperties(['name' => 'host2']);
                })())
        );
    }
}