Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
Help
What's new
8
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Menu
Projects
Groups
Snippets
Get a free trial
Sign up
Login
Sign in / Register
Toggle navigation
Menu
Open sidebar
Florent Torregrosa Drupal
Docker Drupal Project
Commits
a59c236f
Commit
a59c236f
authored
Oct 13, 2020
by
Florent Torregrosa
🤘
Browse files
Tools: Adapt scripts and configuration to execute PHPUnit tests.
parent
1d4f4a8b
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
a59c236f
...
...
@@ -109,6 +109,11 @@ build dev:
script
:
-
security-checker security:check composer.lock
'
Tests:
PHPUnit'
:
stage
:
tests
script
:
-
./scripts/tests/run-tests-phpunit.sh
workflow
:
rules
:
# Execute jobs in merge request context.
...
...
Makefile
View file @
a59c236f
...
...
@@ -212,6 +212,10 @@ quality-fix-all: ## Launch all code quality fix of the project.
## Tests.
################################################################################
.PHONY
:
tests-phpunit
tests-phpunit
:
##
Launch PHPUnit tests on project sources.
@
docker-compose
exec
web bash
-c
'cd
$(PROJECT_PATH)
&& \
./scripts/tests/run-tests-phpunit.sh'
# https://stackoverflow.com/a/6273809/1826109
...
...
scripts/script-parameters.sh
View file @
a59c236f
...
...
@@ -7,6 +7,20 @@
source
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
/../.env
set
+o allexport
# Paths.
if
[
-n
"
${
CI_PROJECT_DIR
}
"
]
;
then
# If CI_PROJECT_DIR is defined it means we are in Gitlab CI.
PROJECT_PATH
=
${
CI_PROJECT_DIR
}
# shellcheck disable=SC2034
APP_PATH
=
${
PROJECT_PATH
}
/app
# shellcheck disable=SC2034
SCRIPTS_PATH
=
${
PROJECT_PATH
}
/scripts
# shellcheck disable=SC2034
WWW_PATH
=
${
PROJECT_PATH
}
/www
# shellcheck disable=SC2034
DRUSH
=
${
PROJECT_PATH
}
/vendor/bin/drush
fi
# shellcheck disable=SC2034
CURRENT_PATH
=
$(
pwd
)
# shellcheck disable=SC2034
...
...
scripts/tests/manage-tests-module.sh
0 → 100755
View file @
a59c236f
#!/bin/bash
# shellcheck source=scripts/script-parameters.sh
.
"
$(
dirname
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
)
"
/script-parameters.sh
usage
()
{
printf
"
\n
"
printf
"Usage:
\n\t
%s --create|--remove
\n
"
"
$0
"
printf
"
\n
"
printf
"Options:
\n
"
printf
"
\t
--create : Create the tests module.
\n
"
printf
"
\t
--remove : Remove the tests module.
\n
"
printf
"
\n
"
exit
0
}
CREATE
=
false
REMOVE
=
false
;
case
"
$1
"
in
-h
)
usage
;;
--create
)
CREATE
=
true
;;
--remove
)
REMOVE
=
true
;;
esac
if
[
"
$CREATE
"
=
false
]
&&
[
"
$REMOVE
"
=
false
]
;
then
echo
-e
"
${
COLOR_RED
}
Error: Please either use the --create or the --remove option.
${
COLOR_NC
}
"
exit
1
fi
TESTS_MODULE_ROOT_DIR
=
"
${
PROJECT_PATH
}
/app/modules/custom/project_tests"
TESTS_MODULE_CONFIG_DIR
=
"
$TESTS_MODULE_ROOT_DIR
/config/optional"
remove_tests_module
()
{
if
[
-d
"
$TESTS_MODULE_ROOT_DIR
"
]
;
then
echo
-e
"
${
COLOR_LIGHT_GREEN
}
Remove the tests module.
${
COLOR_NC
}
"
rm
-rf
"
$TESTS_MODULE_ROOT_DIR
"
fi
}
create_tests_module
()
{
remove_tests_module
echo
-e
"
${
COLOR_LIGHT_GREEN
}
Create the tests module folder.
${
COLOR_NC
}
"
mkdir
-p
"
$TESTS_MODULE_CONFIG_DIR
"
echo
-e
"
${
COLOR_LIGHT_GREEN
}
Copy project configuration the tests module.
${
COLOR_NC
}
"
printf
"name: 'Project Tests'
\n
type: module
\n
package: 'Testing'"
>
"
$TESTS_MODULE_ROOT_DIR
/project_tests.info.yml"
echo
-e
"
${
COLOR_LIGHT_GREEN
}
Copy configuration into the tests module.
${
COLOR_NC
}
"
find
"
${
PROJECT_PATH
}
/conf/drupal/
${
DRUPAL_SITE_DEFAULT_FOLDER_NAME
}
/sync"
\
-maxdepth
1
\
-type
f
\
-name
"*.yml"
\
-not
-name
"core.extension.yml"
\
-not
-name
"system.site.yml"
\
-exec
cp
{}
"
$TESTS_MODULE_CONFIG_DIR
"
\;
echo
-e
"
${
COLOR_LIGHT_GREEN
}
Remove uuid key from config files.
${
COLOR_NC
}
"
find
"
$TESTS_MODULE_CONFIG_DIR
"
\
-type
f
\
-exec
sed
-i
'1 s/^uuid:.*//'
{}
\;
}
if
[
"
$CREATE
"
=
true
]
;
then
create_tests_module
fi
if
[
"
$REMOVE
"
=
true
]
;
then
remove_tests_module
fi
scripts/tests/phpunit.xml
→
scripts/tests/phpunit.xml
.dist
View file @
a59c236f
...
...
@@ -5,10 +5,11 @@
or your current system user. See core/tests/README.md and
https://www.drupal.org/node/2116263 for details.
-->
<phpunit
bootstrap=
"/project/app/core/tests/bootstrap.php"
colors=
"true"
beStrictAboutTestsThatDoNotTestAnything=
"true"
beStrictAboutOutputDuringTests=
"true"
<phpunit
bootstrap=
"../../app/core/tests/bootstrap.php"
beStrictAboutChangesToGlobalState=
"true"
beStrictAboutOutputDuringTests=
"true"
beStrictAboutTestsThatDoNotTestAnything=
"true"
colors=
"true"
printerClass=
"\Drupal\Tests\Listeners\HtmlOutputPrinter"
>
<php>
<!-- Set error reporting to E_ALL. -->
...
...
@@ -18,7 +19,7 @@
<!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
<env
name=
"SIMPLETEST_BASE_URL"
value=
"http://web"
/>
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
<env
name=
"SIMPLETEST_DB"
value=
"
my
sql
://drupal:drupal@mysql/drupal
"
/>
<env
name=
"SIMPLETEST_DB"
value=
"sql
ite://localhost/:memory:
"
/>
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
<env
name=
"BROWSERTEST_OUTPUT_DIRECTORY"
value=
"/project/app/sites/default/files/simpletest"
/>
<!-- To have browsertest output use an alternative base URL. For example if
...
...
@@ -38,22 +39,23 @@
<env
name=
"MINK_DRIVER_ARGS_WEBDRIVER"
value=
'["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://chrome:9515"]'
/>
</php>
<testsuites>
<testsuite
name=
"unit"
>
<
file>
/project/app/core/tests/TestSuites/UnitTestSuite.php
</file
>
<testsuite
name=
"
project-
unit"
>
<
directory
suffix=
"Test.php"
>
../../app/modules/custom/*/tests/src/Unit
</directory
>
</testsuite>
<testsuite
name=
"kernel"
>
<
file>
/project/app/core/tests/TestSuites/KernelTestSuite.php
</file
>
<testsuite
name=
"
project-
kernel"
>
<
directory
suffix=
"Test.php"
>
../../app/modules/custom/*/tests/src/Kernel
</directory
>
</testsuite>
<testsuite
name=
"functional"
>
<
file>
/project/app/core/tests/TestSuites/FunctionalTestSuite.php
</file
>
<testsuite
name=
"
project-
functional"
>
<
directory
suffix=
"Test.php"
>
../../app/modules/custom/*/tests/src/Functional
</directory
>
</testsuite>
<testsuite
name=
"functional-javascript"
>
<
file>
/project/app/core/tests/TestSuites
/FunctionalJavascript
TestSuite.php
</file
>
<testsuite
name=
"
project-
functional-javascript"
>
<
directory
suffix=
"Test.php"
>
../../app/modules/custom/*/tests/src
/FunctionalJavascript
</directory
>
</testsuite>
<testsuite
name=
"build"
>
<
file>
/project/app/core/tests/TestSuites/BuildTestSuite.php
</file
>
<testsuite
name=
"
project-
build"
>
<
directory
suffix=
"Test.php"
>
../../app/modules/custom/*/tests/src/Build
</directory
>
</testsuite>
</testsuites>
<listeners>
<listener
class=
"\Drupal\Tests\Listeners\DrupalListener"
>
</listener>
...
...
@@ -61,25 +63,14 @@
<listener
class=
"Symfony\Bridge\PhpUnit\SymfonyTestsListener"
>
</listener>
</listeners>
<!-- Filter for coverage reports. -->
<filter>
<whitelist>
<directory>
/project/app/core/includes
</directory>
<directory>
/project/app/core/lib
</directory>
<!-- Extensions can have their own test directories, so exclude those. -->
<directory>
/project/app/core/modules
</directory>
<exclude>
<directory>
/project/app/core/modules/*/src/Tests
</directory>
<directory>
/project/app/core/modules/*/tests
</directory>
</exclude>
<directory>
/project/app/modules
</directory>
<directory
suffix=
".php"
>
../../app/modules/custom/*
</directory>
<exclude>
<directory>
/project/app/modules/*/src/Tests
</directory>
<directory>
/project/app/modules/*/tests
</directory>
<directory>
/project/app/modules/*/*/src/Tests
</directory>
<directory>
/project/app/modules/*/*/tests
</directory>
<directory>
../../app/modules/custom/*/tests
</directory>
</exclude>
<directory>
/project/app/sites
</directory>
</whitelist>
</filter>
</phpunit>
scripts/run-tests-phpunit.sh
→
scripts/
tests/
run-tests-phpunit.sh
View file @
a59c236f
#!/bin/bash
usage
()
{
echo
"run-test-phpunit.sh arguments"
}
# shellcheck source=scripts/script-parameters.sh
.
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
/script-parameters.sh
.
"
$(
dirname
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
)
"
/script-parameters.sh
echo
-e
"
${
COLOR_LIGHT_GREEN
}
Workaround for drupal-composer/drupal-paranoia
:
make symlink to sites/simpletest.
${
COLOR_NC
}
"
echo
-e
"
${
COLOR_LIGHT_GREEN
}
Workaround for drupal-composer/drupal-paranoia make symlink to sites/simpletest.
${
COLOR_NC
}
"
rm
-rf
"
${
WWW_PATH
}
"
/sites/simpletest
ln
-s
"
${
APP_PATH
}
"
/sites/simpletest
"
${
WWW_PATH
}
"
/sites/simpletest
.
"
${
SCRIPTS_PATH
}
"
/tests/manage-tests-module.sh
--create
echo
-e
"
${
COLOR_LIGHT_GREEN
}
Run tests.
${
COLOR_NC
}
"
sudo
-u
"
${
WEBSERVER_USER
}
"
-E
"
${
PROJECT_PATH
}
"
/vendor/bin/phpunit
-c
"
${
PROJECT_PATH
}
"
/scripts/tests/phpunit.xml
"
$@
"
sudo
-u
"
${
WEBSERVER_USER
}
"
-E
"
${
PROJECT_PATH
}
"
/vendor/bin/phpunit
-c
"
${
PROJECT_PATH
}
"
/scripts/tests/phpunit.xml.dist
.
"
${
SCRIPTS_PATH
}
"
/tests/manage-tests-module.sh
--remove
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment