12 if (isset($_SERVER[
'SERVER_NAME'])) {
13 die(
'This script can only be executed from the command-line.');
22 define(
'INDEX_FILE_LOCATION', dirname(dirname(dirname(dirname(__FILE__)))).
'/index.php');
26 define(
'DONT_DIE_ON_ERROR',
true);
29 define(
'SESSION_DISABLE_INIT',
true);
32 ini_set(
'assert.active',
true);
33 ini_set(
'assert.bail',
false);
34 ini_set(
'assert.warning',
true);
35 ini_set(
'assert.callback',
null);
36 ini_set(
'assert.quiet_eval',
false);
47 if (isset($_SERVER[
'PKP_MOCK_ENV'])) {
48 define(
'PHPUNIT_CURRENT_MOCK_ENV', $_SERVER[
'PKP_MOCK_ENV']);
50 foreach(array(
'lib/pkp/tests/mock/',
'tests/mock/') as $testDir) {
51 $normalizedMockEnv = normalizeMockEnvironment($testDir . $_SERVER[
'PKP_MOCK_ENV']);
52 if ($normalizedMockEnv) {
53 if (!empty($mockEnvs)) $mockEnvs .=
';';
54 $mockEnvs .= $normalizedMockEnv;
57 define(
'PHPUNIT_ADDITIONAL_INCLUDE_DIRS', $mockEnvs);
62 define(
'PHPUNIT_CURRENT_MOCK_ENV',
'__NONE__');
63 assert(is_array($_SERVER[
'argv']) and
count($_SERVER[
'argv'])>1);
64 $testDir = end($_SERVER[
'argv']);
65 define(
'PHPUNIT_ADDITIONAL_INCLUDE_DIRS', normalizeMockEnvironment($testDir));
76 function require_mock_env($mockEnv) {
77 if (PHPUNIT_CURRENT_MOCK_ENV ==
'__NONE__' || PHPUNIT_CURRENT_MOCK_ENV != $mockEnv) {
81 debug_print_backtrace();
83 'You are trying to run a test in the wrong mock environment ('
84 . PHPUNIT_CURRENT_MOCK_ENV .
' rather than ' . $mockEnv.
')!'
98 function import($class) {
99 static $mockEnvArray =
null;
102 if (is_null($mockEnvArray)) {
103 if (defined(
'PHPUNIT_ADDITIONAL_INCLUDE_DIRS')) {
104 $mockEnvArray = explode(
';', PHPUNIT_ADDITIONAL_INCLUDE_DIRS);
105 foreach($mockEnvArray as $mockEnv) {
106 if (!is_dir($mockEnv)) die (
'Invalid mock environment directory ' . $mockEnv .
'!');
109 $mockEnvArray = array();
115 foreach($mockEnvArray as $mockEnv) {
116 $classParts = explode(
'.', $class);
117 $mockClassFile = $mockEnv .
'/Mock'.array_pop($classParts) .
'.inc.php';
118 if (file_exists($mockClassFile)) {
119 require_once($mockClassFile);
125 require_once(
'./'.str_replace(
'.',
'/', $class) .
'.inc.php');
136 function normalizeMockEnvironment($mockEnv) {
137 if (substr($mockEnv, 0, 1) !=
'/') {
138 $mockEnv = getcwd() .
'/' . $mockEnv;
140 if (!is_dir($mockEnv)) {
141 $mockEnv = dirname($mockEnv);
143 $mockEnv = realpath($mockEnv);
146 if (is_dir($mockEnv)) {
157 require_once(
'./lib/pkp/includes/bootstrap.inc.php');
164 error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
167 ini_set(
'display_errors',
true);