Skip to content

Commit

Permalink
Add functional and browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmfcmf committed Aug 6, 2017
1 parent 99f4d91 commit eb3d0ec
Show file tree
Hide file tree
Showing 29 changed files with 1,699 additions and 181 deletions.
3 changes: 3 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
codecov:
ci:
- !styleci.com
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: symfony
59 changes: 59 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
language: php
php:
- '7.0'
- '7.1'
env:
global:
- SYMFONY_ENV=test
- PHPUNIT=vendor/symfony/phpunit-bridge/bin/simple-phpunit
matrix:
- TESTSUITE=functional
- TESTSUITE=browser

matrix:
fast_finish: true

services:
# ElasticSearch takes few seconds to start, but it also takes a while until
# we finally execute the tests, no need to wait!
# https://docs.travis-ci.com/user/database-setup/#ElasticSearch
- elasticsearch

cache:
directories:
- $HOME/.composer/cache/files
- node_modules

install:
- composer install -n
- npm install
- npm run prod

before_script:
- php bin/console doctrine:schema:create -n
- php bin/console app:elasticsearch:reindex

script:
- set -e
# Check for Twig and Yaml syntax errors
- php bin/console lint:twig app
- php bin/console lint:yaml app
# Check for security issues in installed dependencies
# Specifying the endpoint is a (temporary) fix for Travis, see:
# https://github.com/travis-ci/travis-ci/issues/6339
# https://github.com/sensiolabs/security-checker/pull/77#issuecomment-290733113
- php bin/console security:check --end-point=http://security.sensiolabs.org/check_lock
# Start server and PhantomJS if browser tests are executed
- |
if [[ ${TESTSUITE} == "browser" ]]; then
bash scripts/start-phantomjs.sh
fi;
# Execute tests
# Only gather coverage on PHP 7.1
- |
if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]] || [ "$TESTSUITE" == "browser" ]; then
$PHPUNIT --testsuite $TESTSUITE;
else
$PHPUNIT --testsuite $TESTSUITE --coverage-clover=coverage.xml;
bash <(curl -s https://codecov.io/bash) -X gcov -X coveragepy;
fi;
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ npm run dev
The application is now running at http://localhost:8000/app_dev.php.
Elasticsearch can be accessed at http://localhost:9200.

## Running tests

Tests use PHPUnit to run. There are two testsuites, one with functional tests and one with browser tests.
Functional tests can be executed like so:
```
php vendor/symfony/phpunit-bridge/bin/simple-phpunit --testsuite functional
```
Browser tests require PhantomJS as well as the application running in the test environment.
To do that, execute `bash tests/start-phantomjs.sh` *once* before executing the tests. There is not
need to call the script again until you reboot. Then execute the following to run the brow3ser tests:
```
php vendor/symfony/phpunit-bridge/bin/simple-phpunit --testsuite browser
```

# Running the application in production

## Apache configuration
Expand Down
8 changes: 7 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Vagrant.configure("2") do |config|
mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS adl"
# PHP
apt -y install php7.0 php7.0-curl php7.0-fpm php7.0-mysql php7.0-zip php7.0-cli php7.0-xml php-xdebug
apt -y install php7.0 php7.0-curl php7.0-fpm php7.0-mysql php7.0-zip php7.0-cli php7.0-xml php7.0-mbstring php7.0-sqlite3 php-xdebug
# Utilities
apt -y install htop git nano vim
Expand All @@ -52,6 +52,12 @@ Vagrant.configure("2") do |config|
curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt install -y nodejs
# PhantomJS headless browser
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar -xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2
mv phantomjs-2.1.1-linux-x86_64 /opt/phantomjs
ln -s /opt/phantomjs/bin/phantomjs /usr/bin/phantomjs
# Yarn (Frontend Package Manager)
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
Expand Down
3 changes: 3 additions & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function registerBundles()
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
if ('test' === $this->getEnvironment()) {
$bundles[] = new Liip\FunctionalTestBundle\LiipFunctionalTestBundle();
}
}

return $bundles;
Expand Down
31 changes: 31 additions & 0 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,34 @@ web_profiler:

swiftmailer:
disable_delivery: true

# Use an SQLite database for tests
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
path: "%kernel.cache_dir%/test.db"

# The best practice in symfony is to put a HTTP basic auth
# for the firewall in test env, so that not to have to
# make a request to the login form every single time.
# http://symfony.com/doc/current/cookbook/testing/http_authentication.html
security:
firewalls:
main:
http_basic: ~

liip_functional_test:
cache_sqlite_db: true
authentication:
username: 'User #1'
password: user1

parameters:
elasticsearch:
index_name: 'adventure_test'
type_name: 'all'
# Overwrite default blame listener to be able to manually set the user to blame.
stof_doctrine_extensions.event_listener.blame.class: Tests\ConfigurableBlameListener
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
]
},
"require": {
"php": ">=5.5.9",
"php": ">=7",
"data-dog/audit-bundle": "^v0.1.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
Expand All @@ -41,7 +41,11 @@
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"behat/mink": "^1.7",
"behat/mink-browserkit-driver": "^1.3",
"doctrine/doctrine-fixtures-bundle": "^2.3",
"jcalderonzumba/mink-phantomjs-driver": "^0.3.3",
"liip/functional-test-bundle": "^1.8",
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
Expand Down
Loading

0 comments on commit eb3d0ec

Please sign in to comment.