Reading view

[Help] PHPUnit in Drupal Multisite loading 'default' instead of specific site directory

Hey everyone, I'm running into a frustrating issue with a Drupal Multisite setup and could use some help.

I'm on a Linux server running Drupal 10.6.2 and Drush 12.5.3.0. My working directory is /var/www/uat.

Here is my /var/www/uat/phpunit.myWebsiteBBB.xml:

<?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="/var/www/uat/bootstrap.myWebsiteBBB.php" colors="true"> <php> <env name="DTT_SITE_DIR" value="myWebsiteBBB"/> <env name="SIMPLETEST_BASE_URL" value="https://uat.myWebsiteBBB.com"/> <env name="SIMPLETEST_DB" value="mysql://lmuat:Bwurp9vS(CQSbd5F@localhost:3306/myWebsiteBBB"/> <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/uat/web/sites/simpletest/browser_output"/> <ini name="memory_limit" value="-1"/> <server name="HTTP_HOST" value="uat.myWebsiteBBB.com"/> <server name="SERVER_NAME" value="uat.myWebsiteBBB.com"/> <env name="DTT_BASE_URL" value="https://uat.myWebsiteBBB.com"/> <env name="DTT_API_URL" value="https://uat.myWebsiteBBB.com"/> </php> <testsuites> <testsuite name="MyWebsiteBBB Existing Site Tests"> <directory>/var/www/uat/web/modules/custom/lps_api/tests/src/ExistingSite</directory> </testsuite> </testsuites> </phpunit> 

And my /var/www/uat/phpunit.myPageAAA.xml:

<?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="/var/www/uat/web/core/tests/bootstrap.php" colors="true"> <php> <env name="DTT_SITE_DIR" value="default"/> <env name="SIMPLETEST_BASE_URL" value="https://uat.myPageAAA.ca"/> <env name="SIMPLETEST_DB" value="mysql://lmuat:Bwurp9vS(CQSbd5F@localhost:3306/multisite"/> <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/uat/web/sites/simpletest/browser_output"/> <ini name="memory_limit" value="-1"/> <server name="HTTP_HOST" value="uat.myPageAAA.ca"/> <server name="SERVER_NAME" value="uat.myPageAAA.ca"/> <env name="DTT_BASE_URL" value="https://uat.myPageAAA.ca"/> <env name="DTT_API_URL" value="http://localhost"/> </php> <testsuites> <testsuite name="MyPageAAA Existing Site Tests"> <directory>/var/www/uat/web/modules/custom/lps_api/tests/src/ExistingSite</directory> </testsuite> </testsuites> </phpunit> 

The tests are located in: /var/www/uat/web/modules/custom/lps_api/tests/src/ExistingSite/

I added some lines to debug the environment in /var/www/uat/web/modules/custom/lps_api/tests/src/ExistingSite/ClinicImagesConsistencyTest.php:

public function testClinicImagesMatchJson(): void { // --- HOME SAFE DIAGNOSTICS --- $site_path = \Drupal::getContainer()->getParameter('site.path'); $db_name = \Drupal\Core\Database\Database::getConnection()->getConnectionOptions()['database']; $dtt_url = getenv('DTT_BASE_URL'); fwrite(STDERR, "\n--- SCAN RESULTS ---\n"); fwrite(STDERR, "1. Environment URL (DTT_BASE_URL): " . ($dtt_url ?: 'VACÍO') . "\n"); fwrite(STDERR, "2. Folder you chose to upload : " . $site_path . "\n"); fwrite(STDERR, "3. Final database : " . $db_name . "\n"); fwrite(STDERR, "------------------------------\n"); // --- END OF SAFE DIAGNOSIS --- 

In /var/www/uat/web/sites/sites.php:

<?php $sites['upcore.branchmanager.myWebsiteBBB.com'] = 'myWebsiteBBB'; $sites['dev.branchmanager.myWebsiteBBB.com'] = 'myWebsiteBBB'; $sites['myWebsiteBBB.com'] = 'myWebsiteBBB'; $sites['uat.myWebsiteBBB.com'] = 'myWebsiteBBB'; 

I have two sites: uat.myPageAAA and uat.myWebsiteBBB. Inside /var/www/uat/web/sites, I have the following folders: myWebsiteBBB and default.

So, what's the problem? When I execute: ./vendor/bin/phpunit -c phpunit.myWebsiteBBB.xml

This is the output I get:

--- SCAN RESULTS --- 1. Environment URL (DTT_BASE_URL): https://uat.myWebsiteBBB.com 2. Folder you chose to upload: sites/default 3. Final database: multisite 

Basically, when I run the tests for myWebsiteBBB, it does not load the myWebsiteBBB site data. Instead, it falls back to the default directory. Because of this, everything goes wrong when I execute my test script: /var/www/uat/run_multisite_tests.sh

#!/bin/bash # Ensure we run everything from the directory where this script is located SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Define base log directory LOG_BASE_DIR="$SCRIPT_DIR/logs" # Create the logs directory if it doesn't exist mkdir -p "$LOG_BASE_DIR" # Define static log files for this execution MYPAGEAAA_LOG="$LOG_BASE_DIR/uat_myPageAAA.log" MYWEBSITEBBB_LOG="$LOG_BASE_DIR/uat_myWebsiteBBB.log" echo "===================================================" echo "🚀 Starting tests for MyPageAAA..." echo "📄 Logging output to: logs/uat_myPageAAA.log" echo "===================================================" # Run PHPUnit and pipe the output to 'tee' to overwrite the log file ./vendor/bin/phpunit -c phpunit.myPageAAA.xml | tee "$MYPAGEAAA_LOG" MYPAGEAAA_RESULT=${PIPESTATUS[0]} echo "" echo "===================================================" echo "🚀 Starting tests for MyWebsiteBBB..." echo "📄 Logging output to: logs/uat_myWebsiteBBB.log" echo "===================================================" ./vendor/bin/phpunit -c phpunit.myWebsiteBBB.xml | tee "$MYWEBSITEBBB_LOG" MYWEBSITEBBB_RESULT=${PIPESTATUS[0]} echo "" echo "=================== SUMMARY =======================" if [ $MYPAGEAAA_RESULT -eq 0 ]; then echo "✅ MyPageAAA: SUCCESS" else echo "❌ MyPageAAA: FAILED (Check logs/uat_myPageAAA.log)" fi if [ $MYWEBSITEBBB_RESULT -eq 0 ]; then echo "✅ MyWebsiteBBB: SUCCESS" else echo "❌ MyWebsiteBBB: FAILED (Check logs/uat_myWebsiteBBB.log)" fi echo "===================================================" # If any test failed, return an error code for continuous integration systems if [ $MYPAGEAAA_RESULT -ne 0 ] || [ $MYWEBSITEBBB_RESULT -ne 0 ]; then exit 1 fi exit 0 

Has anyone run into this before? Why is PHPUnit ignoring my myWebsiteBBB environment variables and forcing the default site directory? Any pointers would be greatly appreciated!

submitted by /u/ScriptNone
[link] [comments]
  •  
❌