NEW: Move Travis behat test to run locally.

This shifts the behat test run to be triggered form composer activity
within the framework module directly,

 * silverstripe/serve is used to provide a webserver, based on the
   php -S command
 * se/selenium-server-standalone is used to install selenium rather than
   a download command

Because we’re using serve, the behat configuration can be locked down.

Further refinements could be made on this:

 * the behat-extension could be responsible for installing and
   starting/stopping selenium, making these tests more portable
 * xvfb initialisation could be provided with another bin tool in the
   begat-extension: vendor/bin/xvfb 1024x768
 * The bootstrap-file argument to serve could be provided as part of a
   composer.json setting. This would make it easier for developers to
   start a dev server simply by running vendor/bin/serve
 * the behat-extension could be responsible for installing and
   starting/stopping silverstripe/serve, removing the need for
   specifying base_url at all, and possibly utilising the same bootstrap
   file between serve and behat.
This commit is contained in:
Sam Minnee 2016-09-13 18:23:31 +12:00
parent 96126323d2
commit 07396e4437
5 changed files with 94 additions and 10 deletions

View File

@ -27,13 +27,13 @@ matrix:
env: DB=MYSQL PDO=1 PHPUNIT_TEST=1
- php: 5.6
env: DB=MYSQL BEHAT_TEST=1
- php: 5.6
env: NPM_TEST=1
allow_failures:
- php: 5.6
env: DB=MYSQL CMS_TEST=1 PHPUNIT_TEST=1
- php: 5.6
env: DB=MYSQL CMS_TEST=1 BEHAT_TEST=1
- php: 5.6
env: NPM_TEST=1
allow_failures:
- php: 7.0
env: DB=MYSQL PDO=1 PHPUNIT_TEST=1
@ -42,17 +42,22 @@ before_script:
- composer self-update || true
- phpenv rehash
- phpenv config-rm xdebug.ini
- "if [ \"$PHPUNIT_TEST\" = \"1\" ]; then composer install; fi"
- "if [ \"$DB\" = \"PGSQL\" ]; then composer require silverstripe/postgresql:^2.0; fi"
- "if [ \"$DB\" = \"SQLITE\" ]; then composer require silverstripe/sqlite3:^2.0; fi"
- "export DISPLAY=\":99\""
- "export XVFBARGS=\":99 -ac -screen 0 1024x768x16\""
- "if [ \"$na\" = \"\" ]; then composer install --prefer-dist; fi"
- "if [ \"$DB\" = \"PGSQL\" ]; then composer require silverstripe/postgresql:2.0.x-dev --prefer-dist; fi"
- "if [ \"$DB\" = \"SQLITE\" ]; then composer require silverstripe/sqlite3:2.0.x-dev --prefer-dist; fi"
- "if [ \"$CMS_TEST\" = \"1\" ]; then COMPOSER_ROOT_VERSION=4.0.x-dev composer require silverstripe/cms:4.0.x-dev silverstripe/siteconfig:4.0.x-dev silverstripe/reports:4.0.x-dev --prefer-dist; fi"
- "if [ \"$NPM_TEST\" = \"1\" ]; then nvm install $TRAVIS_NODE_VERSION && npm install; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup_selenium.php; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then sh -e /etc/init.d/xvfb start; sleep 3; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then (vendor/bin/selenium-server-standalone > selenium.log 2>&1 &); fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then (vendor/bin/serve --bootstrap-file tests/behat/serve-bootstrap.php &> serve.log &); fi"
script:
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/phpunit; fi"
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then vendor/bin/phpunit cms/tests; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/behat @framework; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then vendor/bin/behat @cms; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/behat --config tests/behat/config.yml .; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then vendor/bin/behat @cms --config cms/tests/behat/behat.yml; fi"
- "if [ \"$NPM_TEST\" = \"1\" ]; then npm run test; fi"
after_failure:

View File

@ -24,7 +24,11 @@
"embed/embed": "^2.6"
},
"require-dev": {
"phpunit/PHPUnit": "~4.8"
"phpunit/PHPUnit": "~4.8",
"silverstripe/behat-extension": "^2.1.0",
"silverstripe/serve": "dev-master",
"silverstripe/testsession": "^2.0.0-alpha3",
"se/selenium-server-standalone": "2.41.0"
},
"extra": {
"branch-alias": {

23
tests/behat/config.yml Normal file
View File

@ -0,0 +1,23 @@
default:
context:
class: SilverStripe\Framework\Test\Behaviour\FeatureContext
filters:
tags: "~@todo"
formatter:
name: pretty
parameters:
snippets: false
extensions:
SilverStripe\BehatExtension\MinkExtension:
base_url: http://localhost:8080/
files_path: %behat.paths.base%/tests/behat/features/files/
default_session: selenium2
javascript_session: selenium2
selenium2:
browser: firefox
SilverStripe\BehatExtension\Extension:
screenshot_path: %behat.paths.base%/artifacts/screenshots
framework_path: "../.."
bootstrap_file: "tests/behat/serve-bootstrap.php"

View File

@ -0,0 +1,47 @@
<?php
// Asset folder
if(!file_exists(BASE_PATH . '/assets')) {
mkdir(BASE_PATH . '/assets', 02775);
}
// DATABASE BOOTSTRAP
if (!defined('SS_ENVIRONMENT_TYPE')) {
define('SS_ENVIRONMENT_TYPE', 'dev');
}
if (!defined('SS_DATABASE_CLASS') && !defined('SS_DATABASE_USERNAME')) {
// The default settings let us define the database config via environment vars
// Database connection, including PDO and legacy ORM support
switch(getenv('DB')) {
case "PGSQL";
define('SS_DATABASE_CLASS', getenv('PDO') ? 'PostgrePDODatabase' : 'PostgreSQLDatabase');
define('SS_DATABASE_USERNAME', 'postgres');
define('SS_DATABASE_PASSWORD', '');
break;
case "SQLITE":
define('SS_DATABASE_CLASS', getenv('PDO') ? 'SQLite3PDODatabase' : 'SQLite3Database');
define('SS_DATABASE_USERNAME', 'root');
define('SS_DATABASE_PASSWORD', '');
define('SS_SQLITE_DATABASE_PATH', ':memory:');
break;
default:
define('SS_DATABASE_CLASS', getenv('PDO') ? 'MySQLPDODatabase' : 'MySQLDatabase');
define('SS_DATABASE_USERNAME', 'root');
define('SS_DATABASE_PASSWORD', '');
}
define('SS_DATABASE_SERVER', '127.0.0.1');
define('SS_DATABASE_CHOOSE_NAME', true);
}
// Default database settings
global $database;
$database = '';
require_once(__DIR__ . '/../../conf/ConfigureFromEnv.php');
class Page extends SilverStripe\View\ViewableData {}
class Page_Controller extends SilverStripe\Control\Controller {}

View File

@ -76,6 +76,11 @@ if (empty($_SERVER['HTTP_HOST'])) {
$_SERVER['HTTP_HOST'] = 'localhost';
}
// Asset folder
if(!file_exists(BASE_PATH . '/assets')) {
mkdir(BASE_PATH . '/assets', 02775);
}
// Default database settings
global $project;
$project = 'mysite';