Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-07-28 10:38:43 +0300
committerJoas Schilling <coding@schilljs.com>2020-07-28 10:38:43 +0300
commitbab4fb98ebd839441a0bb4cdc9413d9f1e47d355 (patch)
tree044db04763ed3f6d4ee982e62fec4f525327df58 /tests
parent4cac0f6895cf4bda4dda0b7cb3b843546eb0a952 (diff)
Fix overwriteService() for apps
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/TestCase.php15
1 files changed, 11 insertions, 4 deletions
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;
});