Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Allow Symfony 4 #52

Merged
merged 9 commits into from
Aug 10, 2018
Merged
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build:
dependencies:
override:
-
command: 'composer require --dev "symfony/symfony:3.4.*" --no-update'
command: 'composer require "symfony/symfony:3.4.*" --no-update'
-
command: 'composer install --no-interaction -vv --profile --no-progress'
idle_timeout: 900
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ php:

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
Expand All @@ -25,7 +26,8 @@ before_install:
- if [[ $PHPUNIT_FLAGS = "" ]]; then phpenv config-rm xdebug.ini; fi

install:
- composer require --dev symfony/symfony:${SYMFONY_VERSION} $DEPENDENCY --no-update
- 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:
Expand Down
43 changes: 8 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ This bundle is also used to test several CI (Continuous Integration) services.
### Requirements:

- [Twitter keys][Twitter keys]
- PHP >= 5.5 (required by abraham/twitteroauth 0.6.0)
- PHP >= 7.1
- a database (must be supported by Doctrine2)
- [Symfony][Symfony GitHub] (2.7 or higher) with [Composer][Composer]. If you want to install it:
- [Symfony][Symfony GitHub] (3.4+) with [Composer][Composer]. If you want to install it:

php composer.phar create-project symfony/framework-standard-edition YOUR_DIRECTORY "2.7.*" -vvv
php composer.phar create-project symfony/framework-standard-edition YOUR_DIRECTORY "3.4.*" -vvv

### Steps:

Expand Down Expand Up @@ -79,49 +79,24 @@ This bundle is also used to test several CI (Continuous Integration) services.
### Usage:

1. Launch this command to fetch tweets: `php app/console statuses:hometimeline --table --env=prod`, with the ` --table` option the imported tweets will be shown
2. Update <kbd>app/config/config.yml</kbd> to enable Assetic if it's not activated yet:

framework:
# ...
assets: ~

3. Import the routes in your <kbd>app/config/routing.yml</kbd>:
2. Import the routes in your <kbd>app/config/routing.yml</kbd>:

asynctweets_website:
resource: "@AsyncTweetsBundle/Resources/config/routing.yml"
prefix: /asynctweets # Use only "/" if you want AsyncTweets at the root of the website

4. Open the page with your browser `.../YOUR_DIRECTORY/web/asynctweets/` or use the following command `php app/console statuses:read --env=prod` to see tweets

5. If you have an error `An exception has been thrown during the compilation of a template ("You must add AsyncTweetsBundle to the assetic.bundle config to use the {% image %} tag in AsyncTweetsBundle::layout.html.twig.") in "AsyncTweetsBundle::layout.html.twig".`, add the bundle in assetic bundles:

# Assetic Configuration
assetic:
# ...
bundles: [ AsyncTweetsBundle ]

6. Add `php app/console statuses:hometimeline --env=prod` in your crontab (e.g. every hour) to retrieve tweets automatically
3. Open the page with your browser `.../YOUR_DIRECTORY/web/asynctweets/` or use the following command `php app/console statuses:read --env=prod` to see tweets
4. Add `php app/console statuses:hometimeline --env=prod` in your crontab (e.g. every hour) to retrieve tweets automatically

## Dependencies
- [symfony/symfony][Symfony GitHub] (2.7+)
- [symfony/symfony][Symfony GitHub] (3.4+)
- [abraham/twitteroauth][twitteroauth] (^0.6.0)
- [twitter/bootstrap][Twitter Bootstrap] (use [Bootswatch 3.3.2][Bootstrap CDN])


### Tests:

If `phpunit` is installed:

phpunit

Or by installing `phpunit` with Composer:

php composer.phar require --dev phpunit/phpunit "4.8.* || 5.1.*" -vvv ; php vendor/bin/phpunit

### Development environment

- [doctrine/doctrine-fixtures-bundle][doctrine-fixtures-bundle] (~2.3)
- [liip/functional-test-bundle][functional-test-bundle] (~1.0)
php vendor/bin/phpunit

[Packagist]: https://packagist.org/packages/alexislefebvre/async-tweets-bundle
[Packagist Stable Image]: https://poser.pugx.org/alexislefebvre/async-tweets-bundle/v/stable.svg
Expand Down Expand Up @@ -159,5 +134,3 @@ Or by installing `phpunit` with Composer:
[twitteroauth]: https://github.com/abraham/twitteroauth
[Twitter Bootstrap]: https://github.com/twbs/bootstrap
[Bootstrap CDN]: http://www.bootstrapcdn.com/#bootswatch_tab
[doctrine-fixtures-bundle]: https://github.com/doctrine/DoctrineFixturesBundle
[functional-test-bundle]: https://github.com/liip/LiipFunctionalTestBundle
21 changes: 5 additions & 16 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ default:
features: tests/Features
contexts:
- 'Acme\Features\Context\FeatureContext'
- Knp\FriendlyContexts\Context\AliceContext
- Knp\FriendlyContexts\Context\EntityContext
- Knp\FriendlyContexts\Context\MinkContext
- 'Acme\Features\Context\DoctrineContext':
doctrine: '@doctrine'
- 'Behat\MinkExtension\Context\MinkContext'
- behatch:context:browser
extensions:
Behat\Symfony2Extension:
# http://zalas.eu/run-behat-scenarios-and-functional-tests-from-symfony-bundle-in-isolation-of-project/
Expand All @@ -20,16 +21,4 @@ default:
sessions:
default:
symfony2: ~
Knp\FriendlyContexts\Extension:
symfony_kernel:
bootstrap: tests/App/bootstrap.php
path: tests/App/AppKernel.php
class: AppKernel
env: test
debug: true
alice:
fixtures:
User: tests/Fixtures/User.yml
Tweet: tests/Fixtures/Tweet.yml
dependencies:
Tweet: [ User ]
Behatch\Extension: ~
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- sed -i 's/^;//' /opt/circleci/php/$(phpenv global)/etc/conf.d/xdebug.ini
- rm /opt/circleci/php/$(phpenv global)/etc/conf.d/xdebug.ini
override:
- composer require --dev "symfony/symfony:3.4.*" --no-update
- composer require "symfony/symfony:3.4.*" --no-update
- composer install --no-interaction --profile --no-progress
cache_directories:
- ~/.composer/cache
Expand Down
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,30 @@
"require" : {
"php": ">=7.0",
"ext-mbstring": "*",
"symfony/symfony": "~3.4",
"symfony/config": "~3.4|~4.0",
"symfony/form": "~3.4|~4.0",
"symfony/framework-bundle": "~3.4|~4.0",
"symfony/security-csrf": "~3.4|~4.0",
"symfony/templating": "~3.4|~4.0",
"symfony/twig-bundle": "~3.4|~4.0",
"symfony/var-dumper": "~3.4|~4.0",
"doctrine/orm": "^2.4.8",
"abraham/twitteroauth": "~0.6"
},
"require-dev": {
"doctrine/orm": "^2.4.8",
"symfony/assetic-bundle": "~2.3",
"symfony/monolog-bundle": "~3.1",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"liip/functional-test-bundle": "~2.0@alpha",
"phpunit/phpunit": "~6.5.6|~7.0",
"knplabs/friendly-contexts": "~0.8",
"behat/behat": "~3.2",
"behat/symfony2-extension": "^2.1",
"behat/mink": "^1.7",
"behat/mink-extension": "~2.2",
"behat/mink-browserkit-driver": "~1.3",
"phpspec/phpspec": "~3.4||~4.2"
"phpspec/phpspec": "~3.4||~4.2",
"doctrine/data-fixtures": "^1.3",
"nelmio/alice": "^3.4",
"behatch/contexts": "^3.1"
},
"autoload" : {
"psr-4" : {
Expand Down
2 changes: 0 additions & 2 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public function registerBundles()
{
$bundles = [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \Symfony\Bundle\MonologBundle\MonologBundle(),
new \Symfony\Bundle\AsseticBundle\AsseticBundle(),
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new \AlexisLefebvre\Bundle\AsyncTweetsBundle\AsyncTweetsBundle(),
new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
Expand Down
7 changes: 2 additions & 5 deletions tests/App/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ framework:
storage_id: session.storage.filesystem
profiler:
collect: false
# Enable Assetic
# see https://github.com/symfony/assetic-bundle/issues/396#issuecomment-160986958
assets: ~

monolog:
handlers:
Expand All @@ -26,7 +23,7 @@ monolog:
handler: nested
nested:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug

liip_functional_test:
Expand All @@ -39,7 +36,7 @@ doctrine:
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
path: "%kernel.cache_dir%/test.db"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
Expand Down
97 changes: 97 additions & 0 deletions tests/Features/Context/DoctrineContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace Acme\Features\Context;

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Tools\SchemaTool;
use Nelmio\Alice\Loader\NativeLoader;
use Symfony\Bridge\Doctrine\ManagerRegistry;

class DoctrineContext implements Context
{
/**
* @var ObjectManager
*/
private $manager;

/**
* @var SchemaTool
*/
private $schemaTool;

/**
* @var array
*/
private $classes;

/**
* @var \Nelmio\Alice\Loader\NativeLoader
*/
private $nativeLoader;

/**
* @var \Nelmio\Alice\ObjectSet
*/
private $objectSet;

public function __construct(
ManagerRegistry $doctrine
) {
$this->manager = $doctrine->getManager();
$this->schemaTool = new SchemaTool($this->manager);
$this->classes = $this->manager->getMetadataFactory()->getAllMetadata();
}

/**
* @BeforeScenario
*/
public function dropData()
{
$purger = new ORMPurger();
$purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);

$executor = new ORMExecutor($this->manager, $purger);
$executor->execute([]);
}

/**
* @AfterScenario @dropSchema
*/
public function dropDatabase()
{
$this->schemaTool->dropSchema($this->classes);
}

/**
* @When I load the following fixtures:
*/
public function loadFixtures(TableNode $data)
{
$this->nativeLoader = new NativeLoader();

$files = [];

foreach ($data->getRows() as $row) {
$name = $row[0];
$filePath = sprintf('%s/../../Fixtures/%s.yml', __DIR__, $name);

if (!file_exists($filePath)) {
throw new \RuntimeException(sprintf('File %s not found', $name));
}

$files[] = $filePath;
}

$this->objectSet = $this->nativeLoader->loadFiles($files)->getObjects();

foreach ($this->objectSet as $object) {
$this->manager->persist($object);
}

$this->manager->flush();
}
}
3 changes: 1 addition & 2 deletions tests/Features/Controller/Controller.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@reset-schema
Feature: Test DefaultController

Scenario: Index
When I am on the homepage
When I am on "/"
Then I should see a "html > body" element
And I should see a "html > head > title" element
And I should see "Home timeline" in the "html > head > title" element
Expand Down
13 changes: 8 additions & 5 deletions tests/Features/Controller/ControllerWithFixtures.feature
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@reset-schema
@alice(*)
Feature: Test DefaultController with Fixtures

Background:
Given I load the following fixtures:
| User |
| Tweet |

Scenario: Index
When I am on the homepage
When I am on "/"
Then I should see a "html > body" element
And I should see a "html > head > title" element
And I should see "Home timeline" in the "html > head > title" element
Expand All @@ -26,10 +29,10 @@ Feature: Test DefaultController with Fixtures
And I should see "3 pending tweets" in the "body > main.container > div.navigation.row > div.count.alert.alert-info" element
# There is no message about deleted tweets
And I should not see a "div.alert.alert-success" element
When I press the 2nd "Mark as read" link
When I follow the 2nd "Mark as read" link
Then I should not see a "div.alert.alert-success" element
# Delete old tweets
When I press the "Delete old tweets" link
When I follow "Delete old tweets"
Then I should see a "div.alert.alert-success" element
And I should see "1 tweets deleted." in the "div.alert.alert-success" element
And I should see a "main.container > div.tweets" element
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Tweet.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AlexisLefebvre\Bundle\AsyncTweetsBundle\Entity\Tweet:
tweet{1..3}:
id: <current()>
created_at: <date()>
created_at: <(new \DateTime())>
text: "Tweet <current()>"
user: '@user<current()>'
retweet_count: 42
Expand Down