Skip to content

Commit

Permalink
DQA-8756: Fix .env and parse_ini_file issue (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocsilva authored Feb 15, 2024
1 parent 7e78195 commit 73d0ef9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpunit/phpunit": "^9.5 || ^10.0",
"squizlabs/php_codesniffer": "^3.7"
"squizlabs/php_codesniffer": "^3.7",
"vlucas/phpdotenv": "^5.6"
},
"suggest": {
"drupal/console": "The Drupal CLI, tool to generate boilerplate code, interact with and debug Drupal."
Expand Down
12 changes: 8 additions & 4 deletions src/TaskRunner/Commands/ComponentCheckCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace EcEuropa\Toolkit\TaskRunner\Commands;

use Composer\Semver\Semver;
use Dotenv\Dotenv;
use EcEuropa\Toolkit\DrupalReleaseHistory;
use EcEuropa\Toolkit\TaskRunner\AbstractCommands;
use EcEuropa\Toolkit\Website;
Expand Down Expand Up @@ -303,17 +304,20 @@ protected function validateEnvironmentVariables()
$parsed_yaml = Yaml::parseFile($filename);
// Loop through all the services looking for environment variables.
if (!empty($parsed_yaml['services'])) {
foreach ($parsed_yaml['services'] as $service_name => $service_settings) {
if (!empty($service_settings['environment'])) {
foreach ($parsed_yaml['services'] as $serviceName => $serviceSettings) {
if (!empty($serviceSettings['environment'])) {
// Add environment variables set for check.
$envVarsSet[$filename . '_' . $service_name] = $service_settings['environment'];
$envVarsSet[$filename . '_' . $serviceName] = $serviceSettings['environment'];
}
}
}
// Ini files.
} else {
// Add environment variables set for check.
$envVarsSet[$filename] = parse_ini_file($filename);
$contentParsed = Dotenv::parse(file_get_contents($filename));
if (is_array($contentParsed)) {
$envVarsSet[$filename] = $contentParsed;
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/commands/component-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,11 @@
- touch: composer.json
- file: .env
content: |
# Use special characters like `~/.bashrc` or (parentheses).
# This is the user for the Nextcloud.
NEXTCLOUD_USER=
NEXTCLOUD_PASS=
# This is the deprecated ASDA user.
ASDA_USER=
ASDA_PASSWORD=
QA_API_BASIC_AUTH=
Expand Down

0 comments on commit 73d0ef9

Please sign in to comment.