Skip to content

Commit 063dfa9

Browse files
committed
fix: Fix Autoloading of test classes with new autoloader
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent f1c4223 commit 063dfa9

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

lib/private/App/AppManager.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,13 @@ public function registerAppsAutoloading(array $apps): void {
606606
// FIXME needed?
607607
require_once $path . '/composer/autoload.php';
608608
}
609+
// Register Test namespace only when testing
610+
if ((defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) && is_dir($path . '/tests')) {
611+
\OC::$autoloader->addPsr4($appNamespace . '\\Tests', $path . '/tests');
612+
}
613+
}
614+
if ((defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN'))) {
615+
\OC::$autoloader->rebuild();
609616
}
610617
$this->eventLogger->end('bootstrap:register_apps_autoloading:apply_cache');
611618
$this->eventLogger->end('bootstrap:register_apps_autoloading');
@@ -655,11 +662,11 @@ public function registerAutoloading(string $app, string $path, bool $force = fal
655662
}
656663

657664
// Register Test namespace only when testing
658-
if ((defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) && is_dir($path . '/tests/')) {
659-
\OC::$autoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/');
665+
if ((defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) && is_dir($path . '/tests')) {
666+
\OC::$autoloader->addPsr4($appNamespace . '\\Tests', $path . '/tests');
660667
}
661668
if ($force) {
662-
\OC::$autoloader->triggerReload();
669+
\OC::$autoloader->rebuild();
663670
}
664671
}
665672

tests/autoload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
* This is a file that applications can require to be able to autoload the class Test\TestCase from Nextcloud tests
1414
*/
1515

16-
\OC::$autoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/lib/');
17-
\OC::$autoloader->triggerReload();
16+
\OC::$autoloader->addPsr4('Test', OC::$SERVERROOT . '/tests/lib');
17+
\OC::$autoloader->rebuild();

0 commit comments

Comments
 (0)