HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/be.naniguide.com/tests/bootstrap.php
<?php

/**
 * PHPUnit / Pest bootstrap.
 *
 * Pre-registers the PSR-4 prefixes from every installed plugin's
 * composer.json so test-file discovery can resolve plugin classes
 * (`Acelle\Ai\…`, `Athena\Evs\…`, etc.) BEFORE Laravel boots and the
 * runtime plugin loader (`Plugin::autoloadWithoutDbQuery`) takes over.
 *
 * Without this bootstrap, top-level class definitions in plugin test
 * files that reference plugin contracts (e.g. `class BadKeyTool
 * implements Acelle\Ai\AIHandler\…\AIToolInterface`) explode during
 * Pest's discovery sweep with "Interface … not found" because the
 * autoloader doesn't know where to look.
 *
 * Production code paths are unaffected — Laravel's runtime loader
 * still registers the same prefixes during AppServiceProvider boot.
 * This file only fires when phpunit.xml `bootstrap=` points at it.
 */

/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__ . '/../vendor/autoload.php';

$pluginsRoot = __DIR__ . '/../storage/app/plugins';
foreach (glob("$pluginsRoot/*/*/composer.json") as $composerFile) {
    $meta = json_decode(file_get_contents($composerFile), true);
    if (! is_array($meta) || ! isset($meta['autoload']['psr-4'])) {
        continue;
    }

    $pluginPath = dirname($composerFile);
    foreach ($meta['autoload']['psr-4'] as $prefix => $relPath) {
        $relPath = is_array($relPath) ? $relPath : [$relPath];
        foreach ($relPath as $rel) {
            $loader->addPsr4($prefix, "$pluginPath/$rel");
        }
    }
}