Files
xxx/tests/php/environment.php
tim ed959888b4 Add PHP unit tests and page tests.
Run "composer install", then "composer test".
2026-09-26 03:48:09 +02:00

26 lines
975 B
PHP

<?php
/*
* The test environment without the site libraries: a fake database, a
* test configuration and an error log that tests can read. The bootstrap
* loads it, and so do subprocesses that include a library themselves.
*/
if (!defined('XXX_ROOT'))
define('XXX_ROOT', dirname(__DIR__, 2));
require_once XXX_ROOT . '/vendor/autoload.php';
// The site reads the test configuration, never a real .env
putenv('XXX_ENV_FILE=' . XXX_ROOT . '/tests/php/fixtures/test.env');
// Messages that the code logs go to a file that tests can read
define('XXX_TEST_LOG', getenv('XXX_TEST_LOG') ?: sys_get_temp_dir() . '/xxx-test-' . getmypid() . '.log');
ini_set('error_log', XXX_TEST_LOG);
// open_db() makes a FakeDb, so the mysqli extension is not needed
if (!function_exists('mysqli_report')) {
define('MYSQLI_REPORT_OFF', 0);
function mysqli_report($flags) { return TRUE; }
}
$GLOBALS['db_class'] = Xxx\Tests\Support\FakeDb::class;
$_SERVER['REMOTE_ADDR'] = '192.0.2.1';