1 | <?php |
||
8 | class StatusesHomeTimelineTestCommand extends StatusesHomeTimelineCommand |
||
9 | { |
||
10 | 7 | protected function configure() |
|
11 | { |
||
12 | 7 | parent::configure(); |
|
13 | |||
14 | 7 | $this |
|
15 | 7 | ->setName('statuses:hometimelinetest') |
|
16 | 7 | ->setDescription('Fetch home timeline test') |
|
17 | 7 | ->addArgument( |
|
18 | 7 | 'test', |
|
19 | 7 | InputArgument::OPTIONAL, |
|
20 | 'Return data for tests' |
||
21 | 7 | ) |
|
22 | ; |
||
23 | 7 | } |
|
24 | |||
25 | /** |
||
26 | * Read tweet(s) from a JSON file |
||
27 | * |
||
28 | * @param string $filename |
||
29 | * @return array |
||
30 | */ |
||
31 | 3 | protected function getTestContent($filename) |
|
32 | { |
||
33 | /** @see https://insight.sensiolabs.com/what-we-analyse/symfony.dependency_injection.use_dir_file_constant */ |
||
34 | 3 | return(json_decode(file_get_contents( |
|
35 | 3 | $this->container->get('kernel')->locateResource( |
|
36 | '@AsyncTweetsBundle/Tests/Command/data/'.$filename |
||
37 | 3 | ) |
|
38 | 3 | ))); |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param InputInterface $input |
||
43 | */ |
||
44 | 7 | protected function getContent(InputInterface $input) |
|
45 | { |
||
46 | 7 | switch($input->getArgument('test')) { |
|
47 | 7 | case 'json': |
|
48 | 2 | return($this->getTestContent( |
|
49 | 2 | 'tweets_32_bits.json')); |
|
50 | 5 | case 'json_with_retweet': |
|
51 | 1 | return($this->getTestContent( |
|
52 | 1 | 'tweet_with_retweet.json')); |
|
53 | 4 | case 'not_array': |
|
54 | // Return null instead of JSON |
||
55 | 1 | return(null); |
|
56 | 3 | case 'empty_array': |
|
57 | // Return an empty array instead of JSON |
||
58 | 2 | return(array()); |
|
59 | 1 | default: |
|
60 | // Normal behaviour |
||
61 | 1 | return(parent::getContent($input)); |
|
62 | 1 | } |
|
63 | } |
||
64 | } |
||
65 |