Skip to content

Commit

Permalink
Merge 631b9fa into efa0669
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Nov 17, 2018
2 parents efa0669 + 631b9fa commit f34864c
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 95 deletions.
122 changes: 94 additions & 28 deletions .travis.yml
@@ -1,8 +1,12 @@
dist: trusty
sudo: false

sudo: required

language: php

services:
- docker

git:
depth: 5

Expand All @@ -12,30 +16,92 @@ cache:

php:
- 7.1
- 7.2

env:
- SYMFONY_VERSION="3.4.*"
- SYMFONY_VERSION="~4.1"

# Only send code coverage to Code Climate for the current versions of PHP and Symfony LTS
# https://github.com/doctrine/doctrine2/blob/3570f4a49afc7e98fed71e0596dded6a39d4fd7b/.travis.yml#L16
before_install:
- if echo "$TRAVIS_COMMIT_MESSAGE" | grep -F -q "[skip travis]" ; then echo "[skip travis] has been found, exiting" && exit 0 ; else echo "[skip travis] has not been found, continuing" ; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' && $SYMFONY_VERSION = '3.4.*' ]]; then DEPENDENCY="codeclimate/php-test-reporter:~0.3 satooshi/php-coveralls:~1.0"; PHPUNIT_FLAGS="--coverage-clover ./build/logs/clover.xml"; else DEPENDENCY=""; PHPUNIT_FLAGS=""; fi
- if [[ $PHPUNIT_FLAGS = "" ]]; then phpenv config-rm xdebug.ini; fi

install:
- if [[ $SYMFONY_VERSION = '3.4.*' ]]; then composer require symfony/lts:v3 --no-update; fi
- composer require symfony/config:${SYMFONY_VERSION} symfony/form:${SYMFONY_VERSION} symfony/framework-bundle:${SYMFONY_VERSION} symfony/templating:${SYMFONY_VERSION} symfony/security-csrf:${SYMFONY_VERSION} symfony/var-dumper:${SYMFONY_VERSION} $DEPENDENCY --no-update
- composer install --no-interaction --profile --no-progress

script:
- php ./vendor/bin/phpspec run --format=pretty
- php ./vendor/bin/phpunit $PHPUNIT_FLAGS
- php ./vendor/bin/behat

# Only send code coverage if it has been generated
after_success:
- if [[ $PHPUNIT_FLAGS != "" ]]; then php ./vendor/bin/test-reporter; fi
- if [[ $PHPUNIT_FLAGS != "" ]]; then travis_retry php vendor/bin/coveralls -v --config .coveralls.yml; fi

stages:
- analysis
- test

jobs:
include:
- stage: analysis
name: "php-cs-fixer"
before_install:
- docker pull jakzal/phpqa
script:
- docker run --volume $PWD:/app --workdir /app jakzal/phpqa:alpine php-cs-fixer fix src/ --dry-run
- name: "phpstan"
install:
- composer install --no-interaction --profile --no-progress
script:
- docker run --volume $PWD:/app --workdir /app jakzal/phpqa:alpine phpstan analyse --level 6 src/ --no-progress

- stage: test
name: "PHP 7.1 / Symfony 3.4"
php: 7.1
env:
- SYMFONY_VERSION="3.4.*"
before_install:
- phpenv config-rm xdebug.ini

install:
- composer require symfony/lts:v3 --no-update
- composer require symfony/config:${SYMFONY_VERSION} symfony/form:${SYMFONY_VERSION} symfony/framework-bundle:${SYMFONY_VERSION} symfony/templating:${SYMFONY_VERSION} symfony/security-csrf:${SYMFONY_VERSION} symfony/var-dumper:${SYMFONY_VERSION} --no-update
- composer install --no-interaction --profile --no-progress

script:
- php ./vendor/bin/phpspec run --format=pretty
- php ./vendor/bin/phpunit $PHPUNIT_FLAGS
- php ./vendor/bin/behat
- name: "PHP 7.2 / Symfony 3.4 / Code coverage"
php: 7.2
env:
- SYMFONY_VERSION="3.4.*"
# Only send code coverage to Code Climate for the current versions of PHP and Symfony LTS
# https://github.com/doctrine/doctrine2/blob/3570f4a49afc7e98fed71e0596dded6a39d4fd7b/.travis.yml#L16
before_install:
- DEPENDENCY="codeclimate/php-test-reporter:~0.3 satooshi/php-coveralls:~1.0"

install:
- composer require symfony/lts:v3 --no-update
- composer require symfony/config:${SYMFONY_VERSION} symfony/form:${SYMFONY_VERSION} symfony/framework-bundle:${SYMFONY_VERSION} symfony/templating:${SYMFONY_VERSION} symfony/security-csrf:${SYMFONY_VERSION} symfony/var-dumper:${SYMFONY_VERSION} $DEPENDENCY --no-update
- composer install --no-interaction --profile --no-progress

script:
- php ./vendor/bin/phpspec run --format=pretty
- php ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml
- php ./vendor/bin/behat

after_success:
- php ./vendor/bin/test-reporter
- travis_retry php vendor/bin/coveralls -v --config .coveralls.yml
- name: "PHP 7.1 / Symfony 4"
php: 7.1
env:
- SYMFONY_VERSION="^4.1"
before_install:
- phpenv config-rm xdebug.ini

install:
- composer require symfony/config:${SYMFONY_VERSION} symfony/form:${SYMFONY_VERSION} symfony/framework-bundle:${SYMFONY_VERSION} symfony/templating:${SYMFONY_VERSION} symfony/security-csrf:${SYMFONY_VERSION} symfony/var-dumper:${SYMFONY_VERSION} --no-update
- composer install --no-interaction --profile --no-progress

script:
- php ./vendor/bin/phpspec run --format=pretty
- php ./vendor/bin/phpunit $PHPUNIT_FLAGS
- php ./vendor/bin/behat
- name: "PHP 7.2 / Symfony 4"
php: 7.2
env:
- SYMFONY_VERSION="^4.1"
before_install:
- phpenv config-rm xdebug.ini

install:
- composer require symfony/config:${SYMFONY_VERSION} symfony/form:${SYMFONY_VERSION} symfony/framework-bundle:${SYMFONY_VERSION} symfony/templating:${SYMFONY_VERSION} symfony/security-csrf:${SYMFONY_VERSION} symfony/var-dumper:${SYMFONY_VERSION} --no-update
- composer install --no-interaction --profile --no-progress

script:
- php ./vendor/bin/phpspec run --format=pretty
- php ./vendor/bin/phpunit $PHPUNIT_FLAGS
- php ./vendor/bin/behat

6 changes: 4 additions & 2 deletions src/Command/BaseCommand.php
Expand Up @@ -2,6 +2,7 @@

namespace AlexisLefebvre\Bundle\AsyncTweetsBundle\Command;

use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -27,7 +28,8 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->container = $this->getContainer();

// This loads Doctrine, you can load your own services as well
$this->em = $this->container->get('doctrine')
->getManager();
/** @var ManagerRegistry $doctrine */
$doctrine = $this->container->get('doctrine');
$this->em = $doctrine->getManager();
}
}
45 changes: 29 additions & 16 deletions src/Command/StatusesHomeTimelineCommand.php
Expand Up @@ -30,8 +30,12 @@ protected function configure()
->setName('statuses:hometimeline')
->setDescription('Fetch home timeline')
// http://symfony.com/doc/2.3/cookbook/console/console_command.html#automatically-registering-commands
->addOption('table', null, InputOption::VALUE_NONE,
'Display a table with tweets');
->addOption(
'table',
null,
InputOption::VALUE_NONE,
'Display a table with tweets'
);
}

/**
Expand Down Expand Up @@ -107,9 +111,10 @@ protected function getContent(InputInterface $input)
* @param OutputInterface $output
* @param null|object $content
*/
protected function displayContentNotArrayError(OutputInterface $output,
$content)
{
protected function displayContentNotArrayError(
OutputInterface $output,
$content
) {
$formatter = $this->getHelper('formatter');

$errorMessages = ['Error!', 'Something went wrong, $content is not an array.'];
Expand All @@ -124,9 +129,12 @@ protected function displayContentNotArrayError(OutputInterface $output,
* @param array $content
* @param int $numberOfTweets
*/
protected function addAndDisplayTweets(InputInterface $input,
OutputInterface $output, $content, $numberOfTweets)
{
protected function addAndDisplayTweets(
InputInterface $input,
OutputInterface $output,
$content,
$numberOfTweets
) {
$output->writeln('<comment>Number of tweets: '.$numberOfTweets.'</comment>');

// Iterate through $content in order to add the oldest tweet first,
Expand All @@ -150,9 +158,10 @@ protected function addAndDisplayTweets(InputInterface $input,
* @param OutputInterface $output
* @param int $numberOfTweets
*/
protected function setProgressBar(OutputInterface $output,
$numberOfTweets)
{
protected function setProgressBar(
OutputInterface $output,
$numberOfTweets
) {
$this->progress = new ProgressBar($output, $numberOfTweets);
$this->progress->setBarCharacter('<comment>=</comment>');
$this->progress->start();
Expand All @@ -162,9 +171,10 @@ protected function setProgressBar(OutputInterface $output,
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function setTable(InputInterface $input,
OutputInterface $output)
{
protected function setTable(
InputInterface $input,
OutputInterface $output
) {
$this->displayTable = $input->getOption('table');

// Display
Expand All @@ -180,8 +190,11 @@ protected function setTable(InputInterface $input,
*/
protected function iterateTweets($tweets)
{
$persistTweet = new PersistTweet($this->em, $this->displayTable,
$this->table);
$persistTweet = new PersistTweet(
$this->em,
$this->displayTable,
$this->table
);

foreach ($tweets as $tweetTmp) {
$persistTweet->addTweet($tweetTmp, true);
Expand Down
34 changes: 24 additions & 10 deletions src/Command/StatusesReadCommand.php
Expand Up @@ -29,13 +29,17 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var int|null $page */
$page = $input->getArgument('page');

if ($page < 1) {
$page = 1;
}

$output->writeln('Current page: <comment>'.$page.'</comment>');
$output->writeln(sprintf(
'Current page: <comment>%d</comment>',
$page
));

// Get the tweets
$tweets = $this->em
Expand All @@ -55,18 +59,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @param OutputInterface $output
* @param array $tweets
*/
protected function displayTweets(OutputInterface $output,
$tweets)
{
protected function displayTweets(
OutputInterface $output,
$tweets
) {
$this->setTable($output);

foreach ($tweets as $tweet) {
$this->table->addRows([
$this->table->addRows(
[
[
$this->formatCell('info',
$tweet->getUser()->getName(), 13),
$this->formatCell('comment',
$tweet->getText(), 40),
$this->formatCell(
'info',
$tweet->getUser()->getName(),
13
),
$this->formatCell(
'comment',
$tweet->getText(),
40
),
$tweet->getCreatedAt()->format('Y-m-d H:i'),
],
// empty row between tweets
Expand Down Expand Up @@ -101,7 +113,9 @@ protected function formatCell($tag, $content, $length)
{
return '<'.$tag.'>'.
// Close and reopen the tag before each new line
str_replace("\n", '</'.$tag.">\n<".$tag.'>',
str_replace(
"\n",
'</'.$tag.">\n<".$tag.'>',
wordwrap($content, $length, "\n")
).
'</'.$tag.'>';
Expand Down
11 changes: 8 additions & 3 deletions src/Command/StatusesShowCommand.php
Expand Up @@ -25,6 +25,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var int|null $tweet_id */
$tweet_id = $input->getArgument('tweet_id');

$connection = new TwitterOAuth(
Expand All @@ -34,8 +35,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->container->getParameter('twitter_token_secret')
);

$output->writeln(
json_encode($connection->get('statuses/show/'.$tweet_id))
);
/** @var string $json */
$json = json_encode($connection->get(sprintf(
'statuses/show/%d',
$tweet_id
)));

$output->writeln($json);
}
}

0 comments on commit f34864c

Please sign in to comment.