Skip to content

Commit

Permalink
Updated PHPUnit config and fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Nov 19, 2024
1 parent 0c3b08e commit 9e2f776
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ web/themes/**/node_modules
web/themes/**/build
.data
.logs
.phpunit.cache
.twig-cs-fixer.cache

# Ignore local override files.
Expand Down
50 changes: 24 additions & 26 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- For how to customize PHPUnit configuration, see web/core/tests/README.md. -->
<!-- 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="web/core/tests/bootstrap.php" colors="true"
bootstrap="web/core/tests/bootstrap.php"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
failOnWarning="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
cacheResult="false"
testdox="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
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/databasename#table_prefix -->
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/database_name#table_prefix -->
<env name="SIMPLETEST_DB" value=""/>
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
<env name="BROWSERTEST_OUTPUT_DIRECTORY" 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 container-based environment),
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=""/>

<!-- Deprecation testing is managed through Symfony's PHPUnit Bridge.
The environment variable SYMFONY_DEPRECATIONS_HELPER is used to configure
the behaviour of the deprecation tests.
See https://symfony.com/doc/current/components/phpunit_bridge.html#configuration
<!-- 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.
Expand All @@ -46,19 +45,17 @@
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
<!-- Deprecation errors can be selectively ignored by specifying a file of
regular expression patterns for exclusion.
See https://symfony.com/doc/current/components/phpunit_bridge.html#ignoring-deprecations
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=''/>
<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", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=''/>
<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>
<testsuites>
<testsuite name="unit">
Expand Down Expand Up @@ -93,6 +90,12 @@
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="false">
<report>
<html outputDirectory=".logs/coverage/phpunit/.coverage-html" lowUpperBound="50" highLowerBound="90"/>
<cobertura outputFile=".logs/coverage/phpunit/cobertura.xml"/>
</report>
</coverage>
<source>
<include>
<directory>web/modules/custom</directory>
<directory>web/themes/custom</directory>
Expand All @@ -104,10 +107,5 @@
<directory>web/modules/custom/*/tests</directory>
<directory>web/themes/custom/*/tests</directory>
</exclude>

<report>
<html outputDirectory=".logs/coverage/phpunit/.coverage-html" lowUpperBound="50" highLowerBound="90"/>
<cobertura outputFile=".logs/coverage/phpunit/cobertura.xml"/>
</report>
</coverage>
</source>
</phpunit>
4 changes: 1 addition & 3 deletions tests/phpunit/Drupal/EnvironmentSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public function testEnvironmentTypeResolution(array $vars, string $expected_env)
/**
* Data provider for testing of the resulting environment.
*/
public function dataProviderEnvironmentTypeResolution(): array {
$this->requireSettingsFile();

public static function dataProviderEnvironmentTypeResolution(): array {
return [
// By default, the default environment type is local.
[[], static::ENVIRONMENT_LOCAL],
Expand Down
6 changes: 4 additions & 2 deletions tests/phpunit/Drupal/SettingsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ protected function unsetEnvVars(): void {
* Require settings file.
*/
protected function requireSettingsFile(): void {
$app_root = getcwd();
if (empty($app_root)) {
$app_root = getcwd() . '/web';

if (!file_exists($app_root)) {
throw new \RuntimeException('Could not determine application root.');
}

$site_path = 'sites/default';
$config = [];
$settings = [];
Expand Down

1 comment on commit 9e2f776

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.