co-phpunit 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env php
  2. <?php
  3. $code = 0;
  4. Swoole\Coroutine::set(['exit_condition' => function(){
  5. return Swoole\Coroutine::stats()['coroutine_num'] === 0;
  6. }]);
  7. Swoole\Coroutine::create(function () use (&$code) {
  8. if (version_compare('7.1.0', PHP_VERSION, '>')) {
  9. fwrite(
  10. STDERR,
  11. sprintf(
  12. 'This version of PHPUnit is supported on PHP 7.1 and PHP 7.2.' . PHP_EOL .
  13. 'You are using PHP %s (%s).' . PHP_EOL,
  14. PHP_VERSION,
  15. PHP_BINARY
  16. )
  17. );
  18. die(1);
  19. }
  20. if (! ini_get('date.timezone')) {
  21. ini_set('date.timezone', 'UTC');
  22. }
  23. $dirs = [
  24. getcwd() . '/vendor/autoload.php',
  25. __DIR__ . '/../../autoload.php',
  26. __DIR__ . '/../vendor/autoload.php',
  27. __DIR__ . '/vendor/autoload.php',
  28. ];
  29. foreach ($dirs as $file) {
  30. if (file_exists($file)) {
  31. define('PHPUNIT_COMPOSER_INSTALL', $file);
  32. break;
  33. }
  34. }
  35. unset($file);
  36. if (! defined('PHPUNIT_COMPOSER_INSTALL')) {
  37. fwrite(
  38. STDERR,
  39. 'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
  40. ' composer install' . PHP_EOL . PHP_EOL .
  41. 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
  42. );
  43. die(1);
  44. }
  45. $options = getopt('', ['prepend:']);
  46. if (isset($options['prepend'])) {
  47. require $options['prepend'];
  48. }
  49. unset($options);
  50. require PHPUNIT_COMPOSER_INSTALL;
  51. $code = PHPUnit\TextUI\Command::main(false);
  52. Swoole\Timer::clearAll();
  53. });
  54. swoole_event_wait();
  55. exit($code);