15
15
use Symfony \Component \HttpClient \MockHttpClient ;
16
16
use Symfony \Component \Notifier \Bridge \Slack \SlackOptions ;
17
17
use Symfony \Component \Notifier \Bridge \Slack \SlackTransport ;
18
+ use Symfony \Component \Notifier \Exception \InvalidArgumentException ;
18
19
use Symfony \Component \Notifier \Exception \LogicException ;
19
20
use Symfony \Component \Notifier \Exception \TransportException ;
20
21
use Symfony \Component \Notifier \Exception \UnsupportedMessageTypeException ;
@@ -31,23 +32,31 @@ public function testToStringContainsProperties()
31
32
{
32
33
$ channel = 'test Channel ' ; // invalid channel name to test url encoding of the channel
33
34
34
- $ transport = new SlackTransport ('testToken ' , $ channel , $ this ->createMock (HttpClientInterface::class));
35
+ $ transport = new SlackTransport ('xoxb-TestToken ' , $ channel , $ this ->createMock (HttpClientInterface::class));
35
36
$ transport ->setHost ('host.test ' );
36
37
37
38
$ this ->assertSame ('slack://host.test?channel=test+Channel ' , (string ) $ transport );
38
39
}
39
40
41
+ public function testInstatiatingWithAnInvalidSlackTokenThrowsInvalidArgumentException ()
42
+ {
43
+ $ this ->expectException (InvalidArgumentException::class);
44
+ $ this ->expectExceptionMessage ('A valid Slack token needs to start with "xoxb-", "xoxp-" or "xoxa-2". See https://api.slack.com/authentication/token-types for further information. ' );
45
+
46
+ new SlackTransport ('token ' , 'testChannel ' , $ this ->createMock (HttpClientInterface::class));
47
+ }
48
+
40
49
public function testSupportsChatMessage ()
41
50
{
42
- $ transport = new SlackTransport ('testToken ' , 'testChannel ' , $ this ->createMock (HttpClientInterface::class));
51
+ $ transport = new SlackTransport ('xoxb-TestToken ' , 'testChannel ' , $ this ->createMock (HttpClientInterface::class));
43
52
44
53
$ this ->assertTrue ($ transport ->supports (new ChatMessage ('testChatMessage ' )));
45
54
$ this ->assertFalse ($ transport ->supports ($ this ->createMock (MessageInterface::class)));
46
55
}
47
56
48
57
public function testSendNonChatMessageThrowsLogicException ()
49
58
{
50
- $ transport = new SlackTransport ('testToken ' , 'testChannel ' , $ this ->createMock (HttpClientInterface::class));
59
+ $ transport = new SlackTransport ('xoxb-TestToken ' , 'testChannel ' , $ this ->createMock (HttpClientInterface::class));
51
60
52
61
$ this ->expectException (UnsupportedMessageTypeException::class);
53
62
@@ -70,7 +79,7 @@ public function testSendWithEmptyArrayResponseThrows()
70
79
return $ response ;
71
80
});
72
81
73
- $ transport = new SlackTransport ('testToken ' , 'testChannel ' , $ client );
82
+ $ transport = new SlackTransport ('xoxb-TestToken ' , 'testChannel ' , $ client );
74
83
75
84
$ transport ->send (new ChatMessage ('testMessage ' ));
76
85
}
@@ -93,14 +102,14 @@ public function testSendWithErrorResponseThrows()
93
102
return $ response ;
94
103
});
95
104
96
- $ transport = new SlackTransport ('testToken ' , 'testChannel ' , $ client );
105
+ $ transport = new SlackTransport ('xoxb-TestToken ' , 'testChannel ' , $ client );
97
106
98
107
$ transport ->send (new ChatMessage ('testMessage ' ));
99
108
}
100
109
101
110
public function testSendWithOptions ()
102
111
{
103
- $ token = 'testToken ' ;
112
+ $ token = 'xoxb-TestToken ' ;
104
113
$ channel = 'testChannel ' ;
105
114
$ message = 'testMessage ' ;
106
115
@@ -129,7 +138,7 @@ public function testSendWithOptions()
129
138
130
139
public function testSendWithNotification ()
131
140
{
132
- $ token = 'testToken ' ;
141
+ $ token = 'xoxb-TestToken ' ;
133
142
$ channel = 'testChannel ' ;
134
143
$ message = 'testMessage ' ;
135
144
@@ -172,14 +181,14 @@ public function testSendWithInvalidOptions()
172
181
return $ this ->createMock (ResponseInterface::class);
173
182
});
174
183
175
- $ transport = new SlackTransport ('testToken ' , 'testChannel ' , $ client );
184
+ $ transport = new SlackTransport ('xoxb-TestToken ' , 'testChannel ' , $ client );
176
185
177
186
$ transport ->send (new ChatMessage ('testMessage ' , $ this ->createMock (MessageOptionsInterface::class)));
178
187
}
179
188
180
189
public function testSendWith200ResponseButNotOk ()
181
190
{
182
- $ token = 'testToken ' ;
191
+ $ token = 'xoxb-TestToken ' ;
183
192
$ channel = 'testChannel ' ;
184
193
$ message = 'testMessage ' ;
185
194
0 commit comments