Skip to content
Snippets Groups Projects
Commit 691d6590 authored by Simon Bäse's avatar Simon Bäse
Browse files

Merge branch 'gitlab-ci-test' into '1.0.x'

Draft: Gitlab CI tests #3

See merge request !11
parents 2e812d52 cd563d1b
No related branches found
No related tags found
No related merge requests found
Pipeline #380314 failed
# Using the Gitlab CI template. Find original description here: # Using the Gitlab CI template. Find original description here:
# https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/gitlab-ci/template.gitlab-ci.yml # https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/gitlab-ci/template.gitlab-ci.yml
include: include:
- project: $_GITLAB_TEMPLATES_REPO - project: 'issue/gitlab_templates-3389338'
ref: $_GITLAB_TEMPLATES_REF ref: '3389338-phpunit-coverage'
file: file:
- '/includes/include.drupalci.main.yml' - '/includes/include.drupalci.main.yml'
- '/includes/include.drupalci.variables.yml' - '/includes/include.drupalci.variables.yml'
...@@ -10,13 +10,47 @@ include: ...@@ -10,13 +10,47 @@ include:
variables: variables:
OPT_IN_TEST_CURRENT: 1 OPT_IN_TEST_CURRENT: 1
OPT_IN_TEST_MAX_PHP: 1 OPT_IN_PHPUNIT_COVERAGE: 1
OPT_IN_TEST_PREVIOUS_MAJOR: 1
_CSPELL_WORDS: 'Bäse, Demianik' _CSPELL_WORDS: 'Bäse, Demianik'
_PHPUNIT_EXTRA: "--testdox"
phpcs: phpcs:
allow_failure: false allow_failure: false
phpstan: phpstan:
allow_failure: false allow_failure: false
phpunit (coverage-test):
allow_failure: true
extends:
- .phpunit-base
# @todo In MR257 remove this webdriver variable override.
variables:
MINK_DRIVER_ARGS_WEBDRIVER: !reference [.test-variables, variables, MINK_DRIVER_ARGS_WEBDRIVER]
rules:
- *opt-in-phpunit-coverage-rule
- *skip-phpunit-rule
- exists:
- '**/tests/**/*Test.php'
when: manual
script:
- |
echo https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/phpunit-enable-coverage.sh
curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/phpunit-enable-coverage.sh && chmod +x ./phpunit-enable-coverage.sh
# Execute using source so that all env vars will be available.
source ./phpunit-enable-coverage.sh
- _PHPUNIT_EXTRA="${_PHPUNIT_EXTRA} ${_PHPUNIT_COVERAGE_ARGS}"
- !reference [.phpunit-base, script]
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: $CI_PROJECT_DIR/coverage/cobertura-coverage.xml
paths:
# Merging paths is impossible, see https://gitlab.com/gitlab-org/gitlab/-/issues/351169.
- junit.xml
- $CI_PROJECT_DIR/$_WEB_ROOT/sites/default/files/simpletest
- $BROWSERTEST_OUTPUT_DIRECTORY
- apache.access.log.txt
- apache.error.log.txt
- $CI_PROJECT_DIR/coverage/cobertura-coverage.xml
#!/bin/bash
# Enables Xdebug for PHPUnit tests.
if [[ "$_PHPUNIT_CONCURRENT" == "1" ]]; then
echo "Error: The coverage mode is not supported in parallel mode (_PHPUNIT_CONCURRENT=1). Set _PHPUNIT_CONCURRENT=0 to enable coverage reporting." >&2
exit 1
fi
# Enable Xdebug extension.
PHP_EXTENSIONS_DIRECTORY=/usr/local/lib/php/extensions
PHP_EXTENSIONS_SUBDIRECTORY=$(ls -d "$PHP_EXTENSIONS_DIRECTORY"/* | head -n 1)
PHP_XDEBUG_EXTENSION_PATH=$PHP_EXTENSIONS_SUBDIRECTORY/xdebug.so
MODULE_DIRECTORY=$CI_PROJECT_DIR/web/modules/custom/$CI_PROJECT_NAME
# We can't use docker-php-ext-enable because it's produces a warning:
# PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0
echo "[xdebug]
zend_extension=\"$PHP_XDEBUG_EXTENSION_PATH\"" >> /usr/local/etc/php/php-cli.ini
# Enable coverage for Xdebug.
export XDEBUG_MODE=coverage
export _PHPUNIT_COVERAGE_ARGS="-c $MODULE_DIRECTORY/phpunit.xml --coverage-text --coverage-cobertura=$CI_PROJECT_DIR/coverage/cobertura-coverage.xml --colors=never"
<?xml version="1.0" encoding="UTF-8"?>
<!-- For how to customize PHPUnit configuration, see core/tests/README.md. -->
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
<!-- PHPUnit expects functional tests to be run with either a privileged user
or your current system user. See core/tests/README.md and
https://www.drupal.org/node/2116263 for details.
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutChangesToGlobalState="true" failOnRisky="true" failOnWarning="true" displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerDeprecations="true" cacheResult="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
<ini name="memory_limit" value="-1"/>
<!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
<env name="SIMPLETEST_BASE_URL" value=""/>
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/database_name#table_prefix -->
<env name="SIMPLETEST_DB" value=""/>
<!-- By default, browser tests will output links that use the base URL set
in SIMPLETEST_BASE_URL. However, if your SIMPLETEST_BASE_URL is an internal
path (such as may be the case in a virtual or Docker-based environment),
you can set the base URL used in the browser test output links to something
reachable from your host machine here. This will allow you to follow them
directly and view the output. -->
<env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>
<!-- The environment variable SYMFONY_DEPRECATIONS_HELPER is used to configure
the behavior of the deprecation tests.
Drupal core's testing framework is setting this variable to its defaults.
Projects with their own requirements need to manage this variable
explicitly.
-->
<!-- To disable deprecation testing completely uncomment the next line. -->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
<!-- Deprecation errors can be selectively ignored by specifying a file of
regular expression patterns for exclusion.
Uncomment the line below to specify a custom deprecations ignore file.
NOTE: it may be required to specify the full path to the file to run tests
correctly.
-->
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=.deprecation-ignore.txt"/> -->
<!-- Example for changing the driver class for mink tests MINK_DRIVER_CLASS value: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver' -->
<env name="MINK_DRIVER_CLASS" value=""/>
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS" value=""/>
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "goog:chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=""/>
</php>
<extensions>
<!-- Functional tests HTML output logging. -->
<bootstrap class="Drupal\TestTools\Extension\HtmlLogging\HtmlOutputLogger">
<!-- The directory where the browser output will be stored. If a relative
path is specified, it will be relative to the current working directory
of the process running the PHPUnit CLI. In CI environments, this can be
overridden by the value set for the "BROWSERTEST_OUTPUT_DIRECTORY"
environment variable.
-->
<parameter name="outputDirectory" value="sites/simpletest/browser_output"/>
<!-- By default browser tests print the individual links in the test run
report. To avoid overcrowding the output in CI environments, you can
set the "verbose" parameter or the "BROWSERTEST_OUTPUT_VERBOSE"
environment variable to "false". In GitLabCI, the output is saved
anyway as an artifact that can be browsed or downloaded from Gitlab.
-->
<parameter name="verbose" value="true"/>
</bootstrap>
</extensions>
<testsuites>
<testsuite name="unit">
<directory>tests/Drupal/Tests</directory>
<directory>modules/**/tests/src/Unit</directory>
<directory>profiles/**/tests/src/Unit</directory>
<directory>themes/**/tests/src/Unit</directory>
<directory>../modules/**/tests/src/Unit</directory>
<directory>../profiles/**/tests/src/Unit</directory>
<directory>../themes/**/tests/src/Unit</directory>
</testsuite>
<testsuite name="kernel">
<directory>tests/Drupal/KernelTests</directory>
<directory>modules/**/tests/src/Kernel</directory>
<directory>recipes/*/tests/src/Kernel</directory>
<directory>profiles/**/tests/src/Kernel</directory>
<directory>themes/**/tests/src/Kernel</directory>
<directory>../modules/**/tests/src/Kernel</directory>
<directory>../profiles/**/tests/src/Kernel</directory>
<directory>../themes/**/tests/src/Kernel</directory>
</testsuite>
<testsuite name="functional">
<directory>tests/Drupal/FunctionalTests</directory>
<directory>modules/**/tests/src/Functional</directory>
<directory>profiles/**/tests/src/Functional</directory>
<directory>recipes/*/tests/src/Functional</directory>
<directory>themes/**/tests/src/Functional</directory>
<directory>../modules/**/tests/src/Functional</directory>
<directory>../profiles/**/tests/src/Functional</directory>
<directory>../themes/**/tests/src/Functional</directory>
</testsuite>
<testsuite name="functional-javascript">
<directory>tests/Drupal/FunctionalJavascriptTests</directory>
<directory>modules/**/tests/src/FunctionalJavascript</directory>
<directory>recipes/*/tests/src/FunctionalJavascript</directory>
<directory>profiles/**/tests/src/FunctionalJavascript</directory>
<directory>themes/**/tests/src/FunctionalJavascript</directory>
<directory>../modules/**/tests/src/FunctionalJavascript</directory>
<directory>../profiles/**/tests/src/FunctionalJavascript</directory>
<directory>../themes/**/tests/src/FunctionalJavascript</directory>
</testsuite>
<testsuite name="build">
<directory>tests/Drupal/BuildTests</directory>
</testsuite>
</testsuites>
<!-- Settings for coverage reports. -->
<coverage>
<include>
<directory>./web/modules/custom/language_country_negotiation</directory>
</include>
<exclude>
<directory>./web/modules/custom/language_country_negotiation/tests</directory>
<directory>./web/modules/custom/language_country_negotiation/*/tests</directory>
<directory>./web/modules/custom/language_country_negotiation/modules/*/tests</directory>
</exclude>
</coverage>
</phpunit>
<?php
declare(strict_types=1);
namespace Drupal\Tests\language_country_negotiation\Functional;
use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;
/**
* Generic module test for language country negotiation.
*
* @group language_country_negotiation
*/
class GenericTest extends GenericModuleTestBase {
/**
* {@inheritdoc}
*/
protected function preUninstallSteps(): void {
$storage = \Drupal::entityTypeManager()->getStorage('lcn_country');
$countries = $storage->loadMultiple();
$storage->delete($countries);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment