1
- <?php
1
+ <?php /** @noinspection PhpUnhandledExceptionInspection */
2
2
3
3
/**
4
4
* Telegram Bot API.
@@ -31,19 +31,13 @@ final class InteractionsProviderTest extends TestCase
31
31
*/
32
32
private $ credentials ;
33
33
34
- /**
35
- * {@inheritdoc}
36
- */
37
34
protected function setUp (): void
38
35
{
39
36
parent ::setUp ();
40
37
41
38
$ this ->credentials = new TelegramCredentials ('25896951:AAGB5PnXUTW-SuI4CIe742FKcTvPEwP82_o ' );
42
39
}
43
40
44
- /**
45
- * {@inheritdoc}
46
- */
47
41
protected function tearDown (): void
48
42
{
49
43
parent ::tearDown ();
@@ -55,101 +49,97 @@ protected function tearDown(): void
55
49
56
50
/**
57
51
* @test
58
- *
59
- * @return void
60
52
*/
61
53
public function unknownMethod (): void
62
54
{
63
55
Loop::run (
64
- function (): \Generator
56
+ function (): \Generator
65
57
{
66
58
/** @var \ServiceBus\TelegramBot\Interaction\Result\Fail $result */
67
59
$ result = yield (new InteractionsProvider (TestHttpClient::create ('{} ' , 404 )))->call (
68
60
new TestMethod (),
69
61
$ this ->credentials
70
62
);
71
63
72
- static ::assertInstanceOf (Fail::class, $ result );
73
- static ::assertSame ('Method TestMethod not exists ' , $ result ->errorMessage );
64
+ self ::assertInstanceOf (Fail::class, $ result );
65
+ self ::assertSame ('Method TestMethod not exists ' , $ result ->errorMessage );
74
66
}
75
67
);
76
68
}
77
69
78
70
/**
79
71
* @test
80
- *
81
- * @return void
82
72
*/
83
73
public function validationFailed (): void
84
74
{
85
75
Loop::run (
86
- function (): \Generator
76
+ function (): \Generator
87
77
{
88
78
/** @var \ServiceBus\TelegramBot\Interaction\Result\Fail $result */
89
79
$ result = yield (new InteractionsProvider (TestHttpClient::create ('{} ' , 404 )))->call (
90
80
new TestMethod ('' ),
91
81
$ this ->credentials
92
82
);
93
83
94
- static ::assertInstanceOf (Fail::class, $ result );
95
- static ::assertSame ('Validation failed ' , $ result ->errorMessage );
84
+ self ::assertInstanceOf (Fail::class, $ result );
85
+ self ::assertSame ('Validation failed ' , $ result ->errorMessage );
86
+
87
+ Loop::stop ();
96
88
}
97
89
);
98
90
}
99
91
100
92
/**
101
93
* @test
102
- *
103
- * @return void
104
94
*/
105
95
public function internalError (): void
106
96
{
107
97
Loop::run (
108
- function (): \Generator
98
+ function (): \Generator
109
99
{
110
100
/** @var \ServiceBus\TelegramBot\Interaction\Result\Fail $result */
111
101
$ result = yield (new InteractionsProvider (TestHttpClient::create ('{} ' , 500 )))->call (
112
102
new TestMethod (),
113
103
$ this ->credentials
114
104
);
115
105
116
- static ::assertInstanceOf (Fail::class, $ result );
117
- static ::assertSame ('Incorrect server response code: 500 ' , $ result ->errorMessage );
106
+ self ::assertInstanceOf (Fail::class, $ result );
107
+ self ::assertSame ('Incorrect server response code: 500 ' , $ result ->errorMessage );
108
+
109
+ Loop::stop ();
118
110
}
119
111
);
120
112
}
121
113
122
114
/**
123
115
* @test
124
- *
125
- * @return void
126
116
*/
127
117
public function incorrectResponsePayload (): void
128
118
{
129
119
Loop::run (
130
- function (): \Generator
120
+ function (): \Generator
131
121
{
132
122
/** @var \ServiceBus\TelegramBot\Interaction\Result\Fail $result */
133
123
$ result = yield (new InteractionsProvider (TestHttpClient::create ('{} ' , 200 )))->call (
134
124
new TestMethod (),
135
125
$ this ->credentials
136
126
);
137
127
138
- static ::assertInstanceOf (Fail::class, $ result );
139
- static ::assertSame ('Incorrect response payload ' , $ result ->errorMessage );
128
+ self ::assertInstanceOf (Fail::class, $ result );
129
+ self ::assertSame ('Incorrect response payload ' , $ result ->errorMessage );
130
+
131
+ Loop::stop ();
140
132
}
141
133
);
142
134
}
143
135
144
136
/**
145
137
* @test
146
- *
147
- * @return void
148
138
*/
149
139
public function successRequest (): void
150
140
{
151
141
Loop::run (
152
- function (): \Generator
142
+ function (): \Generator
153
143
{
154
144
$ expectedResponse = '{"ok":true,"result":{"id":1,"is_bot":true,"first_name":"First","last_name":"","username":"User"}} ' ;
155
145
@@ -159,55 +149,57 @@ function (): \Generator
159
149
$ this ->credentials
160
150
);
161
151
162
- static ::assertInstanceOf (Success::class, $ result );
152
+ self ::assertInstanceOf (Success::class, $ result );
163
153
164
154
/** @var User $type */
165
155
$ type = $ result ->type ;
166
156
167
- static ::assertSame ('1 ' , $ type ->id ->toString ());
157
+ self ::assertSame ('1 ' , $ type ->id ->toString ());
158
+
159
+ Loop::stop ();
168
160
}
169
161
);
170
162
}
171
163
172
164
/**
173
165
* @test
174
- *
175
- * @return void
176
166
*/
177
167
public function failedDownload (): void
178
168
{
179
169
Loop::run (
180
- function (): \Generator
170
+ function (): \Generator
181
171
{
182
172
/** @var \ServiceBus\TelegramBot\Interaction\Result\Fail $result */
183
173
$ result = yield (new InteractionsProvider (TestHttpClient::failed ('fail message ' )))->call (
184
174
DownloadFile::create ('' , '' , '' ),
185
175
$ this ->credentials
186
176
);
187
177
188
- static ::assertInstanceOf (Fail::class, $ result );
189
- static ::assertSame ('fail message ' , $ result ->errorMessage );
178
+ self ::assertInstanceOf (Fail::class, $ result );
179
+ self ::assertSame ('fail message ' , $ result ->errorMessage );
180
+
181
+ Loop::stop ();
190
182
}
191
183
);
192
184
}
193
185
194
186
/**
195
187
* @test
196
- *
197
- * @return void
198
188
*/
199
189
public function successDownload (): void
200
190
{
201
191
Loop::run (
202
- function (): \Generator
192
+ function (): \Generator
203
193
{
204
194
/** @var \ServiceBus\TelegramBot\Interaction\Result\Success $result */
205
195
$ result = yield (new InteractionsProvider (TestHttpClient::create ('' , 200 )))->call (
206
196
DownloadFile::create ('' , '' , '' ),
207
197
$ this ->credentials
208
198
);
209
199
210
- static ::assertInstanceOf (Success::class, $ result );
200
+ self ::assertInstanceOf (Success::class, $ result );
201
+
202
+ Loop::stop ();
211
203
}
212
204
);
213
205
}
0 commit comments