Skip to content

Commit

Permalink
Updated testing on Travis.
Browse files Browse the repository at this point in the history
- Fixes #40.
  • Loading branch information
jhedstrom committed Oct 14, 2016
1 parent 29d38e9 commit c9289dd
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor
composer.lock
69 changes: 29 additions & 40 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ language: php
sudo: false

php:
- 5.5
- 5.6
- 7.0

env:
matrix:
- DRUPAL_CORE=8.1.x
- DRUPAL_CORE=8.2.x
global:
MODULE_NAME='message_subscribe'
CODER_VERSION='8.2.*'
- TEST_SUITE=8.1.x
- TEST_SUITE=8.2.x
- TEST_SUITE=8.3.x
- TEST_SUITE=PHP_CodeSniffer

# Only run the coding standards check once.
matrix:
exclude:
- php: 5.6
env: TEST_SUITE=PHP_CodeSniffer

mysql:
database: drupal
Expand All @@ -25,8 +28,14 @@ before_script:
# We also don't care if that file exists or not on PHP 7.
- phpenv config-rm xdebug.ini || true

# Make sure Composer is up to date.
- composer self-update

# Remember the current directory for later use in the Drupal installation.
- TESTDIR=$(pwd)
- MODULE_DIR=$(pwd)

# Install Composer dependencies.
- composer install

# Navigate out of module directory to prevent blown stack by recursive module
# lookup.
Expand All @@ -35,45 +44,25 @@ before_script:
# Create database.
- mysql -e 'create database drupal'

# Export database variable for kernel tests.
- export SIMPLETEST_DB=mysql://root:@127.0.0.1/drupal
# Download Drupal 8 core. Skip this for the coding standards test.
- test ${TEST_SUITE} == "PHP_CodeSniffer" || travis_retry git clone --branch $TEST_SUITE --depth 1 https://git.drupal.org/project/drupal.git

# Download Drupal 8 core.
- travis_retry git clone --branch $DRUPAL_CORE --depth 1 https://git.drupal.org/project/drupal.git
- cd drupal

# Download dependencies.
# @todo Specify in `require` and `require-dev` in `composer.json`
- cd modules
- travis_retry git clone --branch 8.x-1.x --depth 1 https://github.com/Gizra/og.git
- travis_retry git clone --branch 8.x-4.x --depth 1 https://git.drupal.org/project/flag.git
- travis_retry git clone --branch 8.x-1.x --depth 1 https://github.com/Gizra/message.git
- travis_retry git clone --branch 8.x-1.x --depth 1 https://github.com/Gizra/message_notify.git
- cd ..
# Remember the Drupal installation path.
- DRUPAL_DIR=$(pwd)/drupal

# Install Composer dependencies on 8.1.x and above.
- test ${DRUPAL_CORE} == "8.0.x" || composer self-update && composer install

# Coder.
- composer global require drupal/coder:$CODER_VERSION
- ln -s ~/.composer/vendor/drupal/coder/coder_sniffer/Drupal ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/

# Reference OG in the Drupal site.
- ln -s $TESTDIR modules/$MODULE_NAME
# Install Composer dependencies for core. Skip this for the coding standards test.
- test ${TEST_SUITE} == "PHP_CodeSniffer" || composer install --working-dir=$DRUPAL_DIR

# Start a web server on port 8888 in the background.
- nohup php -S localhost:8888 > /dev/null 2>&1 &
- test ${TEST_SUITE} == "PHP_CodeSniffer" || nohup php -S localhost:8888 --docroot $DRUPAL_DIR > /dev/null 2>&1 &

# Wait until the web server is responding.
- until curl -s localhost:8888; do true; done > /dev/null
- test ${TEST_SUITE} == "PHP_CodeSniffer" || until curl -s localhost:8888; do true; done > /dev/null

# Export web server URL for browser tests.
- export SIMPLETEST_BASE_URL=http://localhost:8888

script:
# Coding standards.
- $HOME/.composer/vendor/bin/phpcs --report=full --standard=Drupal $TESTDIR
# Run the PHPUnit tests which also include the kernel tests.
- ./vendor/phpunit/phpunit/phpunit -c ./core/phpunit.xml.dist ./modules/$MODULE_NAME
# Run legacy simpletests.
- php core/scripts/run-tests.sh --color --verbose --php `which php` --directory modules/$MODULE_NAME/src/Tests --dburl $SIMPLETEST_DB --url $SIMPLETEST_BASE_URL --sqlite ./.db.sqlite
# Export database variable for kernel tests.
- export SIMPLETEST_DB=mysql://root:@127.0.0.1/drupal

script: DRUPAL_DIR=$DRUPAL_DIR MODULE_DIR=$MODULE_DIR $MODULE_DIR/scripts/travis-ci/run-test.sh $TEST_SUITE
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"drupal/message_notify": "~8.1.0"
},
"require-dev": {
"drupal/og": "~8.1.0"
"drupal/og": "~8.1.0",
"drupal/coder": "^8.2"
},
"minimum-stability": "dev"
}
17 changes: 17 additions & 0 deletions phpcs-ruleset.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!-- PHP_CodeSniffer standard for Drupal modules. -->
<!-- See http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php -->
<ruleset name="Drupal Module">
<description>Drupal coding standard for contributed modules</description>

<!-- Exclude unsupported file types. -->
<exclude-pattern>*.gif</exclude-pattern>
<exclude-pattern>*.less</exclude-pattern>
<exclude-pattern>*.png</exclude-pattern>

<!-- Minified files don't have to comply with coding standards. -->
<exclude-pattern>*.min.css</exclude-pattern>
<exclude-pattern>*.min.js</exclude-pattern>

<rule ref="./vendor/drupal/coder/coder_sniffer/Drupal" />
</ruleset>
10 changes: 10 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="pbm_default">
<description>Default PHP CodeSniffer configuration for Messages.</description>
<rule ref="phpcs-ruleset.xml.dist"/>
<arg name="extensions" value="php,inc,module,install,info,test,profile,theme,css,js"/>
<arg name="report" value="full"/>
<arg value="p"/>
<file>.</file>
<exclude-pattern>./vendor</exclude-pattern>
</ruleset>
18 changes: 18 additions & 0 deletions scripts/travis-ci/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Run either PHPUnit tests or PHP_CodeSniffer tests on Travis CI, depending
# on the passed in parameter.

case "$1" in
PHP_CodeSniffer)
cd $MODULE_DIR
composer install
./vendor/bin/phpcs
exit $?
;;
*)
ln -s $MODULE_DIR $DRUPAL_DIR/modules/message_subscribe
cd $DRUPAL_DIR
./vendor/bin/phpunit -c ./core/phpunit.xml.dist $MODULE_DIR/tests
exit $?
esac

0 comments on commit c9289dd

Please sign in to comment.