From 64c4584b8ffb44f970618597bdf6725c317bd455 Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Sun, 10 Sep 2023 18:19:42 +0200 Subject: [PATCH] fix: Allow dynamic autoloading for classes added during upgrade (#230) * See also https://github.com/nextcloud/calendar/pull/5295 --- composer.json | 1 - tests/Integration/Composer/AutoloaderTest.php | 60 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/Integration/Composer/AutoloaderTest.php diff --git a/composer.json b/composer.json index 4926d12..3200f2e 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,6 @@ }, "config": { "optimize-autoloader": true, - "classmap-authoritative": true, "platform": { "php": "8.0" }, diff --git a/tests/Integration/Composer/AutoloaderTest.php b/tests/Integration/Composer/AutoloaderTest.php new file mode 100644 index 0000000..50002d2 --- /dev/null +++ b/tests/Integration/Composer/AutoloaderTest.php @@ -0,0 +1,60 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCA\WorkflowOcr\Tests\Integration\Composer; + +use OCP\Security\ISecureRandom; +use OCP\Server; +use Test\TestCase; + +class AutoloaderTest extends TestCase { + /** @var null|string */ + private $testClass = null; + + private static function getClassPath(string $class): string { + return __DIR__ . '/../../../lib/' . $class . '.php'; + } + + protected function tearDown(): void { + parent::tearDown(); + + if ($this->testClass !== null && file_exists(self::getClassPath($this->testClass))) { + unlink(self::getClassPath($this->testClass)); + } + } + + public function testLoadDynamicClass(): void { + $rand = Server::get(ISecureRandom::class); + $className = ucfirst($rand->generate(10, ISecureRandom::CHAR_LOWER)); + $namespace = "OCA\\WorkflowOcr"; + + file_put_contents(self::getClassPath($className), <<testClass = $className; + + $this->assertTrue(class_exists($namespace . '\\' . $className)); + } +}