1+ #!/usr/bin/env php
2+ <?php
3+ declare (strict_types=1 );
4+ use Pest \Kernel ;
5+ use Pest \Panic ;
6+ use Pest \TestCaseFilters \GitDirtyTestCaseFilter ;
7+ use Pest \TestCaseMethodFilters \TodoTestCaseFilter ;
8+ use Pest \TestSuite ;
9+ use Symfony \Component \Console \Input \ArgvInput ;
10+ use Symfony \Component \Console \Output \ConsoleOutput ;
11+ (function () {
12+ $ prepend = null ;
13+ foreach ($ _SERVER ["argv " ] as $ index => $ argv ) {
14+ // --prepend /path/to/file
15+ if ($ argv === "--prepend " ) {
16+ unset($ _SERVER ["argv " ][$ index ]);
17+ if (isset ($ _SERVER ["argv " ][$ index + 1 ])) {
18+ $ prepend = $ _SERVER ["argv " ][$ index + 1 ];
19+ unset($ _SERVER ["argv " ][$ index + 1 ]);
20+ }
21+ break ;
22+ }
23+ // --prepend=/path/to/file
24+ if (strpos ($ argv , "--prepend= " ) === 0 ) {
25+ $ prepend = substr ($ argv , 10 );
26+ unset($ _SERVER ["argv " ][$ index ]);
27+ break ;
28+ }
29+ }
30+ if ($ prepend !== null && file_exists ($ prepend )) {
31+ require $ prepend ;
32+ }
33+ })();
34+ $ code = 0 ;
35+ Swoole \Coroutine::set (["hook_flags " => SWOOLE_HOOK_ALL , "exit_condition " => function () {
36+ return Swoole \Coroutine::stats ()["coroutine_num " ] === 0 ;
37+ }]);
38+ Swoole \Coroutine \run (function () use (&$ code ) {
39+ try {
40+ $ code = (static function () {
41+ // Ensures Collision's Printer is registered.
42+ $ _SERVER ['COLLISION_PRINTER ' ] = 'DefaultPrinter ' ;
43+ $ args = $ _SERVER ['argv ' ];
44+ $ dirty = false ;
45+ $ todo = false ;
46+ foreach ($ args as $ key => $ value ) {
47+ if ($ value === '--compact ' ) {
48+ $ _SERVER ['COLLISION_PRINTER_COMPACT ' ] = 'true ' ;
49+ unset($ args [$ key ]);
50+ }
51+ if ($ value === '--profile ' ) {
52+ $ _SERVER ['COLLISION_PRINTER_PROFILE ' ] = 'true ' ;
53+ unset($ args [$ key ]);
54+ }
55+ if (str_contains ($ value , '--test-directory ' )) {
56+ unset($ args [$ key ]);
57+ }
58+ if ($ value === '--dirty ' ) {
59+ $ dirty = true ;
60+ unset($ args [$ key ]);
61+ }
62+ if ($ value === '--todos ' ) {
63+ $ todo = true ;
64+ unset($ args [$ key ]);
65+ }
66+ if (str_contains ($ value , '--teamcity ' )) {
67+ unset($ args [$ key ]);
68+ $ args [] = '--no-output ' ;
69+ unset($ _SERVER ['COLLISION_PRINTER ' ]);
70+ }
71+ }
72+ // Used when Pest is required using composer.
73+ $ vendorPath = dirname (__DIR__ , 4 ) . '/vendor/autoload.php ' ;
74+ // Used when Pest maintainers are running Pest tests.
75+ $ localPath = dirname (__DIR__ ) . '/vendor/autoload.php ' ;
76+ if (file_exists ($ vendorPath )) {
77+ include_once $ vendorPath ;
78+ $ autoloadPath = $ vendorPath ;
79+ } else {
80+ include_once $ localPath ;
81+ $ autoloadPath = $ localPath ;
82+ }
83+ // Get $rootPath based on $autoloadPath
84+ $ rootPath = dirname ($ autoloadPath , 2 );
85+ $ input = new ArgvInput ();
86+ $ testSuite = TestSuite::getInstance ($ rootPath , $ input ->getParameterOption ('--test-directory ' , 'tests ' ));
87+ if ($ dirty ) {
88+ $ testSuite ->tests ->addTestCaseFilter (new GitDirtyTestCaseFilter ($ rootPath ));
89+ }
90+ if ($ todo ) {
91+ $ testSuite ->tests ->addTestCaseMethodFilter (new TodoTestCaseFilter ());
92+ }
93+ $ isDecorated = $ input ->getParameterOption ('--colors ' , 'always ' ) !== 'never ' ;
94+ $ output = new ConsoleOutput (ConsoleOutput::VERBOSITY_NORMAL , $ isDecorated );
95+ try {
96+ $ kernel = Kernel::boot ($ testSuite , $ input , $ output );
97+ $ result = $ kernel ->handle ($ args );
98+ $ kernel ->shutdown ();
99+ } catch (Throwable |Error $ e ) {
100+ Panic::with ($ e );
101+ }
102+ return $ result ;
103+ })();
104+ } catch (Swoole \ExitException $ e ) {
105+ $ code = $ e ->getStatus ();
106+ }
107+ Swoole \Timer::clearAll ();
108+ Hyperf \Coordinator \CoordinatorManager::until (Hyperf \Coordinator \Constants::WORKER_EXIT )->resume ();
109+ });
110+ die ($ code );
0 commit comments