8000 [Twitter][Notifier] Fix post INIT upload · symfony/symfony@8087b8b · GitHub
[go: up one dir, main page]

Skip to content

Commit 8087b8b

Browse files
committed
[Twitter][Notifier] Fix post INIT upload
1 parent f32a66f commit 8087b8b

File tree

2 files changed

+33
-12
lines changed

src/Symfony/Component/Notifier/Bridge/Twitter/Tests/TwitterTransportTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ public function testTweetImage()
6666
$transport = $this->createTransport(new MockHttpClient((function () {
6767
yield function (string $method, string $url, array $options) {
6868
$this->assertSame('POST', $method);
69-
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json?command=INIT&total_bytes=185&media_type=image%252Fgif&media_category=tweet_image', $url);
69+
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json', $url);
70+
$this->assertArrayHasKey('post', $options);
71+
$this->assertSame($options['post'], [
72+
'command' => 'INIT',
73+
'total_bytes' => 185,
74+
'media_type' => 'image%2Fgif',
75+
'media_category' => 'tweet_image'
76+
]);
7077
$this->assertArrayHasKey('authorization', $options['normalized_headers']);
7178

7279
return new MockResponse('{"media_id_string":"gif123"}');
@@ -127,15 +134,29 @@ public function testTweetVideo()
127134
$transport = $this->createTransport(new MockHttpClient((function () {
128135
yield function (string $method, string $url, array $options) {
129136
$this->assertSame('POST', $method);
130-
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json?command=INIT&total_bytes=185&media_type=image%252Fgif&media_category=tweet_video', $url);
137+
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json', $url);
138+
$this->assertArrayHasKey('post', $options);
139+
$this->assertSame($options['post'], [
140+
'command' => 'INIT',
141+
'total_bytes' => 185,
142+
'media_type' => 'image%2Fgif',
143+
'media_category' => 'tweet_video'
144+
]);
131145
$this->assertArrayHasKey('authorization', $options['normalized_headers']);
132146

133147
return new MockResponse('{"media_id_string":"gif123"}');
134148
};
135149

136150
yield function (string $method, string $url, array $options) {
137151
$this->assertSame('POST', $method);
138-
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json?command=INIT&total_bytes=185&media_type=image%252Fgif&media_category=subtitles', $url);
152+
$this->assertSame('https://upload.twitter.com/1.1/media/upload.json', $url);
153+
$this->assertArrayHasKey('post', $options);
154+
$this->assertSame($options['post'], [
155+
'command' => 'INIT',
156+
'total_bytes' => 185,
157+
'media_type' => 'image%2Fgif',
158+
'media_category' => 'subtitles'
159+
]);
139160
$this->assertArrayHasKey('authorization', $options['normalized_headers']);
140161

141162
return new MockResponse('{"media_id_string":"sub234"}');

src/Symfony/Component/Notifier/Bridge/Twitter/TwitterTransport.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,32 +160,32 @@ private function uploadMedia(array $media): array
160160
'category' => $category,
161161
'owners' => $extraOwners,
162162
]) {
163-
$query = [
163+
$post = [
164164
'command' => 'INIT',
165165
'total_bytes' => $file->getSize(),
166-
'media_type' => rawurlencode($file->getContentType()),
166+
'media_type' => $file->getContentType(),
167167
];
168168

169169
if ($category) {
170-
$query['media_category'] = $category;
170+
$post['media_category'] = $category;
171171
}
172172

173173
if ($extraOwners) {
174-
$query['additional_owners'] = implode(',', $extraOwners);
174+
$post['additional_owners'] = implode(',', $extraOwners);
175175
}
176176

177177
$pool[++$i] = $this->request('POST', '/1.1/media/upload.json', [
178-
'query' => $query,
178+
'post' => $post,
179179
'user_data' => [$i, null, 0, fopen($file->getPath(), 'r'), $alt, $subtitles],
180180
]);
181181

182182
if ($subtitles) {
183-
$query['total_bytes'] = $subtitles->getSize();
184-
$query['media_type'] = rawurlencode($subtitles->getContentType());
185-
$query['media_category'] = 'subtitles';
183+
$post['total_bytes'] = $subtitles->getSize();
184+
$post['media_type'] = $subtitles->getContentType();
185+
$post['media_category'] = 'subtitles';
186186

187187
$pool[++$i] = $this->request('POST', '/1.1/media/upload.json', [
188-
'query' => $query,
188+
'post' => $post,
189189
'user_data' => [$i, null, 0, fopen($subtitles->getPath(), 'r'), null, $subtitles],
190190
]);
191191
}

0 commit comments

Comments
 (0)
0