diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-09-13 17:44:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-13 17:44:38 +0200 |
commit | bcb4e781a407798ef9d071dc3a15a1d0ac9e0e8d (patch) | |
tree | e210686e9c6d7fdd33b7e0cc905fbd38143db0a3 /tests | |
parent | 032f17c7956748fd25e33edf5d85d1d25b1ee94b (diff) | |
parent | 7a16d01ea79bf8effedd5e0e9ac7c2e4b4ea41f8 (diff) | |
download | nextcloud-server-bcb4e781a407798ef9d071dc3a15a1d0ac9e0e8d.tar.gz nextcloud-server-bcb4e781a407798ef9d071dc3a15a1d0ac9e0e8d.zip |
Merge pull request #47927 from nextcloud/fix/migrate-away-from-oc_app
Migrate away from OC_App to IAppManager
Diffstat (limited to 'tests')
-rw-r--r-- | tests/apps.php | 11 | ||||
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 4 | ||||
-rw-r--r-- | tests/lib/InfoXmlTest.php | 12 | ||||
-rw-r--r-- | tests/lib/IntegrityCheck/CheckerTest.php | 4 | ||||
-rw-r--r-- | tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Route/RouterTest.php | 14 |
6 files changed, 35 insertions, 14 deletions
diff --git a/tests/apps.php b/tests/apps.php index c01e364c0a8..c2015fecda9 100644 --- a/tests/apps.php +++ b/tests/apps.php @@ -44,10 +44,15 @@ function getSubclasses($parentClassName): array { } $apps = OC_App::getEnabledApps(); +$appManager = \OCP\Server::get(\OCP\App\IAppManager::class); foreach ($apps as $app) { - $dir = OC_App::getAppPath($app); - if (is_dir($dir . '/tests')) { - loadDirectory($dir . '/tests'); + try { + $dir = $appManager->getAppPath($app); + if (is_dir($dir . '/tests')) { + loadDirectory($dir . '/tests'); + } + } catch (\OCP\App\AppPathNotFoundException) { + /* ignore */ } } diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index 82a3f0d2045..ac470c00335 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -341,7 +341,7 @@ class AppManagerTest extends TestCase { $manager->expects($this->once()) ->method('getAppPath') ->with('test') - ->willReturn(null); + ->willReturn(''); $manager->expects($this->once()) ->method('getAppInfo') @@ -402,7 +402,7 @@ class AppManagerTest extends TestCase { $manager->expects($this->once()) ->method('getAppPath') ->with('test') - ->willReturn(null); + ->willReturn(''); $manager->expects($this->once()) ->method('getAppInfo') diff --git a/tests/lib/InfoXmlTest.php b/tests/lib/InfoXmlTest.php index 702eca4c0ce..1527e363bd7 100644 --- a/tests/lib/InfoXmlTest.php +++ b/tests/lib/InfoXmlTest.php @@ -7,6 +7,7 @@ namespace Test; use OCP\App\IAppManager; +use OCP\Server; /** * Class InfoXmlTest @@ -15,6 +16,13 @@ use OCP\App\IAppManager; * @package Test */ class InfoXmlTest extends TestCase { + private IAppManager $appManager; + + protected function setUp(): void { + parent::setUp(); + $this->appManager = Server::get(IAppManager::class); + } + public function dataApps() { return [ ['admin_audit'], @@ -45,8 +53,8 @@ class InfoXmlTest extends TestCase { * @param string $app */ public function testClasses($app) { - $appInfo = \OCP\Server::get(IAppManager::class)->getAppInfo($app); - $appPath = \OC_App::getAppPath($app); + $appInfo = $this->appManager->getAppInfo($app); + $appPath = $this->appManager->getAppPath($app); \OC_App::registerAutoloading($app, $appPath); //Add the appcontainer diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php index bf4ea16f564..05607f8113c 100644 --- a/tests/lib/IntegrityCheck/CheckerTest.php +++ b/tests/lib/IntegrityCheck/CheckerTest.php @@ -1030,9 +1030,9 @@ class CheckerTest extends TestCase { $this->checker ->expects($this->once()) ->method('verifyCoreSignature'); - $this->appLocator + $this->appManager ->expects($this->once()) - ->method('getAllApps') + ->method('getAllAppsInAppsFolders') ->willReturn([ 'files', 'calendar', diff --git a/tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php b/tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php index a86507f6bb2..d99a42e0d63 100644 --- a/tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php +++ b/tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php @@ -30,8 +30,4 @@ class AppLocatorTest extends TestCase { $this->locator->getAppPath('aTotallyNotExistingApp'); } - - public function testGetAllApps() { - $this->assertSame(\OC_App::getAllApps(), $this->locator->getAllApps()); - } } diff --git a/tests/lib/Route/RouterTest.php b/tests/lib/Route/RouterTest.php index 713d90d3c20..8647bb0f2f6 100644 --- a/tests/lib/Route/RouterTest.php +++ b/tests/lib/Route/RouterTest.php @@ -13,6 +13,7 @@ use OCP\App\IAppManager; use OCP\Diagnostics\IEventLogger; use OCP\IConfig; use OCP\IRequest; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -26,6 +27,8 @@ use Test\TestCase; */ class RouterTest extends TestCase { private Router $router; + private IAppManager&MockObject $appManager; + protected function setUp(): void { parent::setUp(); /** @var LoggerInterface $logger */ @@ -36,13 +39,16 @@ class RouterTest extends TestCase { $this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message)); } ); + + $this->appManager = $this->createMock(IAppManager::class); + $this->router = new Router( $logger, $this->createMock(IRequest::class), $this->createMock(IConfig::class), $this->createMock(IEventLogger::class), $this->createMock(ContainerInterface::class), - $this->createMock(IAppManager::class), + $this->appManager, ); } @@ -51,6 +57,12 @@ class RouterTest extends TestCase { } public function testGenerateConsecutively(): void { + $this->appManager->expects(self::atLeastOnce()) + ->method('cleanAppId') + ->willReturnArgument(0); + $this->appManager->expects(self::atLeastOnce()) + ->method('getAppPath') + ->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid); $this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index')); |