File tree 2 files changed +58
-0
lines changed
library/Icingadb/Command/Transport
2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments