/
TwitterOAuthDirectMessagesTest.php
67 lines (59 loc) · 1.8 KB
/
TwitterOAuthDirectMessagesTest.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
<?php
/**
* WARNING: Running tests will post and delete through the actual Twitter account when updating or saving VCR cassettes.
*/
declare(strict_types=1);
namespace Abraham\TwitterOAuth\Test;
use PHPUnit\Framework\TestCase;
use Abraham\TwitterOAuth\TwitterOAuth;
class TwitterOAuthDirectMessagesTest extends TestCase
{
/** @var TwitterOAuth */
protected $twitter;
protected function setUp(): void
{
$this->twitter = new TwitterOAuth(
CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET,
);
$this->twitter->setApiVersion('1.1');
$this->userId = explode('-', ACCESS_TOKEN)[0];
}
/**
* @vcr testPostDirectMessagesEventsNew.json
*/
public function testPostDirectMessagesEventsNew()
{
$data = [
'event' => [
'type' => 'message_create',
'message_create' => [
'target' => [
'recipient_id' => $this->userId,
],
'message_data' => [
'text' => 'Hello World!',
],
],
],
];
$result = $this->twitter->post('direct_messages/events/new', $data, [
'jsonPayload' => true,
]);
$this->assertEquals(200, $this->twitter->getLastHttpCode());
return $result;
}
/**
* @depends testPostDirectMessagesEventsNew
* @vcr testDeleteDirectMessagesEventsDestroy.json
*/
public function testDeleteDirectMessagesEventsDestroy($message)
{
$this->twitter->delete('direct_messages/events/destroy', [
'id' => $message->event->id,
]);
$this->assertEquals(204, $this->twitter->getLastHttpCode());
}
}