@@ -8,35 +8,36 @@ use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
88use Testo \Common \Info ;
99use Testo \Common \Command ;
1010
11- // Set timeout to 0 to prevent script from timing out
11+ # Set timeout to 0 to prevent script from timing out
1212\set_time_limit (0 );
1313\ini_set ('memory_limit ' , '2G ' );
1414\error_reporting (E_ALL & ~E_DEPRECATED & ~E_NOTICE );
1515
1616(static function (): void {
17- $ cwd = \getcwd ();
18-
19- $ possibleAutoloadPaths = [
20- // local dev repository
21- \dirname (__DIR__ ) . '/vendor/autoload.php ' ,
22- // running from project root
23- $ cwd . '/vendor/autoload.php ' ,
24- // running from project bin
25- \dirname ($ cwd ) . '/autoload.php ' ,
26- // dependency
27- \dirname (__DIR__ , 4 ) . '/vendor/autoload.php ' ,
28- ];
17+ /** @var list<non-empty-string> $paths */
18+ $ paths = [];
19+
20+ # Local dev repository
21+ $ paths [] = __DIR__ . '/../vendor/autoload.php ' ;
22+
23+ # As a dependency
24+ $ s = DIRECTORY_SEPARATOR ;
25+ \str_ends_with (__DIR__ , "{$ s }vendor {$ s }testo {$ s }testo {$ s }bin " ) and $ paths [] = __DIR__ . '/../../../autoload.php ' ;
26+
27+ # Fallback to CWD
28+ $ paths [] = 'vendor/autoload.php ' ;
29+
2930 $ autoloadPath = null ;
30- foreach ($ possibleAutoloadPaths as $ possibleAutoloadPath ) {
31- if (\file_exists ($ possibleAutoloadPath )) {
32- $ autoloadPath = $ possibleAutoloadPath ;
31+ foreach ($ paths as $ path ) {
32+ if (\file_exists ($ path )) {
33+ $ autoloadPath = $ path ;
3334 break ;
3435 }
3536 }
3637
3738 if ($ autoloadPath === null ) {
3839 $ message = "Unable to find `vendor/autoload.php` in the following paths: \n\n" ;
39- $ message .= '- ' . \implode ("\n- " , $ possibleAutoloadPaths ) . "\n\n" ;
40+ $ message .= '- ' . \implode ("\n- " , $ paths ) . "\n\n" ;
4041 \fwrite (STDERR , $ message );
4142 exit (1 );
4243 }
0 commit comments