diff --git a/apps/updatenotification/lib/Notification/BackgroundJob.php b/apps/updatenotification/lib/Notification/BackgroundJob.php index 08baa35664f56..3c0cac60cded4 100644 --- a/apps/updatenotification/lib/Notification/BackgroundJob.php +++ b/apps/updatenotification/lib/Notification/BackgroundJob.php @@ -53,6 +53,9 @@ class BackgroundJob extends TimedJob { /** @var IClientService */ protected $client; + /** @var Installer */ + protected $installer; + /** @var string[] */ protected $users; @@ -64,8 +67,9 @@ class BackgroundJob extends TimedJob { * @param IGroupManager $groupManager * @param IAppManager $appManager * @param IClientService $client + * @param Installer $installer */ - public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client) { + public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) { // Run once a day $this->setInterval(60 * 60 * 24); @@ -74,6 +78,7 @@ public function __construct(IConfig $config, IManager $notificationManager, IGro $this->groupManager = $groupManager; $this->appManager = $appManager; $this->client = $client; + $this->installer = $installer; } protected function run($argument) { @@ -257,6 +262,6 @@ protected function getChannel() { * @return string|false */ protected function isUpdateAvailable($app) { - return Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher()); + return $this->installer->isUpdateAvailable($app); } } diff --git a/apps/updatenotification/tests/Notification/BackgroundJobTest.php b/apps/updatenotification/tests/Notification/BackgroundJobTest.php index 92a8a687f5a16..0355b10a09c7d 100644 --- a/apps/updatenotification/tests/Notification/BackgroundJobTest.php +++ b/apps/updatenotification/tests/Notification/BackgroundJobTest.php @@ -23,6 +23,7 @@ namespace OCA\UpdateNotification\Tests\Notification; +use OC\Installer; use OCA\UpdateNotification\Notification\BackgroundJob; use OCP\App\IAppManager; use OCP\Http\Client\IClientService; @@ -47,6 +48,8 @@ class BackgroundJobTest extends TestCase { protected $appManager; /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */ protected $client; + /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */ + protected $installer; public function setUp() { parent::setUp(); @@ -56,6 +59,7 @@ public function setUp() { $this->groupManager = $this->createMock(IGroupManager::class); $this->appManager = $this->createMock(IAppManager::class); $this->client = $this->createMock(IClientService::class); + $this->installer = $this->createMock(Installer::class); } /** @@ -69,7 +73,8 @@ protected function getJob(array $methods = []) { $this->notificationManager, $this->groupManager, $this->appManager, - $this->client + $this->client, + $this->installer ); } { return $this->getMockBuilder(BackgroundJob::class) @@ -79,6 +84,7 @@ protected function getJob(array $methods = []) { $this->groupManager, $this->appManager, $this->client, + $this->installer, ]) ->setMethods($methods) ->getMock(); diff --git a/core/Command/App/Install.php b/core/Command/App/Install.php index c8c4652d7ba86..8f530975be988 100644 --- a/core/Command/App/Install.php +++ b/core/Command/App/Install.php @@ -51,13 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { } try { - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - \OC::$server->getLogger(), - \OC::$server->getConfig() - ); + $installer = \OC::$server->query(Installer::class); $installer->downloadApp($appId); $result = $installer->installApp($appId); } catch(\Exception $e) { diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index 755d3d386c11b..be6a2da22c8c4 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -30,6 +30,7 @@ namespace OC\Core\Command\Maintenance; use InvalidArgumentException; +use OC\Installer; use OC\Setup; use OC\SystemConfig; use OCP\Defaults; @@ -73,9 +74,15 @@ protected function execute(InputInterface $input, OutputInterface $output) { // validate the environment $server = \OC::$server; - $setupHelper = new Setup($this->config, $server->getIniWrapper(), - $server->getL10N('lib'), $server->query(Defaults::class), $server->getLogger(), - $server->getSecureRandom()); + $setupHelper = new Setup( + $this->config, + $server->getIniWrapper(), + $server->getL10N('lib'), + $server->query(Defaults::class), + $server->getLogger(), + $server->getSecureRandom(), + \OC::$server->query(Installer::class) + ); $sysInfo = $setupHelper->getSystemInfo(true); $errors = $sysInfo['errors']; if (count($errors) > 0) { diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php index 0877c19bc016e..2a502dbe92186 100644 --- a/core/Command/Upgrade.php +++ b/core/Command/Upgrade.php @@ -35,6 +35,7 @@ namespace OC\Core\Command; use OC\Console\TimestampFormatter; +use OC\Installer; use OC\Updater; use OCP\IConfig; use OCP\ILogger; @@ -63,11 +64,13 @@ class Upgrade extends Command { /** * @param IConfig $config * @param ILogger $logger + * @param Installer $installer */ - public function __construct(IConfig $config, ILogger $logger) { + public function __construct(IConfig $config, ILogger $logger, Installer $installer) { parent::__construct(); $this->config = $config; $this->logger = $logger; + $this->installer = $installer; } protected function configure() { @@ -101,7 +104,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { $updater = new Updater( $this->config, \OC::$server->getIntegrityCodeChecker(), - $this->logger + $this->logger, + $this->installer ); if ($input->getOption('no-app-disable')) { diff --git a/core/ajax/update.php b/core/ajax/update.php index 71d60f5c432c8..2a29d1e536c14 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -116,7 +116,8 @@ public function handleRepairFeedback($event) { $updater = new \OC\Updater( $config, \OC::$server->getIntegrityCodeChecker(), - $logger + $logger, + \OC::$server->query(\OC\Installer::class) ); $incompatibleApps = []; $disabledThirdPartyApps = []; diff --git a/core/register_command.php b/core/register_command.php index 3f7fbf508e5da..60e151a5f2c16 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -137,7 +137,7 @@ $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger())); + $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); $application->add(new OC\Core\Command\Maintenance\Repair( new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getAppManager())); diff --git a/lib/base.php b/lib/base.php index dc09d0f533d4d..30f8069568009 100644 --- a/lib/base.php +++ b/lib/base.php @@ -915,9 +915,15 @@ public static function handleRequest() { // Check if Nextcloud is installed or in maintenance (update) mode if (!$systemConfig->getValue('installed', false)) { \OC::$server->getSession()->clear(); - $setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(), - \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), - \OC::$server->getSecureRandom()); + $setupHelper = new OC\Setup( + \OC::$server->getSystemConfig(), + \OC::$server->getIniWrapper(), + \OC::$server->getL10N('lib'), + \OC::$server->query(\OCP\Defaults::class), + \OC::$server->getLogger(), + \OC::$server->getSecureRandom(), + \OC::$server->query(\OC\Installer::class) + ); $controller = new OC\Core\Controller\SetupController($setupHelper); $controller->run($_POST); exit(); diff --git a/lib/private/Installer.php b/lib/private/Installer.php index e754f28455bc6..70d6c10b335ff 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -67,6 +67,10 @@ class Installer { private $logger; /** @var IConfig */ private $config; + /** @var array - for caching the result of app fetcher */ + private $apps = null; + /** @var bool|null - for caching the result of the ready status */ + private $isInstanceReadyForUpdates = null; /** * @param AppFetcher $appFetcher @@ -187,7 +191,7 @@ public static function isInstalled( $app ) { * @return bool */ public function updateAppstoreApp($appId) { - if(self::isUpdateAvailable($appId, $this->appFetcher)) { + if($this->isUpdateAvailable($appId)) { try { $this->downloadApp($appId); } catch (\Exception $e) { @@ -375,27 +379,26 @@ public function downloadApp($appId) { * Check if an update for the app is available * * @param string $appId - * @param AppFetcher $appFetcher * @return string|false false or the version number of the update */ - public static function isUpdateAvailable($appId, - AppFetcher $appFetcher) { - static $isInstanceReadyForUpdates = null; - - if ($isInstanceReadyForUpdates === null) { + public function isUpdateAvailable($appId) { + if ($this->isInstanceReadyForUpdates === null) { $installPath = OC_App::getInstallPath(); if ($installPath === false || $installPath === null) { - $isInstanceReadyForUpdates = false; + $this->isInstanceReadyForUpdates = false; } else { - $isInstanceReadyForUpdates = true; + $this->isInstanceReadyForUpdates = true; } } - if ($isInstanceReadyForUpdates === false) { + if ($this->isInstanceReadyForUpdates === false) { return false; } - $apps = $appFetcher->get(); + if ($this->apps === null) { + $apps = $this->appFetcher->get(); + } + foreach($apps as $app) { if($app['id'] === $appId) { $currentVersion = OC_App::getAppVersion($appId); diff --git a/lib/private/Server.php b/lib/private/Server.php index faa0ce2f2ac88..0c6338f6a4c87 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1099,6 +1099,16 @@ public function __construct($webRoot, \OC\Config $config) { $c->query(\OCP\Share\IManager::class) ); }); + + $this->registerService(Installer::class, function(Server $c) { + return new Installer( + $c->getAppFetcher(), + $c->getHTTPClientService(), + $c->getTempManager(), + $c->getLogger(), + $c->getConfig() + ); + }); } /** diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 8214db2d4ef85..92246e8322edf 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -65,6 +65,8 @@ class Setup { protected $logger; /** @var ISecureRandom */ protected $random; + /** @var Installer */ + protected $installer; /** * @param SystemConfig $config @@ -73,13 +75,15 @@ class Setup { * @param Defaults $defaults * @param ILogger $logger * @param ISecureRandom $random + * @param Installer $installer */ public function __construct(SystemConfig $config, IniGetWrapper $iniWrapper, IL10N $l10n, Defaults $defaults, ILogger $logger, - ISecureRandom $random + ISecureRandom $random, + Installer $installer ) { $this->config = $config; $this->iniWrapper = $iniWrapper; @@ -87,6 +91,7 @@ public function __construct(SystemConfig $config, $this->defaults = $defaults; $this->logger = $logger; $this->random = $random; + $this->installer = $installer; } static protected $dbSetupClasses = [ @@ -371,18 +376,11 @@ public function install($options) { // Install shipped apps and specified app bundles Installer::installShippedApps(); - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - \OC::$server->getLogger(), - \OC::$server->getConfig() - ); $bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib')); $defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle(); foreach($defaultInstallationBundles as $bundle) { try { - $installer->installAppBundle($bundle); + $this->installer->installAppBundle($bundle); } catch (Exception $e) {} } @@ -444,9 +442,15 @@ public static function updateHtaccess() { $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; } - $setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(), - \OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), \OC::$server->getLogger(), - \OC::$server->getSecureRandom()); + $setupHelper = new \OC\Setup( + $config, + \OC::$server->getIniWrapper(), + \OC::$server->getL10N('lib'), + \OC::$server->query(Defaults::class), + \OC::$server->getLogger(), + \OC::$server->getSecureRandom(), + \OC::$server->query(Installer::class) + ); $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n"; diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 4f5bb45ae151c..996163daacc64 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -63,6 +63,9 @@ class Updater extends BasicEmitter { /** @var Checker */ private $checker; + /** @var Installer */ + private $installer; + /** @var bool */ private $skip3rdPartyAppsDisable; @@ -78,13 +81,16 @@ class Updater extends BasicEmitter { * @param IConfig $config * @param Checker $checker * @param ILogger $log + * @param Installer $installer */ public function __construct(IConfig $config, Checker $checker, - ILogger $log = null) { + ILogger $log = null, + Installer $installer) { $this->log = $log; $this->config = $config; $this->checker = $checker; + $this->installer = $installer; // If at least PHP 7.0.0 is used we don't need to disable apps as we catch // fatal errors and exceptions and disable the app just instead. @@ -461,17 +467,10 @@ private function isCodeUpgrade() { private function upgradeAppStoreApps(array $disabledApps) { foreach($disabledApps as $app) { try { - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - $this->log, - \OC::$server->getConfig() - ); $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); - if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) { + if ($this->installer->isUpdateAvailable($app)) { $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); - $installer->updateAppstoreApp($app); + $this->installer->updateAppstoreApp($app); } $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); } catch (\Exception $ex) { diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index d2b0f96d59382..1b9fc28873e24 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -375,13 +375,7 @@ public function enable($appId, self::$enabledAppsCache = []; // flush // Check if app is already downloaded - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - \OC::$server->getLogger(), - \OC::$server->getConfig() - ); + $installer = \OC::$server->query(Installer::class); $isDownloaded = $installer->isDownloaded($appId); if(!$isDownloaded) { @@ -415,13 +409,7 @@ public static function removeApp($app) { return false; } - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - \OC::$server->getLogger(), - \OC::$server->getConfig() - ); + $installer = \OC::$server->query(Installer::class); return $installer->removeApp($app); } diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 1e9090960c139..3ce11746672fd 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -708,8 +708,15 @@ public static function checkServer(\OC\SystemConfig $config) { } $webServerRestart = false; - $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), - \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); + $setup = new \OC\Setup( + $config, + \OC::$server->getIniWrapper(), + \OC::$server->getL10N('lib'), + \OC::$server->query(\OCP\Defaults::class), + \OC::$server->getLogger(), + \OC::$server->getSecureRandom(), + \OC::$server->query(\OC\Installer::class) + ); $urlGenerator = \OC::$server->getURLGenerator(); diff --git a/settings/Controller/AppSettingsController.php b/settings/Controller/AppSettingsController.php index 26858eabcf377..f2a92b52f6d17 100644 --- a/settings/Controller/AppSettingsController.php +++ b/settings/Controller/AppSettingsController.php @@ -37,6 +37,7 @@ use OC\App\AppStore\Version\VersionParser; use OC\App\DependencyAnalyzer; use OC\App\Platform; +use OC\Installer; use OCP\App\IAppManager; use \OCP\AppFramework\Controller; use OCP\AppFramework\Http\ContentSecurityPolicy; @@ -74,6 +75,8 @@ class AppSettingsController extends Controller { private $l10nFactory; /** @var BundleFetcher */ private $bundleFetcher; + /** @var Installer */ + private $installer; /** * @param string $appName @@ -86,6 +89,7 @@ class AppSettingsController extends Controller { * @param AppFetcher $appFetcher * @param IFactory $l10nFactory * @param BundleFetcher $bundleFetcher + * @param Installer $installer */ public function __construct($appName, IRequest $request, @@ -96,7 +100,8 @@ public function __construct($appName, CategoryFetcher $categoryFetcher, AppFetcher $appFetcher, IFactory $l10nFactory, - BundleFetcher $bundleFetcher) { + BundleFetcher $bundleFetcher, + Installer $installer) { parent::__construct($appName, $request); $this->l10n = $l10n; $this->config = $config; @@ -106,6 +111,7 @@ public function __construct($appName, $this->appFetcher = $appFetcher; $this->l10nFactory = $l10nFactory; $this->bundleFetcher = $bundleFetcher; + $this->installer = $installer; } /** @@ -270,8 +276,7 @@ private function getAppsForCategory($requestedCategory) { ]; - $appFetcher = \OC::$server->getAppFetcher(); - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher); + $newVersion = $this->installer->isUpdateAvailable($app['id']); if($newVersion && $this->appManager->isInstalled($app['id'])) { $formattedApps[count($formattedApps)-1]['update'] = $newVersion; } @@ -284,7 +289,7 @@ private function getAppsWithUpdates() { $appClass = new \OC_App(); $apps = $appClass->listAllApps(); foreach($apps as $key => $app) { - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); + $newVersion = $this->installer->isUpdateAvailable($app['id']); if($newVersion !== false) { $apps[$key]['update'] = $newVersion; } else { @@ -317,7 +322,7 @@ public function listApps($category = '') { $apps = $appClass->listAllApps(); foreach($apps as $key => $app) { - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); + $newVersion = $this->installer->isUpdateAvailable($app['id']); $apps[$key]['update'] = $newVersion; } @@ -342,7 +347,7 @@ public function listApps($category = '') { }); foreach($apps as $key => $app) { - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); + $newVersion = $this->installer->isUpdateAvailable($app['id']); $apps[$key]['update'] = $newVersion; } @@ -363,7 +368,7 @@ public function listApps($category = '') { }); $apps = array_map(function ($app) { - $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher); + $newVersion = $this->installer->isUpdateAvailable($app['id']); if ($newVersion !== false) { $app['update'] = $newVersion; } diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php index 7b615cb56bb41..3431c68dbd7e5 100644 --- a/settings/ajax/updateapp.php +++ b/settings/ajax/updateapp.php @@ -41,13 +41,7 @@ $config = \OC::$server->getConfig(); $config->setSystemValue('maintenance', true); try { - $installer = new \OC\Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - \OC::$server->getLogger(), - \OC::$server->getConfig() - ); + $installer = \OC::$server->query(\OC\Installer::class); $result = $installer->updateAppstoreApp($appId); $config->setSystemValue('maintenance', false); } catch(Exception $ex) { diff --git a/tests/Settings/Controller/AppSettingsControllerTest.php b/tests/Settings/Controller/AppSettingsControllerTest.php index e264d0dfbfe06..6631873d8ada9 100644 --- a/tests/Settings/Controller/AppSettingsControllerTest.php +++ b/tests/Settings/Controller/AppSettingsControllerTest.php @@ -25,6 +25,7 @@ use OC\App\AppStore\Bundles\BundleFetcher; use OC\App\AppStore\Fetcher\AppFetcher; use OC\App\AppStore\Fetcher\CategoryFetcher; +use OC\Installer; use OC\Settings\Controller\AppSettingsController; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\JSONResponse; @@ -63,6 +64,8 @@ class AppSettingsControllerTest extends TestCase { private $l10nFactory; /** @var BundleFetcher|\PHPUnit_Framework_MockObject_MockObject */ private $bundleFetcher; + /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */ + private $installer; public function setUp() { parent::setUp(); @@ -79,6 +82,7 @@ public function setUp() { $this->appFetcher = $this->createMock(AppFetcher::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->bundleFetcher = $this->createMock(BundleFetcher::class); + $this->installer = $this->createMock(Installer::class); $this->appSettingsController = new AppSettingsController( 'settings', @@ -90,11 +94,15 @@ public function setUp() { $this->categoryFetcher, $this->appFetcher, $this->l10nFactory, - $this->bundleFetcher + $this->bundleFetcher, + $this->installer ); } public function testListCategories() { + $this->installer->expects($this->any()) + ->method('isUpdateAvailable') + ->willReturn(false); $expected = new JSONResponse([ [ 'id' => 2, diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php index 107b9dcb41fe2..897bc47210304 100644 --- a/tests/lib/InstallerTest.php +++ b/tests/lib/InstallerTest.php @@ -40,9 +40,6 @@ class InstallerTest extends TestCase { /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; - /** @var Installer */ - private $installer; - protected function setUp() { parent::setUp(); @@ -51,13 +48,6 @@ protected function setUp() { $this->tempManager = $this->createMock(ITempManager::class); $this->logger = $this->createMock(ILogger::class); $this->config = $this->createMock(IConfig::class); - $this->installer = new Installer( - $this->appFetcher, - $this->clientService, - $this->tempManager, - $this->logger, - $this->config - ); $config = \OC::$server->getConfig(); $this->appstore = $config->setSystemValue('appstoreenabled', true); @@ -72,6 +62,16 @@ protected function setUp() { $installer->removeApp(self::$appid); } + protected function getInstaller() { + return new Installer( + $this->appFetcher, + $this->clientService, + $this->tempManager, + $this->logger, + $this->config + ); + } + protected function tearDown() { $installer = new Installer( \OC::$server->getAppFetcher(), @@ -154,7 +154,8 @@ public function testIsUpdateAvailable(array $appArray, $updateAvailable) { ->method('get') ->willReturn($appArray); - $this->assertSame($updateAvailable, Installer::isUpdateAvailable('files', $this->appFetcher)); + $installer = $this->getInstaller(); + $this->assertSame($updateAvailable, $installer->isUpdateAvailable('files')); } /** @@ -197,7 +198,8 @@ public function testDownloadAppWithRevokedCertificate() { ->willReturn($appArray); - $this->installer->downloadApp('news'); + $installer = $this->getInstaller(); + $installer->downloadApp('news'); } /** @@ -239,7 +241,8 @@ public function testDownloadAppWithNotNextcloudCertificate() { ->method('get') ->willReturn($appArray); - $this->installer->downloadApp('news'); + $installer = $this->getInstaller(); + $installer->downloadApp('news'); } /** @@ -281,7 +284,8 @@ public function testDownloadAppWithDifferentCN() { ->method('get') ->willReturn($appArray); - $this->installer->downloadApp('news'); + $installer = $this->getInstaller(); + $installer->downloadApp('news'); } /** @@ -348,7 +352,8 @@ public function testDownloadAppWithInvalidSignature() { ->method('newClient') ->willReturn($client); - $this->installer->downloadApp('passman'); + $installer = $this->getInstaller(); + $installer->downloadApp('passman'); } /** @@ -431,7 +436,8 @@ public function testDownloadAppWithMoreThanOneFolderDownloaded() { ->method('newClient') ->willReturn($client); - $this->installer->downloadApp('testapp'); + $installer = $this->getInstaller(); + $installer->downloadApp('testapp'); } /** @@ -513,7 +519,8 @@ public function testDownloadAppWithMismatchingIdentifier() { ->method('newClient') ->willReturn($client); - $this->installer->downloadApp('testapp'); + $installer = $this->getInstaller(); + $installer->downloadApp('testapp'); } public function testDownloadAppSuccessful() { @@ -591,7 +598,8 @@ public function testDownloadAppSuccessful() { ->method('newClient') ->willReturn($client); - $this->installer->downloadApp('testapp'); + $installer = $this->getInstaller(); + $installer->downloadApp('testapp'); $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml')); $this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/')); @@ -679,7 +687,8 @@ public function testDownloadAppWithDowngrade() { $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml')); $this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/')); - $this->installer->downloadApp('testapp'); + $installer = $this->getInstaller(); + $installer->downloadApp('testapp'); $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml')); $this->assertEquals('0.8', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/')); } diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php index 78c35a5b0bbf3..e6e9fb5c56ce6 100644 --- a/tests/lib/SetupTest.php +++ b/tests/lib/SetupTest.php @@ -9,6 +9,7 @@ namespace Test; use bantu\IniGetWrapper\IniGetWrapper; +use OC\Installer; use OC\SystemConfig; use OCP\Defaults; use OCP\IL10N; @@ -31,6 +32,8 @@ class SetupTest extends \Test\TestCase { protected $logger; /** @var \OCP\Security\ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */ protected $random; + /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */ + protected $installer; protected function setUp() { parent::setUp(); @@ -41,9 +44,10 @@ protected function setUp() { $this->defaults = $this->createMock(Defaults::class); $this->logger = $this->createMock(ILogger::class); $this->random = $this->createMock(ISecureRandom::class); + $this->installer = $this->createMock(Installer::class); $this->setupClass = $this->getMockBuilder('\OC\Setup') ->setMethods(['class_exists', 'is_callable', 'getAvailableDbDriversForPdo']) - ->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random]) + ->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random, $this->installer]) ->getMock(); } diff --git a/tests/lib/UpdaterTest.php b/tests/lib/UpdaterTest.php index afa0635768d5b..a6a8224ac34cd 100644 --- a/tests/lib/UpdaterTest.php +++ b/tests/lib/UpdaterTest.php @@ -22,6 +22,7 @@ namespace Test; +use OC\Installer; use OC\Updater; use OCP\IConfig; use OCP\ILogger; @@ -36,6 +37,8 @@ class UpdaterTest extends TestCase { private $updater; /** @var Checker | \PHPUnit_Framework_MockObject_MockObject */ private $checker; + /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */ + private $installer; public function setUp() { parent::setUp(); @@ -46,13 +49,17 @@ public function setUp() { ->disableOriginalConstructor() ->getMock(); $this->checker = $this->getMockBuilder(Checker::class) - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); + $this->installer = $this->getMockBuilder(Installer::class) + ->disableOriginalConstructor() + ->getMock(); $this->updater = new Updater( $this->config, $this->checker, - $this->logger + $this->logger, + $this->installer ); }