1 | <?php |
||
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 |