public function setUp() { self::$hookCalls = array(); $config = \OC::$server->getConfig(); $this->dataDir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/'); \OC_Mount_Config::$skipTest = true; // prepare BackendService mock $this->backendService = $this->getMockBuilder('\\OCA\\Files_External\\Service\\BackendService')->disableOriginalConstructor()->getMock(); $authMechanisms = ['identifier:\\Auth\\Mechanism' => $this->getAuthMechMock('null', '\\Auth\\Mechanism'), 'identifier:\\Other\\Auth\\Mechanism' => $this->getAuthMechMock('null', '\\Other\\Auth\\Mechanism'), 'identifier:\\OCA\\Files_External\\Lib\\Auth\\NullMechanism' => $this->getAuthMechMock()]; $this->backendService->method('getAuthMechanism')->will($this->returnCallback(function ($class) use($authMechanisms) { if (isset($authMechanisms[$class])) { return $authMechanisms[$class]; } return null; })); $this->backendService->method('getAuthMechanismsByScheme')->will($this->returnCallback(function ($schemes) use($authMechanisms) { return array_filter($authMechanisms, function ($authMech) use($schemes) { return in_array($authMech->getScheme(), $schemes, true); }); })); $this->backendService->method('getAuthMechanisms')->will($this->returnValue($authMechanisms)); $sftpBackend = $this->getBackendMock('\\OCA\\Files_External\\Lib\\Backend\\SFTP', '\\OC\\Files\\Storage\\SFTP'); $backends = ['identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB' => $this->getBackendMock('\\OCA\\Files_External\\Lib\\Backend\\SMB', '\\OC\\Files\\Storage\\SMB'), 'identifier:\\OCA\\Files_External\\Lib\\Backend\\SFTP' => $sftpBackend, 'identifier:sftp_alias' => $sftpBackend]; $backends['identifier:\\OCA\\Files_External\\Lib\\Backend\\SFTP']->method('getLegacyAuthMechanism')->willReturn($authMechanisms['identifier:\\Other\\Auth\\Mechanism']); $this->backendService->method('getBackend')->will($this->returnCallback(function ($backendClass) use($backends) { if (isset($backends[$backendClass])) { return $backends[$backendClass]; } return null; })); $this->backendService->method('getBackends')->will($this->returnValue($backends)); \OCP\Util::connectHook(Filesystem::CLASSNAME, Filesystem::signal_create_mount, get_class($this), 'createHookCallback'); \OCP\Util::connectHook(Filesystem::CLASSNAME, Filesystem::signal_delete_mount, get_class($this), 'deleteHookCallback'); $containerMock = $this->getMock('\\OCP\\AppFramework\\IAppContainer'); $containerMock->method('query')->will($this->returnCallback(function ($name) { if ($name === 'OCA\\Files_External\\Service\\BackendService') { return $this->backendService; } })); \OC_Mount_Config::$app = $this->getMockBuilder('\\OCA\\Files_External\\Appinfo\\Application')->disableOriginalConstructor()->getMock(); \OC_Mount_Config::$app->method('getContainer')->willReturn($containerMock); }