if ($handle = proc_open($cmd, array(STDIN, STDOUT, STDERR), $pipes)) { $exitCode = proc_close($handle); if ($exitCode) { printf("\n\nUnit tests for module '%s' failed with status %d. Aborting.\n", $module, $exitCode); exit(1); } else { print "\n"; } } else { print "Could not invoke PHPUnit. Aborting.\n"; exit(1); } } // Change to application root directory to allow relative paths chdir(dirname(__DIR__)); // Special application environment, allows application code to skip actions not // appropriate in a unit test environment. putenv('APPLICATION_ENV=test'); if ($argc >= 2) { // Run tests for explicit module and optional filter testModule(ucfirst($argv[1]), @$argv[2]); } else { // Run tests for all modules that have tests defined testModule('Library'); testModule('Database'); testModule('Model'); testModule('Protocol'); testModule('Console'); testModule('DatabaseManager'); testModule('Export'); }
} else { // database option set without values: use all sections $databases = $config; } } else { // Database option not set: use builtin default config $databases[] = null; } // Run tests for all requested modules foreach ($modules as $module) { foreach ($databases as $name => $database) { print "\nRunning tests on {$module} module with "; if ($database) { print "config '{$name}'"; // Set database config as environment variable which will be // evaluated in test bootstrap scripts. This overrides the default // config in phpunit.xml. putenv('BRAINTACLE_TEST_DATABASE=' . json_encode($database)); } else { print 'default config'; // Unset environment variable (if set) to avoid conflicts if this // variable is set for whatever reason. This affects only the // current process. The calling shell is unaffected. // Bootstrap scripts will use the default config defined in // phpunit.xml. putenv('BRAINTACLE_TEST_DATABASE'); } print "\n\n"; testModule($module, $opts->filter, $opts->coverage ?: false); } }