-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXizhiTest.php
83 lines (69 loc) · 2.14 KB
/
XizhiTest.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
<?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\Xizhi;
use Pusher\Message\XizhiMessage;
class XizhiTest extends TestCase
{
private string $token = '';
private string $token_channel = '';
private static bool $PASS = false;
public function setUp(): void
{
$token = getenv('XizhiToken');
$token_channel = getenv('XizhiChannelToken');
if ($token && $token_channel) {
$this->token = $token;
$this->token_channel = $token_channel;
} else {
self::$PASS = true;
}
}
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
{
return [
[ 'Pusher通知单点推送', '此消息为单点推送. [项目地址](https://github.com/idev-sig/pusher)', Xizhi::TYPE_SEND ],
[ 'Pusher通知频道推送', '此消息为频道推送. [项目地址](https://github.com/idev-sig/pusher)', Xizhi::TYPE_CHANNEL],
];
}
/**
* @dataProvider additionProvider
*
* @return void
*/
public function testCases(string $title, string $content, string $type = ''): void
{
$this->skipTest(__METHOD__);
$this->timeSleep(5);
$token = $type === Xizhi::TYPE_SEND ? $this->token : $this->token_channel;
$channel = new Xizhi();
$channel->setType($type)
->setToken($token);
$message = new XizhiMessage($content, $title);
$channel->request($message);
$status = $channel->getStatus();
if (!$status) {
var_dump($channel->getErrMessage());
}
$this->assertTrue($status);
}
}