How can global constants or configuration files be used to control the execution of test code in PHP?

Global constants or configuration files can be used to control the execution of test code in PHP by defining specific values or flags that determine whether test code should be run. By setting these constants or values in a centralized location, such as a configuration file, you can easily enable or disable test code execution without having to modify the test code itself. This approach allows for better code organization and maintainability.

// config.php
define('ENABLE_TESTS', true);

// test.php
include 'config.php';

if (ENABLE_TESTS) {
    // Run test code here
    echo "Running test code...";
} else {
    echo "Tests are disabled.";
}