Skip to content

Commit

Permalink
feat: support BASE_PATH scanning in tests/bootstrap.php
Browse files Browse the repository at this point in the history
  • Loading branch information
albertcht committed Sep 21, 2024
1 parent 654e51c commit 88480e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./tests/bootstrap.php"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
processIsolation="false"
Expand Down
19 changes: 18 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,26 @@

error_reporting(E_ALL);

! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);

$dir = __DIR__;
$lastDir = '';
if (! defined('BASE_PATH')) {
while (! file_exists($dir . '/composer.json') && $dir !== dirname($dir)) {
if ($lastDir === $dir) {
break;
}
$lastDir = $dir;
$dir = dirname($dir);
}
}

if (! file_exists($dir . '/composer.json')) {
throw new RuntimeException("Unable to find base path (directory with composer.json)");
}

define('BASE_PATH', $dir);

Swoole\Runtime::enableCoroutine(true);

require BASE_PATH . '/vendor/autoload.php';
Expand Down

0 comments on commit 88480e4

Please sign in to comment.