1313
1414namespace JoliCode \Slack \Tests ;
1515
16- use JoliCode \Slack \Api \Model \ApiTestGetResponse200 ;
1716use JoliCode \Slack \Api \Model \ConversationsHistoryGetResponse200 ;
1817use JoliCode \Slack \Api \Model \ConversationsListGetResponse200 ;
1918use JoliCode \Slack \Api \Model \ObjsFile ;
2019use JoliCode \Slack \Api \Model \SearchMessagesGetResponse200 ;
2120use JoliCode \Slack \Api \Model \UsersListGetResponse200 ;
22- use JoliCode \Slack \ClientFactory ;
2321use JoliCode \Slack \Exception \SlackErrorResponse ;
24- use PHPUnit \Framework \TestCase ;
2522
26- class ReadingTest extends TestCase
23+ class ReadingTest extends SlackTokenDependentTest
2724{
28- protected function setUp (): void
29- {
30- if (!\array_key_exists ('SLACK_TOKEN ' , $ _SERVER )) {
31- $ this ->markTestSkipped ('SLACK_TOKEN env var not present, skip the test. ' );
32- }
33- }
34-
35- public function testItWorksOnTestSuccess ()
36- {
37- $ client = ClientFactory::create ('' );
38- $ response = $ client ->apiTest ();
39-
40- self ::assertInstanceOf (ApiTestGetResponse200::class, $ response );
41- self ::assertTrue ($ response ->getOk ());
42- }
43-
44- public function testItThrowsExceptionOnTestError ()
45- {
46- $ client = ClientFactory::create ('' );
47-
48- self ::expectException (SlackErrorResponse::class);
49- self ::expectExceptionMessage ('Slack returned error code "yolo" ' );
50-
51- $ client ->apiTest ([
52- 'error ' => 'yolo ' ,
53- ]);
54- }
55-
5625 public function testItWorksOnUserListWithCorrectToken ()
5726 {
58- $ client = ClientFactory:: create ( $ _SERVER [ ' SLACK_TOKEN ' ] );
27+ $ client = $ this -> createClient ( );
5928
6029 $ response = $ client ->usersList ();
6130
@@ -67,7 +36,7 @@ public function testItWorksOnUserListWithCorrectToken()
6736
6837 public function testItThrowsExceptionOnUserListWithoutToken ()
6938 {
70- $ client = ClientFactory:: create ('' );
39+ $ client = $ this -> createClient ('' );
7140
7241 self ::expectException (SlackErrorResponse::class);
7342 self ::expectExceptionMessage ('Slack returned error code "not_authed" ' );
@@ -77,7 +46,7 @@ public function testItThrowsExceptionOnUserListWithoutToken()
7746
7847 public function testItCanReadAConversationHistory ()
7948 {
80- $ client = ClientFactory:: create ( $ _SERVER [ ' SLACK_TOKEN ' ] );
49+ $ client = $ this -> createClient ( );
8150
8251 $ results = $ client ->conversationsHistory ([
8352 'channel ' => $ _SERVER ['SLACK_TEST_CHANNEL ' ],
@@ -105,7 +74,7 @@ public function testItCanReadAConversationHistory()
10574
10675 public function testItCanGetTheImList ()
10776 {
108- $ client = ClientFactory:: create ( $ _SERVER [ ' SLACK_TOKEN ' ] );
77+ $ client = $ this -> createClient ( );
10978
11079 $ results = $ client ->conversationsList (['types ' => 'im ' ]);
11180
@@ -115,7 +84,7 @@ public function testItCanGetTheImList()
11584
11685 public function testItCanReadConversationsAndHydrateThem ()
11786 {
118- $ client = ClientFactory:: create ( $ _SERVER [ ' SLACK_TOKEN ' ] );
87+ $ client = $ this -> createClient ( );
11988
12089 /** @var ConversationsListGetResponse200 $response */
12190 $ response = $ client ->conversationsList ([
@@ -133,7 +102,7 @@ public function testItCanReadConversationsAndHydrateThem()
133102
134103 public function testItCanSearchMessages ()
135104 {
136- $ client = ClientFactory:: create ( $ _SERVER [ ' SLACK_TOKEN ' ] );
105+ $ client = $ this -> createClient ( );
137106
138107 /** @var SearchMessagesGetResponse200 $results */
139108 $ results = $ client ->searchMessages ([
0 commit comments