Overview

Namespaces

  • AlexisLefebvre
    • Bundle
      • AsyncTweetsBundle
        • Command
        • Controller
        • Entity
        • Utils

Classes

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