|
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\Commands; |
|
11
|
|
|
|
|
12
|
|
|
use Prophecy\Argument; |
|
13
|
|
|
use Slack\Payload; |
|
14
|
|
|
use Slack\RealTimeClient; |
|
15
|
|
|
use T3Bot\Commands\AbstractCommand; |
|
16
|
|
|
use T3Bot\Slack\Message; |
|
17
|
|
|
use T3Bot\Tests\Unit\BaseCommandTestCase; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class AbstractCommandTest. |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** @noinspection LongInheritanceChainInspection */ |
|
24
|
|
|
class AbstractCommandTest extends BaseCommandTestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @test |
|
28
|
|
|
*/ |
|
29
|
|
|
public function ensureSendResponseHandlingForStringResponse() |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var Payload $payload */ |
|
32
|
|
|
$payload = new Payload([ |
|
33
|
|
|
'text' => 'test message', |
|
34
|
|
|
'channel' => '#fntest', |
|
35
|
|
|
]); |
|
36
|
|
|
/** @var RealTimeClient $client */ |
|
37
|
|
|
$client = $this->prophesize(RealTimeClient::class); |
|
38
|
|
|
|
|
39
|
|
|
$client->apiCall('chat.postMessage', [ |
|
|
|
|
|
|
40
|
|
|
'unfurl_links' => false, |
|
41
|
|
|
'unfurl_media' => false, |
|
42
|
|
|
'parse' => 'none', |
|
43
|
|
|
'text' => 'this is a test string', |
|
44
|
|
|
'channel' => '#fntest', |
|
45
|
|
|
'as_user' => true, |
|
46
|
|
|
])->willReturn(true); |
|
47
|
|
|
|
|
48
|
|
|
/** @var AbstractCommand $stub */ |
|
49
|
|
|
$stub = $this->getMockForAbstractClass(AbstractCommand::class, [$payload, $client->reveal()]); |
|
|
|
|
|
|
50
|
|
|
$stub->sendResponse('this is a test string'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @test |
|
55
|
|
|
*/ |
|
56
|
|
|
public function ensureSendResponseHandlingForMessageResponse() |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var Payload $payload */ |
|
59
|
|
|
$payload = new Payload([ |
|
60
|
|
|
'text' => 'test message', |
|
61
|
|
|
'channel' => '#fntest', |
|
62
|
|
|
]); |
|
63
|
|
|
/** @var RealTimeClient $client */ |
|
64
|
|
|
$client = $this->prophesize(RealTimeClient::class); |
|
65
|
|
|
/* @noinspection PhpParamsInspection */ |
|
66
|
|
|
$client->postMessage(Argument::any())->willReturn(true); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$message = new Message(['icon_emoji' => 'foo']); |
|
69
|
|
|
$attachment = new Message\Attachment(['title' => 'Test']); |
|
70
|
|
|
$attachment->setTitle('Test'); |
|
71
|
|
|
$attachment->setTitleLink('http://www.google.de'); |
|
72
|
|
|
$attachment->setText('Test'); |
|
73
|
|
|
$attachment->setFallback('Test'); |
|
74
|
|
|
$attachment->setAuthorName('Test'); |
|
75
|
|
|
$attachment->setAuthorLink('http://www.google.de'); |
|
76
|
|
|
$attachment->setAuthorIcon('foo'); |
|
77
|
|
|
$attachment->setImageUrl('http://www.google.de'); |
|
78
|
|
|
$attachment->setThumbUrl('http://www.google.de'); |
|
79
|
|
|
|
|
80
|
|
|
$message->setText('Test'); |
|
81
|
|
|
$message->addAttachment($attachment); |
|
82
|
|
|
|
|
83
|
|
|
/** @var AbstractCommand $stub */ |
|
84
|
|
|
$stub = $this->getMockForAbstractClass(AbstractCommand::class, [$payload, $client->reveal()]); |
|
|
|
|
|
|
85
|
|
|
$stub->sendResponse($message); |
|
86
|
|
|
|
|
87
|
|
|
static::assertEquals('foo', $message->getIconEmoji()); |
|
88
|
|
|
$message->setIconEmoji('bar'); |
|
89
|
|
|
static::assertEquals('bar', $message->getIconEmoji()); |
|
90
|
|
|
|
|
91
|
|
|
$message->setAttachments([$attachment]); |
|
92
|
|
|
static::assertEquals([$attachment], $message->getAttachments()); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.