-
Notifications
You must be signed in to change notification settings - Fork 2
/
ChanifyTest.php
153 lines (124 loc) · 3.92 KB
/
ChanifyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php declare(strict_types=1);
/*
* This file is part of Pusher.
*
* (c) Jetsung Chan <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pusher\Tests\Channels;
use PHPUnit\Framework\TestCase;
use Pusher\Channel\Chanify;
use Pusher\Message\ChanifyMessage;
class ChanifyTest extends TestCase
{
private string $token = '';
private string $customURL = '';
private static bool $PASS = false;
public function setUp(): void
{
$token = getenv('ChanifyToken');
if ($token) {
$this->token = $token;
} else {
self::$PASS = true;
}
$customURL = getenv('ChanifyCustomURL');
if ($customURL) {
$this->customURL = $customURL;
}
}
public function skipTest(string $func, bool $skip = false): void
{
if (self::$PASS || $skip) {
$this->markTestSkipped("skip {$func}");
}
}
// 延时
public function timeSleep(int $time = 5): void
{
sleep($time);
}
public static function additionProvider(): array
{
$content = "不支持 Markdown 和 HTML。
Pusher 项目地址:https://github.com/idev-sig/pusher
";
return [
[ 'Pusher通知', $content],
[ 'Pusher通知文本,自定义 URL', $content, true],
];
}
/**
* @dataProvider additionProvider
*
* @return void
*/
public function testTextCases(string $title, string $text = '', bool $is_custom = false): void
{
$this->skipTest(__METHOD__);
$this->timeSleep(10);
$channel = new Chanify();
$channel->setToken($this->token);
if ($is_custom) {
$channel->setURL($this->customURL);
}
$message = new ChanifyMessage($title, $text);
$channel->request($message);
$this->assertTrue($channel->getStatus());
}
public function testLinkCases(): void
{
$this->skipTest(__METHOD__);
$this->timeSleep(10);
$channel = new Chanify();
$channel->setToken($this->token);
$message = new ChanifyMessage();
$message->setSound(1)
->setPriority(10)
->setLink('https://github.com/idev-sig/pusher');
$channel->request($message);
$this->assertTrue($channel->getStatus());
}
public function testActionsCases(): void
{
$this->skipTest(__METHOD__);
$this->timeSleep(10);
$channel = new Chanify();
$channel->setToken($this->token);
$message = new ChanifyMessage('Actions', '动作消息: Actions');
$message->setCopy('这个是复制的内容')
->setSound(1)
->setPriority(10)
->setInterruptionLevel('time-sensitive')
->setActions(['动作名称1|https://www.baidu.com/?1', '动作名称2|https://www.baidu.com.com/?2'])
->addAction('动作名称3|https://www.baidu.com.com/?3');
$channel->request($message);
$this->assertTrue($channel->getStatus());
}
public function testTimelineCases(): void
{
$this->skipTest(__METHOD__);
$this->timeSleep(10);
$channel = new Chanify();
$channel->setToken($this->token);
$timeline = [
'code' => 'flag',
'timestamp' => time() * 1000,
'items' => [
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
],
];
$message = new ChanifyMessage('Timeline', '时间线 Timeline 内容');
$message->setCopy('这个是复制的内容')
->setSound(1)
->setPriority(10)
->setInterruptionLevel('time-sensitive')
->setTimeline($timeline);
$channel->request($message);
$this->assertTrue($channel->getStatus());
}
}