Repository navigation
Expand file tree
/
Copy pathbootstrap.php
More file actions
89 lines (75 loc) · 2.76 KB
/
Copy pathbootstrap.php
File metadata and controls
89 lines (75 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
date_default_timezone_set('UTC');
function define_from_env($name, $fallback = false) {
$env = getenv($name);
if ($env) {
define($name, $env);
} else {
define($name, $fallback);
}
}
define_from_env('REQUESTS_TEST_HOST', 'requests-test-server.onrender.com');
define_from_env('REQUESTS_TEST_HOST_HTTP', REQUESTS_TEST_HOST);
define_from_env('REQUESTS_TEST_HOST_HTTPS', REQUESTS_TEST_HOST);
define_from_env('REQUESTS_HTTP_PROXY');
define_from_env('REQUESTS_HTTP_PROXY_AUTH');
define_from_env('REQUESTS_HTTP_PROXY_AUTH_USER');
define_from_env('REQUESTS_HTTP_PROXY_AUTH_PASS');
// Make sure the test server(s) is/are available.
$test_servers = [
'HTTP' => REQUESTS_TEST_HOST_HTTP,
'HTTPS' => REQUESTS_TEST_HOST_HTTPS,
];
foreach ($test_servers as $type => $server) {
$command = 'curl -LI ' . $server . ' -o /dev/null -w "%{http_code}\n" -s';
exec($command, $output);
if (is_array($output) && isset($output[0]) && (strpos($output[0], '2') === 0 || strpos($output[0], '3') === 0)) {
define('REQUESTS_TEST_SERVER_' . $type . '_AVAILABLE', true);
} else {
define('REQUESTS_TEST_SERVER_' . $type . '_AVAILABLE', false);
}
unset($output);
echo 'REQUESTS_TEST_SERVER_', $type, '_AVAILABLE was set to: ', var_export(constant('REQUESTS_TEST_SERVER_' . $type . '_AVAILABLE'), true), PHP_EOL;
}
if (is_dir(dirname(__DIR__) . '/vendor')
&& file_exists(dirname(__DIR__) . '/vendor/autoload.php')
&& file_exists(dirname(__DIR__) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php')
) {
$vendor_dir = dirname(__DIR__) . '/vendor';
} else {
echo 'Please run `composer install` before attempting to run the unit tests.
You can still run the tests using a PHPUnit phar file, but some test dependencies need to be available.
';
die(1);
}
if (defined('__PHPUNIT_PHAR__')) {
// Testing via a PHPUnit phar.
// Load the PHPUnit Polyfills autoloader.
require_once $vendor_dir . '/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
// Load the library autoloader.
require_once dirname(__DIR__) . '/src/Autoload.php';
WpOrg\Requests\Autoload::register();
/*
* Autoloader specifically for the test files.
* Fixes issues with PHPUnit not being able to find test classes being extended when running
* in a non-Composer context.
*/
spl_autoload_register(
static function ($class_name) {
// Only try & load our own classes.
if (stripos($class_name, 'WpOrg\\Requests\\Tests\\') !== 0) {
return false;
}
// Strip namespace prefix 'WpOrg\Requests\Tests\'.
$relative_class = substr($class_name, 21);
$file = realpath(__DIR__ . '/' . strtr($relative_class, '\\', '/') . '.php');
if (file_exists($file)) {
include_once $file;
}
return true;
}
);
} else {
// Testing via a Composer setup.
require_once $vendor_dir . '/autoload.php';
}