Completed
Push — master ( 36fe12...410534 )
by Alexis
06:25
created

StatusesHomeTimelineTestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.4286
cc 1
eloc 9
nc 1
nop 0
crap 1
1
<?php
2
3
namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Input\InputArgument;
7
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