diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b7ef35 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/vendor +composer.lock diff --git a/.travis.yml b/.travis.yml index 9e68280..8c11a5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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. @@ -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 diff --git a/composer.json b/composer.json index 6f25798..0cfcf7a 100644 --- a/composer.json +++ b/composer.json @@ -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" } diff --git a/phpcs-ruleset.xml.dist b/phpcs-ruleset.xml.dist new file mode 100644 index 0000000..6141b63 --- /dev/null +++ b/phpcs-ruleset.xml.dist @@ -0,0 +1,17 @@ + + + + + Drupal coding standard for contributed modules + + + *.gif + *.less + *.png + + + *.min.css + *.min.js + + + diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..56d8b74 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,10 @@ + + + Default PHP CodeSniffer configuration for Messages. + + + + + . + ./vendor + diff --git a/scripts/travis-ci/run-test.sh b/scripts/travis-ci/run-test.sh new file mode 100755 index 0000000..42b57b1 --- /dev/null +++ b/scripts/travis-ci/run-test.sh @@ -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