|
| 1 | +<?php |
| 2 | +/** For Swoole coroutine tests */ |
| 3 | + |
| 4 | +use PHPUnit\TextUI\Command; |
| 5 | +use Swoole\Coroutine; |
| 6 | +use Swoole\ExitException; |
| 7 | + |
| 8 | +Coroutine::set([ |
| 9 | + 'log_level' => SWOOLE_LOG_INFO, |
| 10 | + 'trace_flags' => 0 |
| 11 | +]); |
| 12 | + |
| 13 | +/* |
| 14 | + * This file is part of PHPUnit. |
| 15 | + * |
| 16 | + * (c) Sebastian Bergmann <[email protected]> |
| 17 | + * |
| 18 | + * For the full copyright and license information, please view the LICENSE |
| 19 | + * file that was distributed with this source code. |
| 20 | + */ |
| 21 | +if (version_compare('7.1.0', PHP_VERSION, '>')) { |
| 22 | + fwrite(STDERR, |
| 23 | + sprintf('This version of PHPUnit is supported on PHP 7.1 and PHP 7.2.' . PHP_EOL . 'You are using PHP %s (%s).' . PHP_EOL, |
| 24 | + PHP_VERSION, PHP_BINARY)); |
| 25 | + die(1); |
| 26 | +} |
| 27 | + |
| 28 | +if (!ini_get('date.timezone')) { |
| 29 | + ini_set('date.timezone', 'UTC'); |
| 30 | +} |
| 31 | + |
| 32 | +// add loader file |
| 33 | +$__loader_file = dirname(__DIR__) . '/vendor/autoload.php'; |
| 34 | +if (file_exists($__loader_file)) { |
| 35 | + define('PHPUNIT_COMPOSER_INSTALL', $__loader_file); |
| 36 | +} |
| 37 | + |
| 38 | +if (!defined('PHPUNIT_COMPOSER_INSTALL')) { |
| 39 | + fwrite(STDERR, |
| 40 | + "You need to set up the project dependencies using Composer:\n\n" |
| 41 | + . ' composer install' . PHP_EOL . PHP_EOL |
| 42 | + . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL); |
| 43 | + die(1); |
| 44 | +} |
| 45 | + |
| 46 | +if (array_reverse(explode('/', __DIR__))[0] ?? '' === 'test') { |
| 47 | + $vendor_dir = dirname(PHPUNIT_COMPOSER_INSTALL); |
| 48 | + $bin_unit = "{$vendor_dir}/bin/phpunit"; |
| 49 | + $unit_uint = "{$vendor_dir}/phpunit/phpunit/phpunit"; |
| 50 | + if (file_exists($bin_unit)) { |
| 51 | + @unlink($bin_unit); |
| 52 | + @symlink(__FILE__, $bin_unit); |
| 53 | + } |
| 54 | + if (file_exists($unit_uint)) { |
| 55 | + @unlink($unit_uint); |
| 56 | + @symlink(__FILE__, $unit_uint); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +if (!in_array('-c', $_SERVER['argv'], true)) { |
| 61 | + $_SERVER['argv'][] = '-c'; |
| 62 | + $_SERVER['argv'][] = dirname(__DIR__) . '/phpunit.xml'; |
| 63 | +} |
| 64 | + |
| 65 | +require PHPUNIT_COMPOSER_INSTALL; |
| 66 | + |
| 67 | +$status = 0; |
| 68 | +\Swoft\Co::run(function () { |
| 69 | + // Status |
| 70 | + global $status; |
| 71 | + |
| 72 | + try { |
| 73 | + $status = Command::main(false); |
| 74 | + } catch (ExitException $e) { |
| 75 | + $status = $e->getCode(); |
| 76 | + echo 'ExitException: ' . $e->getMessage(), "\n"; |
| 77 | + } |
| 78 | +}); |
| 79 | + |
| 80 | +exit($status); |
0 commit comments