Completed
Branch master (812a3e)
by Frank
04:30 queued 02:09
created

CommandResolverTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3
1
<?php
2
/**
3
 * T3Bot.
4
 *
5
 * @author Frank Nägler <[email protected]>
6
 *
7
 * @link http://www.t3bot.de
8
 * @link http://wiki.typo3.org/T3Bot
9
 */
10
namespace T3Bot\Tests\Unit\Slack;
11
12
use React\EventLoop\LoopInterface;
13
use Slack\Payload;
14
use Slack\RealTimeClient;
15
use T3Bot\Commands\BeerCommand;
16
use T3Bot\Commands\BottyCommand;
17
use T3Bot\Commands\ForgeCommand;
18
use T3Bot\Commands\ReviewCommand;
19
use T3Bot\Commands\TellCommand;
20
use T3Bot\Commands\UtilCommand;
21
use T3Bot\Slack\CommandResolver;
22
use T3Bot\Tests\Unit\BaseTestCase;
23
24
/**
25
 * Class CommandResolverTest.
26
 */
27
28
/** @noinspection LongInheritanceChainInspection */
29
class CommandResolverTest extends BaseTestCase
30
{
31
    /**
32
     * DataProvider for all commands.
33
     *
34
     * @return array
35
     */
36
    public function commandResolverDataProvider()
37
    {
38
        return [
39
            'beer:foo' => ['beer:foo', BeerCommand::class],
40
            'botty:foo' => ['botty:foo', BottyCommand::class],
41
            'forge:foo' => ['forge:foo', ForgeCommand::class],
42
            'review:foo' => ['review:foo', ReviewCommand::class],
43
            'util:foo' => ['util:foo', UtilCommand::class],
44
            'tell <@user> about' => ['tell <@user> about', TellCommand::class],
45
            'bar foo botty foo bar' => ['bar foo botty foo bar', BottyCommand::class],
46
            'no command for any message' => ['no command for any message', false],
47
        ];
48
    }
49
50
    /**
51
     * @param string $message
52
     * @param string $expectedClass
53
     *
54
     * @test
55
     * @dataProvider commandResolverDataProvider
56
     */
57
    public function ensureToResolveCorrectCommand($message, $expectedClass)
58
    {
59
        // set config value for botId
60
        $GLOBALS['config']['slack']['botId'] = 'botty';
61
62
        $loop = $this->getMock(LoopInterface::class);
63
        /** @var Payload $payload */
64
        $payload = new Payload(['text' => $message]);
65
        /** @var RealTimeClient $client */
66
        $client = $this->getMock(RealTimeClient::class, [], [$loop]);
67
        $commandResolver = new CommandResolver($payload, $client);
68
        $subject = $commandResolver->resolveCommand();
69
        if ($expectedClass === false) {
70
            static::assertFalse($subject);
71
        } else {
72
            static::assertInstanceOf($expectedClass, $subject);
73
        }
74
    }
75
}
76