Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Commit 3f0fb46

Browse files
authored
test: change testing strategy (#339)
1 parent 7e4fe77 commit 3f0fb46

File tree

8 files changed

+148
-137
lines changed

8 files changed

+148
-137
lines changed

.env

-2
This file was deleted.

.travis.yml

+25-47
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,53 @@
1-
dist: trusty
2-
group: edge
31
language: php
4-
5-
addons:
6-
chrome: stable
7-
8-
php:
9-
- 7.1
10-
- 7.2
11-
2+
php: 7.2
123
cache:
134
directories:
145
- "$HOME/.composer/cache/files"
15-
166
env:
177
global:
188
- PROJECT_NAME=contentacms
199
- PROJECT_BASE_PATH=$HOME/$PROJECT_NAME
2010
- PROJECT_RELEASE_BRANCH=${PROJECT_RELEASE_BRANCH:-8.x-3.x}
21-
- WEB_HOST=127.0.0.1
22-
- WEB_PORT=8888
11+
- SIMPLETEST_BASE_URL=http://127.0.0.1:8888
12+
- SIMPLETEST_DB=sqlite://tmp/site.sqlite
2313

2414
branches:
2515
only:
2616
- /^8\.x\-[0-9]+\.x$/
2717

28-
before_install:
29-
# Fixes Composer exhausting the memory when using PHP 5.6.
30-
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
31-
# Fix failing tests due to email sending.
32-
- echo 'sendmail_path = /bin/true' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
33-
- mkdir $PROJECT_BASE_PATH
34-
# Load .env and .local.env
35-
- source ./scripts/ci/travis/load_env.sh
36-
37-
install:
38-
- composer run-script install-contenta $PROJECT_BASE_PATH --timeout=0
39-
- composer run-script ci:helper setup_anonymous_user "$PROJECT_BASE_PATH" --timeout=0
40-
41-
before_script:
42-
# Start Contenta Local Server
43-
- composer run-script start-contenta $PROJECT_BASE_PATH --timeout=0 &
44-
- until curl -s $WEB_HOST:$WEB_PORT; do sleep 1; done > /dev/null
45-
46-
script:
47-
- composer run-script ci:helper run_functional_tests "$PROJECT_BASE_PATH" --timeout=0
48-
49-
after_script:
50-
- killall php
51-
52-
# This stanza creates Travis Stages that are sequentially dependent.
5318
jobs:
5419
include:
55-
# Deployment Stage
56-
# This stage promotes a successful artifact from the deployment branch to GitHub
57-
- stage: Release
58-
php: 7.2
59-
install: skip
20+
-
21+
stage: test
22+
before_install:
23+
# Fixes Composer exhausting the memory when using PHP 5.6.
24+
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
25+
# Fix failing tests due to email sending.
26+
- echo 'sendmail_path = /bin/true' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
27+
- mkdir $PROJECT_BASE_PATH
28+
install: composer run-script install-contenta $PROJECT_BASE_PATH --timeout=0
29+
before_script:
30+
# Start Contenta CMS Local Server
31+
- composer run-script start-contenta $PROJECT_BASE_PATH --timeout=0 &
32+
- until curl -sS $SIMPLETEST_BASE_URL; do sleep 1; done > /dev/null
33+
- echo "Connected to the test server at ${SIMPLETEST_BASE_URL}"
34+
script: composer run-script ci:helper run_functional_tests "$PROJECT_BASE_PATH" --timeout=0
35+
after_script: killall php
36+
37+
-
38+
stage: release
39+
install: composer run-script install-contenta $PROJECT_BASE_PATH --timeout=0
6040
before_script: skip
6141
script: skip
6242
before_deploy:
63-
# Install Contenta
64-
- composer run-script install-contenta $PROJECT_BASE_PATH --timeout=0
6543
# Set Deployment Variable
6644
- RELEASE_DATE=$( date +%Y-%m-%d)
67-
- TRAVIS_TAG="v3.0.${TRAVIS_BUILD_NUMBER}"
68-
# Clean the Contenta Profile Folder
45+
# Clean the Contenta CMS Profile Folder
6946
- composer run-script ci:before-deploy contentacms_profile_cleanup "$PROJECT_BASE_PATH/web" --timeout=0
7047
# Remove Site files
7148
- composer run-script ci:before-deploy rm_site "$PROJECT_BASE_PATH/web" --timeout=0
7249
# Zip Folder
50+
- TRAVIS_TAG="v3.0.${TRAVIS_BUILD_NUMBER}"
7351
- composer run-script ci:before-deploy zip_folder "$HOME" "$PROJECT_NAME" "$TRAVIS_TAG" --timeout=0
7452
deploy:
7553
provider: releases

phpunit.xml

+44-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,56 @@
1-
<?xml version="1.0" encoding="UTF-8" ?>
2-
<phpunit
3-
convertErrorsToExceptions="true"
4-
colors="true"
5-
convertWarningsToExceptions="true"
6-
forceCoversAnnotation="false"
7-
stopOnFailure="true"
8-
>
9-
<php>
10-
<ini name="memory_limit" value="-1" />
11-
<env name="WEB_HOST" value="127.0.0.1" />
12-
<env name="WEB_HOST" value="8888" />
1+
<?xml version="1.0" encoding="UTF-8"?>
132

3+
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
4+
<!-- PHPUnit expects functional tests to be run with either a privileged user
5+
or your current system user. See core/tests/README.md and
6+
https://www.drupal.org/node/2116263 for details.
7+
-->
8+
<phpunit bootstrap="../../../core/tests/bootstrap.php"
9+
colors="true"
10+
verbose="true"
11+
beStrictAboutTestsThatDoNotTestAnything="true"
12+
beStrictAboutOutputDuringTests="true"
13+
beStrictAboutChangesToGlobalState="true">
14+
<!-- TODO set printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" once
15+
https://youtrack.jetbrains.com/issue/WI-24808 is resolved. Drupal provides a
16+
result printer that links to the html output results for functional tests.
17+
Unfortunately, this breaks the output of PHPStorm's PHPUnit runner. However, if
18+
using the command line you can add
19+
- -printer="\Drupal\Tests\Listeners\HtmlOutputPrinter" to use it (note there
20+
should be no spaces between the hyphens).
21+
-->
22+
<php>
23+
<!-- Set error reporting to E_ALL. -->
24+
<ini name="error_reporting" value="32767"/>
25+
<!-- Do not limit the amount of memory tests take to run. -->
26+
<ini name="memory_limit" value="-1"/>
27+
<!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
28+
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
29+
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: ../../../sites/simpletest/browser_output -->
30+
<ini name="BROWSERTEST_OUTPUT_DIRECTORY" value="../../../sites/simpletest/browser_output"/>
31+
<!-- To disable deprecation testing completely uncomment the next line. -->
32+
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
33+
<!-- Example for changing the driver class for mink tests MINK_DRIVER_CLASS value: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver' -->
34+
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
35+
<!-- Example for changing the driver args to phantomjs tests MINK_DRIVER_ARGS_PHANTOMJS value: '["http://127.0.0.1:8510"]' -->
36+
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["firefox", null, "http://localhost:4444/wd/hub"]' -->
1437
</php>
1538
<testsuites>
1639
<testsuite name="ContentaFunctional">
1740
<directory suffix="Test.php">tests/src/Functional/</directory>
1841
</testsuite>
1942
</testsuites>
43+
<listeners>
44+
<listener class="\Drupal\Tests\Listeners\DrupalListener">
45+
</listener>
46+
<!-- The Symfony deprecation listener has to come after the Drupal listener -->
47+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
48+
</listener>
49+
</listeners>
50+
<!-- Filter for coverage reports. -->
2051
<filter>
2152
<whitelist>
22-
<directory>tests/src/</directory>
53+
<directory>./tests/src/</directory>
2354
</whitelist>
2455
</filter>
2556
</phpunit>

scripts/ci/travis/load_env.sh

-6
This file was deleted.

scripts/ci/travis/tests/contenta_ci_tests_helper.sh

+15-31
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,6 @@
33
COMPOSER_BIN_DIR="$(composer config bin-dir)"
44
DOCROOT="web"
55

6-
# Setup Anonymous User Function
7-
# Gives access to anonymous user to access protected resources.
8-
# This function receives one argument:
9-
# $1 -> The Drupal Base Path
10-
setup_anonymous_user() {
11-
if [ -z $1 ] ; then
12-
echo "Please pass the Contenta Project Base Path to the install_test_dependencies function " 1>&2
13-
exit 1
14-
fi
15-
16-
# Setup local variables
17-
current_path=`pwd`
18-
DRUSH=$1/$COMPOSER_BIN_DIR/drush
19-
DRUPAL_BASE=$1/$DOCROOT
20-
21-
cd $DRUPAL_BASE
22-
# Add Permission to anonymous user
23-
$DRUSH updatedb -y
24-
$DRUSH cr -y
25-
26-
cd $current_path
27-
}
28-
296
# Run Functional Tests Function
307
# Run Contenta CMS Functional Tests
318
# This function receives one argument:
@@ -36,18 +13,25 @@ run_functional_tests() {
3613
exit 1
3714
fi
3815

39-
if [[ -z $WEB_HOST ]] || [[ -z $WEB_PORT ]] ; then
40-
echo "Please ensure that WEB_HOST and WEB_PORT environment variables are set." 1>&2
16+
if [[ -z $SIMPLETEST_BASE_URL ]] ; then
17+
echo "Please ensure that SIMPLETEST_BASE_URL environment variable is set. Ex: http://localhost" 1>&2
18+
exit 1
19+
fi
20+
if [[ -z $SIMPLETEST_DB ]] ; then
21+
echo "Please ensure that SIMPLETEST_DB environment variable is set. Ex: mysql://username:password@localhost/databasename#table_prefix" 1>&2
4122
exit 1
4223
fi
4324

44-
current_path=`pwd`
45-
CONTENTA_PATH=$1/$DOCROOT/profiles/contrib/contenta_jsonapi/
46-
PHPUNIT=$1/$COMPOSER_BIN_DIR/phpunit
47-
48-
cd $CONTENTA_PATH
25+
# remove xdebug to make php execute faster
26+
phpenv config-rm xdebug.ini
4927

50-
WEB_HOST=$WEB_HOST WEB_PORT=$WEB_PORT $PHPUNIT --testsuite ContentaFunctional
28+
CONTENTA_PATH=$1/$DOCROOT/profiles/contrib/contenta_jsonapi/
29+
DRUSH=$1/$COMPOSER_BIN_DIR/drush
30+
cd $1/$DOCROOT
31+
$DRUSH pm-enable --yes simpletest
32+
cd $1/$DOCROOT
33+
echo "php $1/$DOCROOT/core/scripts/run-tests.sh --php `which php` --url $SIMPLETEST_BASE_URL --suppress-deprecations --verbose --color Contenta"
34+
php $1/$DOCROOT/core/scripts/run-tests.sh --php `which php` --url $SIMPLETEST_BASE_URL --suppress-deprecations --verbose --color Contenta
5135
exit $?
5236
}
5337

scripts/development/build-contenta_jsonapi.sh

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ if [ -d "$DEST_DIR" ]; then
4040
sudo rm -Rf $DEST_DIR
4141
fi
4242
fi
43+
44+
# update composer
45+
$COMPOSER self-update
46+
4347
echo "-----------------------------------------------"
4448
echo " Downloading Contenta CMS using composer "
4549
echo "-----------------------------------------------"
@@ -52,29 +56,27 @@ if [ $? -ne 0 ]; then
5256
fi
5357

5458
cd ${DEST_DIR}
55-
5659
$COMPOSER config repositories.contenta_jsonapi path ${BASE_DIR}
57-
5860
$COMPOSER require "contentacms/contenta_jsonapi:*" "phpunit/phpunit:^6" --no-progress
5961

6062
cd $DOCROOT
6163
echo "-----------------------------------------------"
6264
echo " Installing Contenta CMS for local usage "
6365
echo "-----------------------------------------------"
64-
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} $DRUSH site-install --verbose --yes --db-url=sqlite://tmp/site.sqlite --site-mail=admin@localhost --account-mail=admin@localhost --site-name='Contenta CMS Demo' --account-name=admin --account-pass=admin\n\n"
66+
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} $DRUSH site-install --verbose --yes --db-url=$SIMPLETEST_DB --site-mail=admin@localhost --account-mail=admin@localhost --site-name='Contenta CMS Demo' --account-name=admin --account-pass=admin\n\n"
6567
# There is a problem installing from CLI. Drush can't locate some required services. Reinstalling a
6668
# second time usually does the trick.
6769
# TODO: We need to fix this.
68-
$DRUSH site-install --verbose --yes --db-url=sqlite://tmp/site.sqlite --site-mail=admin@localhost --account-mail=admin@localhost --site-name='Contenta CMS Demo' --account-name=admin --account-pass=admin;
69-
$DRUSH site-install --verbose --yes --db-url=sqlite://tmp/site.sqlite --site-mail=admin@localhost --account-mail=admin@localhost --site-name='Contenta CMS Demo' --account-name=admin --account-pass=admin;
70+
$DRUSH site-install --verbose --yes --db-url=$SIMPLETEST_DB --site-mail=admin@localhost --account-mail=admin@localhost --site-name='Contenta CMS Demo' --account-name=admin --account-pass=admin;
71+
$DRUSH site-install --verbose --yes --db-url=$SIMPLETEST_DB --site-mail=admin@localhost --account-mail=admin@localhost --site-name='Contenta CMS Demo' --account-name=admin --account-pass=admin;
7072

7173
if [ $? -ne 0 ]; then
7274
echo -e "${FG_C}${EBG_C} ERROR ${NO_C} The Drupal installer failed to install Contenta CMS."
7375
exit 3
7476
fi
7577

7678
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} $DRUSH en -y recipes_magazin contentajs\n\n"
77-
$DRUSH en -y recipes_magazin contentajs contenta_graphql
79+
$DRUSH en -y recipes_magazin contentajs
7880

7981
echo -e "\n\n\n"
8082
echo -e "\t********************************"

scripts/development/start-contenta_jsonapi.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22

3-
export $(cat .env | xargs)
3+
if [ -e .env ]; then
4+
export $(cat .env | xargs)
5+
fi
46

57
if [ -e .env.local ]; then
68
export $(cat .env.local | xargs)
@@ -34,11 +36,11 @@ echo "-------------------------------------"
3436
echo " Initializing local PHP server "
3537
echo "-------------------------------------"
3638
echo -e "${FG_C}${WBG_C} INFO ${NO_C} Server started. Use Ctrl+C to stop it."
37-
$DRUSH runserver --default-server=builtin ${WEB_HOST}:${WEB_PORT}
39+
$DRUSH runserver --no-browser $SIMPLETEST_BASE_URL
3840

3941
echo "---------------------------------"
4042
echo " One time admin login link "
4143
echo "---------------------------------"
42-
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} $DRUSH user-login --no-browser --uri=\"http://${WEB_HOST}:${WEB_PORT}\""
44+
echo -e "${FG_C}${BG_C} EXECUTING ${NO_C} $DRUSH user-login --no-browser --uri=\"$SIMPLETEST_BASE_URL\""
4345
echo -e "${FG_C}${WBG_C} INFO ${NO_C} Use this link to login as an administrator in your new site:"
44-
$DRUSH user-login --no-browser --uri="http://$WEB_HOST:$WEB_PORT"
46+
$DRUSH user-login --no-browser --uri="$SIMPLETEST_BASE_URL"

0 commit comments

Comments
 (0)