Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add optionnal root_user configuration for database
  • Loading branch information
kwizer15 committed Jul 16, 2025
commit f04833ce88cb34cbaf7c379daffcecbcd5c09ff8
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
mariadb:
image: mariadb:10.6
env:
MYSQL_ROOT_PASSWORD: root
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
Expand Down
3 changes: 3 additions & 0 deletions docs/fr_FR/unit-tests/phpunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ $CONFIG = [
'dbname' => 'jeedom', // Le bootstrap ajoutera '_test'
'username' => 'root',
'password' => 'root',
'root_user' => 'my_root_user', // À ajouter si besoin, par défaut 'root'
'root_password' => 'my_root_password', // À ajouter si besoin, par défaut pas de mot de passe
],
];
```
Expand Down Expand Up @@ -231,6 +233,7 @@ Jeedom utilise un système de cache FileCache qui stocke les données dans `/tmp
**Erreur de connexion à la base de données :**
- Vérifiez que MySQL/MariaDB est démarré
- Vérifiez les paramètres dans `core/config/common.config.php`
- Vérifiez que l’utilisateur du SGBD a les droits de création/suppression de base

**Erreur de cache :**
- Créez le répertoire de cache avec les bonnes permissions (voir section 4)
Expand Down
21 changes: 15 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
require_once dirname(__DIR__) . '/core/config/common.config.php';
global $CONFIG;

$CONFIG['db']['dbname'] .= '_test';
$rootUser = $CONFIG['db']['root_user'] ?? 'root';
$rootPassword = $CONFIG['db']['root_password'] ?? null;

$connection = new PDO(sprintf('mysql:host=%s;port=%u;charset=utf8', $CONFIG['db']['host'], $CONFIG['db']['port']), $CONFIG['db']['username'], $CONFIG['db']['password']);
$connection->query('DROP DATABASE IF EXISTS ' . $CONFIG['db']['dbname']);
$connection->query('CREATE DATABASE '.$CONFIG['db']['dbname']);
$connection->query('GRANT ALL PRIVILEGES ON '.$CONFIG['db']['dbname'].'.* TO "'.$CONFIG['db']['username'].'"@"%" IDENTIFIED BY "'.$CONFIG['db']['password'].'"');
$connection->query('FLUSH PRIVILEGES');
$CONFIG['db']['dbname'] .= '_test';
$CONFIG['db']['username'] .= '_test';
$CONFIG['db']['password'] .= md5(random_bytes(10));

try {
$connection = new PDO(sprintf('mysql:host=%s;port=%u;charset=utf8', $CONFIG['db']['host'], $CONFIG['db']['port']), $rootUser, $rootPassword);
$connection->query('DROP DATABASE IF EXISTS ' . $CONFIG['db']['dbname']);
$connection->query('CREATE DATABASE ' . $CONFIG['db']['dbname']);
$connection->query('GRANT ALL PRIVILEGES ON ' . $CONFIG['db']['dbname'] . '.* TO "' . $CONFIG['db']['username'] . '"@"%" IDENTIFIED BY "' . $CONFIG['db']['password'] . '"');
$connection->query('FLUSH PRIVILEGES');
} catch (\Throwable $exception) {
throw new RuntimeException(sprintf("Cannot create database: %s\nPlease check your MySQL server configuration\n%s", $exception->getMessage(), json_encode($CONFIG['db'])), 0, $exception);
}

ob_start();
require_once dirname(__DIR__).'/install/database.php';
Expand Down