aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2020-07-28 18:37:35 +0200
committerGitHub <noreply@github.com>2020-07-28 18:37:35 +0200
commit4824e5e1a737068d9781e55d309c1563714938fc (patch)
tree14f7f400a523b5fb1e1fc39352bec8486194907b
parent6c176b064c3060bef98f5adeb19d668acd4ec234 (diff)
parentbab4fb98ebd839441a0bb4cdc9413d9f1e47d355 (diff)
downloadnextcloud-server-4824e5e1a737068d9781e55d309c1563714938fc.tar.gz
nextcloud-server-4824e5e1a737068d9781e55d309c1563714938fc.zip
Merge pull request #22027 from nextcloud/bugfix/noid/fix-overwrite-service-for-apps
Fix overwriteService() for apps
-rw-r--r--lib/private/ServerContainer.php7
-rw-r--r--tests/lib/TestCase.php15
2 files changed, 17 insertions, 5 deletions
diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php
index b1bf38265b8..72275ac1205 100644
--- a/lib/private/ServerContainer.php
+++ b/lib/private/ServerContainer.php
@@ -156,7 +156,12 @@ class ServerContainer extends SimpleContainer {
return parent::query($name, $autoload);
}
- private function getAppContainerForService(string $id): ?DIContainer {
+ /**
+ * @internal
+ * @param string $id
+ * @return DIContainer|null
+ */
+ public function getAppContainerForService(string $id): ?DIContainer {
if (strpos($id, 'OCA\\') !== 0 || substr_count($id, '\\') < 2) {
return null;
}
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 88c5b468543..38cfc4a1c8f 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -51,13 +51,16 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
* @param mixed $newService
* @return bool
*/
- public function overwriteService($name, $newService) {
+ public function overwriteService(string $name, $newService): bool {
if (isset($this->services[$name])) {
return false;
}
$this->services[$name] = \OC::$server->query($name);
- \OC::$server->registerService($name, function () use ($newService) {
+ $container = \OC::$server->getAppContainerForService($name);
+ $container = $container ?? \OC::$server;
+
+ $container->registerService($name, function () use ($newService) {
return $newService;
});
@@ -68,10 +71,14 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
* @param string $name
* @return bool
*/
- public function restoreService($name) {
+ public function restoreService(string $name): bool {
if (isset($this->services[$name])) {
$oldService = $this->services[$name];
- \OC::$server->registerService($name, function () use ($oldService) {
+
+ $container = \OC::$server->getAppContainerForService($name);
+ $container = $container ?? \OC::$server;
+
+ $container->registerService($name, function () use ($oldService) {
return $oldService;
});