co-phpunit 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env php
  2. <?php
  3. declare (strict_types=1);
  4. /*
  5. * This file is part of PHPUnit.
  6. *
  7. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  8. *
  9. * For the full copyright and license information, please view the LICENSE
  10. * file that was distributed with this source code.
  11. */
  12. if (!version_compare(PHP_VERSION, PHP_VERSION, '=')) {
  13. fwrite(STDERR, sprintf('%s declares an invalid value for PHP_VERSION.' . PHP_EOL . 'This breaks fundamental functionality such as version_compare().' . PHP_EOL . 'Please use a different PHP interpreter.' . PHP_EOL, PHP_BINARY));
  14. die(1);
  15. }
  16. if (version_compare('8.1.0', PHP_VERSION, '>')) {
  17. fwrite(STDERR, sprintf('This version of PHPUnit requires PHP >= 8.1.' . PHP_EOL . 'You are using PHP %s (%s).' . PHP_EOL, PHP_VERSION, PHP_BINARY));
  18. die(1);
  19. }
  20. $requiredExtensions = ['dom', 'json', 'libxml', 'mbstring', 'tokenizer', 'xml', 'xmlwriter'];
  21. $unavailableExtensions = array_filter($requiredExtensions, static function ($extension) {
  22. return !extension_loaded($extension);
  23. });
  24. if ([] !== $unavailableExtensions) {
  25. fwrite(STDERR, sprintf('PHPUnit requires the "%s" extensions, but the "%s" %s not available.' . PHP_EOL, implode('", "', $requiredExtensions), implode('", "', $unavailableExtensions), count($unavailableExtensions) === 1 ? 'extension is' : 'extensions are'));
  26. die(1);
  27. }
  28. unset($requiredExtensions, $unavailableExtensions);
  29. if (!ini_get('date.timezone')) {
  30. ini_set('date.timezone', 'UTC');
  31. }
  32. if (isset($GLOBALS['_composer_autoload_path'])) {
  33. define('PHPUNIT_COMPOSER_INSTALL', $GLOBALS['_composer_autoload_path']);
  34. unset($GLOBALS['_composer_autoload_path']);
  35. } else {
  36. foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
  37. if (file_exists($file)) {
  38. define('PHPUNIT_COMPOSER_INSTALL', $file);
  39. break;
  40. }
  41. }
  42. unset($file);
  43. }
  44. if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
  45. fwrite(STDERR, 'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL);
  46. die(1);
  47. }
  48. (function () {
  49. $prepend = null;
  50. foreach ($_SERVER["argv"] as $index => $argv) {
  51. // --prepend /path/to/file
  52. if ($argv === "--prepend") {
  53. unset($_SERVER["argv"][$index]);
  54. if (isset($_SERVER["argv"][$index + 1])) {
  55. $prepend = $_SERVER["argv"][$index + 1];
  56. unset($_SERVER["argv"][$index + 1]);
  57. }
  58. break;
  59. }
  60. // --prepend=/path/to/file
  61. if (strpos($argv, "--prepend=") === 0) {
  62. $prepend = substr($argv, 10);
  63. unset($_SERVER["argv"][$index]);
  64. break;
  65. }
  66. }
  67. if ($prepend !== null && file_exists($prepend)) {
  68. require $prepend;
  69. }
  70. })();
  71. require PHPUNIT_COMPOSER_INSTALL;
  72. $code = 0;
  73. Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL, 'exit_condition' => function () {
  74. return Swoole\Coroutine::stats()['coroutine_num'] === 0;
  75. }]);
  76. Swoole\Coroutine\run(function () use(&$code) {
  77. $code = (new PHPUnit\TextUI\Application())->run($_SERVER['argv']);
  78. Swoole\Timer::clearAll();
  79. Hyperf\Coordinator\CoordinatorManager::until(Hyperf\Coordinator\Constants::WORKER_EXIT)->resume();
  80. });
  81. die($code);