diff --git a/README.md b/README.md index a98ee58..90da3bf 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,7 @@ For example, if you want to start a Chrome Browser you can following the instruc * [Tutorial: Testing Form Submissions](docs/tutorial.md) * [Tutorial: Webservice Mocking with Phockito and TestSession](docs/webservice-mocking.md) + * [Tutorial: Setting up Behat on CircleCI](docs/circleci-tutorial.md) ## Configuration diff --git a/docs/circleci-tutorial.md b/docs/circleci-tutorial.md new file mode 100644 index 0000000..ad5b43d --- /dev/null +++ b/docs/circleci-tutorial.md @@ -0,0 +1,123 @@ +#Setting up CircleCI and Behat +If you'd like to run SilverStripe Behat tests on CircleCI, this can be achieved (along with screenshot artifacts on +error) reasonably easily. + +The below extract is a full `circle.yml` configuration file that gets the environment setup and running for Behat tests. +Please review it thoroughly as there are a few things you'll need to change for your individual project. Notably: + + * If you already have a behat.yml, you should ensure your local requirements are reflected as the following script will + overwrite the behat.yml file in order to ensure screenshot failures are stored in a CircleCI-appropriate directory, + even if you don't store screenshots locally. + * There is one variable required below (`REPO-NAME`) that you need to fill out yourself depending on the name of your + repository (CircleCI will check out your code into a sub-directory of the user's homedir based on the repository name). + * This assumes your Behat fixtures are located under the mysite/ directory. If not, check the `test.override` section + below. + +``` +machine: + php: + version: 5.6.14 +dependencies: + cache_directories: + - vendor + - ~/.composer/cache + + pre: + # Enable xdebug - this is for code coverage and may not be necessary for you. Remove if you don't need it, it can + # drastically slow down tests + - sed -i 's/^;//' ~/.phpenv/versions/$(phpenv global)/etc/conf.d/xdebug.ini + + # We found that some machines have outdated composer versions, so we self-update before running install just in case + - sudo composer self-update + - composer install --prefer-source --no-interaction + + # Behat and SilverStripe often require a reasonably large amount of memory, tune to your specific needs + - echo "memory_limit = 512M" > ~/.phpenv/versions/$(phpenv global)/etc/conf.d/memory.ini + + # Setup the _ss_environment.php file per https://docs.silverstripe.org/en/3.4/getting_started/environment_management + - | + cat << 'EOF' > _ss_environment.php + /etc/apache2/sites-available/website.conf + Listen 8080 + + DocumentRoot /home/ubuntu/REPO-NAME + ServerName localhost + + SetHandler application/x-httpd-php + + + AllowOverride All + + + EOF + + # Restart Apache to pickup new config + - a2ensite website.conf + - a2enmod rewrite + - sudo service apache2 restart + + # Get Selenium setup - we currently do this everytime but ideally we could store in the cache_directories and only + # grab if it doesn't exist to save time - an exercise left to the reader! + - wget http://selenium-release.storage.googleapis.com/2.52/selenium-server-standalone-2.52.0.jar + - 'java -jar selenium-server-standalone-2.52.0.jar > /dev/null 2>&1': + background: true + + # Clear and/or create artifacts directory + - mkdir $CIRCLE_ARTIFACTS/_behat_results + + # Create silverstipe-cache directory and add group perms + - if [ -d silverstripe-cache ]; then rm -rf silverstripe-cache; fi + - mkdir silverstripe-cache + - chmod 775 silverstripe-cache + + # Create assets directory and add group perms + - if [ ! -d assets ]; then mkdir assets && chmod 777 assets; fi + + # Setup behat.yml - you will need to merge your current behat.yml into this configuration + - | + cat > behat.yml <