|
11 | 11 | * the LICENSE file that was distributed with this source code. |
12 | 12 | */ |
13 | 13 |
|
14 | | -$rootPath = realpath(__DIR__ . '/../../../../'); |
| 14 | +$packageRoot = realpath(__DIR__ . '/..'); |
| 15 | +$rootPath = $packageRoot; |
| 16 | +$packageMode = $packageRoot !== false && is_file($packageRoot . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'); |
15 | 17 |
|
16 | | -if ($rootPath === false) { |
| 18 | +if (! $packageMode) { |
| 19 | + $rootPath = realpath(__DIR__ . '/../../../../'); |
| 20 | +} |
| 21 | + |
| 22 | +if ($rootPath === false || ! is_file($rootPath . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) { |
17 | 23 | throw new RuntimeException('Unable to resolve the project root for bootstrap tests.'); |
18 | 24 | } |
19 | 25 |
|
|
23 | 29 | throw new RuntimeException('Unable to create the test public directory for bootstrap tests.'); |
24 | 30 | } |
25 | 31 |
|
| 32 | +if ($packageMode) { |
| 33 | + $testAppRoot = $rootPath . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . 'test-app'; |
| 34 | + $configPath = $testAppRoot . DIRECTORY_SEPARATOR . 'Config'; |
| 35 | + $writablePath = $rootPath . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . 'writable'; |
| 36 | + $frameworkRoot = $rootPath . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'codeigniter4' . DIRECTORY_SEPARATOR . 'framework'; |
| 37 | + $pathsFile = $configPath . DIRECTORY_SEPARATOR . 'Paths.php'; |
| 38 | + |
| 39 | + if (! is_dir($configPath) && ! mkdir($configPath, 0775, true) && ! is_dir($configPath)) { |
| 40 | + throw new RuntimeException('Unable to create the test config directory for bootstrap tests.'); |
| 41 | + } |
| 42 | + |
| 43 | + foreach ([$writablePath, $writablePath . DIRECTORY_SEPARATOR . 'cache', $writablePath . DIRECTORY_SEPARATOR . 'logs', $writablePath . DIRECTORY_SEPARATOR . 'session', $writablePath . DIRECTORY_SEPARATOR . 'uploads'] as $directory) { |
| 44 | + if (! is_dir($directory) && ! mkdir($directory, 0775, true) && ! is_dir($directory)) { |
| 45 | + throw new RuntimeException('Unable to create the writable directory for bootstrap tests.'); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + $pathsContents = <<<PHP |
| 50 | +<?php |
| 51 | +
|
| 52 | +namespace Config; |
| 53 | +
|
| 54 | +class Paths |
| 55 | +{ |
| 56 | + public string \$systemDirectory = %s; |
| 57 | + public string \$appDirectory = %s; |
| 58 | + public string \$writableDirectory = %s; |
| 59 | + public string \$testsDirectory = %s; |
| 60 | + public string \$viewDirectory = %s; |
| 61 | + public string \$envDirectory = %s; |
| 62 | +} |
| 63 | +PHP; |
| 64 | + |
| 65 | + $pathsContents = sprintf( |
| 66 | + $pathsContents, |
| 67 | + var_export(str_replace('\\', '/', $frameworkRoot . '/system'), true), |
| 68 | + var_export(str_replace('\\', '/', $frameworkRoot . '/app'), true), |
| 69 | + var_export(str_replace('\\', '/', $writablePath), true), |
| 70 | + var_export(str_replace('\\', '/', $rootPath . DIRECTORY_SEPARATOR . 'tests'), true), |
| 71 | + var_export(str_replace('\\', '/', $frameworkRoot . '/app/Views'), true), |
| 72 | + var_export(str_replace('\\', '/', $rootPath), true), |
| 73 | + ); |
| 74 | + |
| 75 | + if (! is_file($pathsFile) || file_get_contents($pathsFile) !== $pathsContents) { |
| 76 | + file_put_contents($pathsFile, $pathsContents); |
| 77 | + } |
| 78 | + |
| 79 | + defined('CONFIGPATH') || define('CONFIGPATH', $configPath . DIRECTORY_SEPARATOR); |
| 80 | +} else { |
| 81 | + defined('CONFIGPATH') || define('CONFIGPATH', $rootPath . DIRECTORY_SEPARATOR . 'app/Config' . DIRECTORY_SEPARATOR); |
| 82 | +} |
| 83 | + |
26 | 84 | defined('HOMEPATH') || define('HOMEPATH', $rootPath . DIRECTORY_SEPARATOR); |
27 | | -defined('CONFIGPATH') || define('CONFIGPATH', $rootPath . DIRECTORY_SEPARATOR . 'app/Config' . DIRECTORY_SEPARATOR); |
28 | 85 | defined('PUBLICPATH') || define('PUBLICPATH', $publicPath . DIRECTORY_SEPARATOR); |
29 | 86 | defined('TESTPATH') || define('TESTPATH', __DIR__ . DIRECTORY_SEPARATOR); |
30 | 87 | defined('SUPPORTPATH') || define('SUPPORTPATH', __DIR__ . DIRECTORY_SEPARATOR . '_support' . DIRECTORY_SEPARATOR); |
|
0 commit comments