|
| 1 | +<?php |
| 2 | + |
| 3 | +/** @noinspection StaticClosureCanBeUsedInspection */ |
| 4 | +/** @noinspection PhpUnhandledExceptionInspection */ |
| 5 | + |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +/** |
| 9 | + * This file is part of the guanguans/notify. |
| 10 | + * |
| 11 | + * (c) guanguans <ityaozm@gmail.com> |
| 12 | + * |
| 13 | + * This source file is subject to the MIT license that is bundled. |
| 14 | + */ |
| 15 | + |
| 16 | +namespace Guanguans\NotifyTests\RocketChat; |
| 17 | + |
| 18 | +use Guanguans\Notify\RocketChat\Authenticator; |
| 19 | +use Guanguans\Notify\RocketChat\Client; |
| 20 | +use Guanguans\Notify\RocketChat\Messages\Message; |
| 21 | +use Psr\Http\Message\ResponseInterface; |
| 22 | + |
| 23 | +it('can send message', function (): void { |
| 24 | + $authenticator = new Authenticator('https://guanguans.rocket.chat/hooks/65bf67eb387fb98fc8bcc245/fcN2v4EkkkaLM8wzgfSeEWD9ngjgLPBhspPPFhoM78Ww2'); |
| 25 | + $client = new Client($authenticator); |
| 26 | + $message = Message::make([ |
| 27 | + 'alias' => '报警机器人', |
| 28 | + 'emoji' => ':warning:', |
| 29 | + 'text' => 'This is a text. ', |
| 30 | + // 'attachments' => [ |
| 31 | + // [ |
| 32 | + // 'title' => 'This is a title.', |
| 33 | + // 'title_link' => 'https://rocket.chat', |
| 34 | + // 'text' => 'This is a text.', |
| 35 | + // 'image_url' => 'http://www.xxx.png', |
| 36 | + // 'color' => '#764FA5', |
| 37 | + // ], |
| 38 | + // ], |
| 39 | + ]); |
| 40 | + |
| 41 | + expect($client) |
| 42 | + ->httpErrors(false) |
| 43 | + ->mock([ |
| 44 | + create_response('{"success":true}'), |
| 45 | + create_response('{"success":false,"error":"Invalid integration id or token provided."}'), |
| 46 | + ]) |
| 47 | + ->send($message)->toBeInstanceOf(ResponseInterface::class) |
| 48 | + ->send($message)->toBeInstanceOf(ResponseInterface::class); |
| 49 | +})->group(__DIR__, __FILE__); |
0 commit comments