|
18 | 18 |
|
19 | 19 | final class TelegramOptionsTest extends TestCase
|
20 | 20 | {
|
21 |
| - public function testAnswerCallbackQuery() |
| 21 | + /** |
| 22 | + * @dataProvider validCacheTimeDataProvider |
| 23 | + */ |
| 24 | + public function testAnswerCallbackQueryWithCacheTime(int $cacheTime) |
22 | 25 | {
|
23 | 26 | $options = new TelegramOptions();
|
24 | 27 |
|
25 |
| - $returnedOptions = $options->answerCallbackQuery('123', true, 1); |
| 28 | + $returnedOptions = $options->answerCallbackQuery('123', true, $cacheTime); |
26 | 29 |
|
27 | 30 | $this->assertSame($options, $returnedOptions);
|
28 | 31 | $this->assertEquals(
|
29 | 32 | [
|
30 | 33 | 'callback_query_id' => '123',
|
31 | 34 | 'show_alert' => true,
|
32 |
| - 'cache_time' => 1, |
| 35 | + 'cache_time' => $cacheTime, |
33 | 36 | ],
|
34 | 37 | $options->toArray(),
|
35 | 38 | );
|
36 | 39 | }
|
| 40 | + |
| 41 | + public function validCacheTimeDataProvider(): iterable |
| 42 | + { |
| 43 | + yield 'cache time equals 1' => [1]; |
| 44 | + yield 'cache time equals 2' => [2]; |
| 45 | + yield 'cache time equals 10' => [10]; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @dataProvider invalidCacheTimeDataProvider |
| 50 | + */ |
| 51 | + public function testAnswerCallbackQuery(int $cacheTime) |
| 52 | + { |
| 53 | + $options = new TelegramOptions(); |
| 54 | + |
| 55 | + $returnedOptions = $options->answerCallbackQuery('123', true, $cacheTime); |
| 56 | + |
| 57 | + $this->assertSame($options, $returnedOptions); |
| 58 | + $this->assertEquals( |
| 59 | + [ |
| 60 | + 'callback_query_id' => '123', |
| 61 | + 'show_alert' => true, |
| 62 | + ], |
| 63 | + $options->toArray(), |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + public function invalidCacheTimeDataProvider(): iterable |
| 68 | + { |
| 69 | + yield 'cache time equals 0' => [0]; |
| 70 | + yield 'cache time equals -1' => [-1]; |
| 71 | + yield 'cache time equals -10' => [-10]; |
| 72 | + } |
37 | 73 | }
|