/
StatusesHomeTimelineTest.php
291 lines (231 loc) · 7.88 KB
/
StatusesHomeTimelineTest.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?php
namespace Acme\Command;
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Liip\TestFixturesBundle\Test\FixturesTrait;
use Symfony\Component\Console\Tester\CommandTester;
/**
* @IgnoreAnnotation("requires")
*/
class StatusesHomeTimelineTest extends StatusesBase
{
use FixturesTrait;
/** @var CommandTester */
public $commandTester;
public function setUp(): void
{
parent::setUp();
$this->application->add(new StatusesHomeTimelineTestCommand());
$command = $this->application->find('statuses:hometimelinetest');
$this->commandTester = new CommandTester($command);
}
public function testStatusesHomeTimeline()
{
$this->loadFixtures([]);
$this->commandTester->execute([
'test' => null,
]);
$display = $this->commandTester->getDisplay();
$this->assertStringContainsString('[code] => 215', $display);
$this->assertStringContainsString('[message] => Bad Authentication data.', $display);
}
public function testStatusesHomeTimelineEmpty()
{
$this->loadFixtures([]);
$this->commandTester->execute([
'test' => 'json',
]);
$this->assertStringContainsString('Number of tweets: 4', $this->commandTester->getDisplay());
}
public function testStatusesHomeTimelineNotArray()
{
$this->loadFixtures([]);
$this->commandTester->execute([
'test' => 'not_array',
]);
$this->assertStringContainsString('Something went wrong, $content is not an array.', $this->commandTester->getDisplay());
}
public function testStatusesHomeTimelineEmptyArray()
{
$this->loadFixtures([]);
$this->commandTester->execute([
'test' => 'empty_array',
]);
$display = $this->commandTester->getDisplay();
$this->assertStringContainsString('No new tweet.', $display);
}
public function testStatusesHomeTimelineWithTweets()
{
$this->loadFixtures([]);
// Disable decoration for tests on Windows
$options = [];
// http://stackoverflow.com/questions/5879043/php-script-detect-whether-running-under-linux-or-windows/5879078#5879078
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// https://tracker.phpbb.com/browse/PHPBB3-12752
$options['decorated'] = false;
}
$this->commandTester->execute(
[
'test' => 'json',
'--table' => true,
],
$options
);
$display = $this->commandTester->getDisplay();
$this->assertStringContainsString('Number of tweets: 4', $display);
// Test the headers of the table
$this->assertStringContainsString(
'| Datetime | '.
'Text excerpt | '.
'Name |',
$display
);
// Test the lines of the table
$this->assertStringContainsString(
'| 2015-02-10 21:18:00 | '.
'Bonjour Twitter ! #monpremierTweet | '.
'Asynchronous tweets |',
$display
);
$this->assertStringContainsString(
'| 2015-02-10 21:19:20 | '.
'Hello Twitter! #myfirstTweet | '.
'Asynchronous tweets |',
$display
);
$this->assertStringContainsString(
'| 2015-02-18 00:01:14 | '.
'#image #test http://t.co/rX1oieH1ug | '.
'Asynchronous tweets |',
$display
);
// Test the retweet
$this->assertStringContainsString(
'| 2015-03-03 21:18:00 | '.
'RT This is a retweet. | '.
'Asynchronous tweets |',
$display
);
// Fetch tweet from database
$em = $this
->getContainer()->get('doctrine.orm.entity_manager');
$tweets = $em
->getRepository('AsyncTweetsBundle:Tweet')
->findAll();
$this->assertSame(
5,
count($tweets)
);
}
public function testStatusesHomeTimelineWithTweetAndRetweet()
{
$this->loadFixtures([]);
// Disable decoration for tests on Windows
$options = [];
// http://stackoverflow.com/questions/5879043/php-script-detect-whether-running-under-linux-or-windows/5879078#5879078
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// https://tracker.phpbb.com/browse/PHPBB3-12752
$options['decorated'] = false;
}
$this->commandTester->execute(
[
'test' => 'json_with_retweet',
'--table' => true,
],
$options
);
$display = $this->commandTester->getDisplay();
$this->assertStringContainsString('Number of tweets: 1', $display);
// Test the headers of the table
$this->assertStringContainsString(
'| Datetime | '.
'Text excerpt | '.
'Name |',
$display
);
// Test the retweet
$this->assertStringContainsString(
'| 2015-08-22 20:20:27 | '.
'RT @travisci: Good morning! We shipped o | '.
'Asynchronous tweets |',
$display
);
// Fetch tweet from database
$em = $this
->getContainer()->get('doctrine.orm.entity_manager');
$tweet = $em
->getRepository('AsyncTweetsBundle:Tweet')
->findOneBy([
'id' => 999080449,
]);
$this->assertSame(
999080449,
$tweet->getId()
);
// Image URL was stored with HTTPS
$this->assertSame(
'https://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png',
$tweet->getUser()->getProfileImageUrlHttpOrHttps()
);
// Image URL with HTTP was not stored
$this->assertSame(
'https://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png',
$tweet->getUser()->getProfileImageUrlHttps()
);
$this->assertNull(
$tweet->getUser()->getProfileImageUrl()
);
// The number of retweet is the same for both tweets
$this->assertSame(
89,
$tweet->getRetweetCount()
);
$this->assertSame(
42,
$tweet->getFavoriteCount()
);
$retweet = $tweet->getRetweetedStatus();
$this->assertSame(
79172609,
$retweet->getId()
);
// The number of retweet is the same for both tweets
$this->assertSame(
89,
$retweet->getRetweetCount()
);
$this->assertSame(
61,
$retweet->getFavoriteCount()
);
$tweets = $em
->getRepository('AsyncTweetsBundle:Tweet')
->findAll();
$this->assertSame(
2,
count($tweets)
);
}
/**
* @requires OS Linux
*
* It returns “last tweet = 928032273747800064” on Windows (AppVeyor),
* this is equal to 928032273747795968+4096, it looks like a bug on Windows.
*/
public function testStatusesHomeTimelineWithSinceIdParameter()
{
$this->loadFixtures([
'Acme\DataFixtures\ORM\LoadTweetData',
]);
// Disable decoration for tests on Windows
$options = [];
$this->commandTester->execute(
['test' => 'empty_array'],
$options
);
$display = $this->commandTester->getDisplay();
$this->assertStringContainsString(
'last tweet = 928032273747795968',
$display
);
}
}