diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-27 15:27:18 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-27 15:27:18 +0100 |
commit | 3a7cf40aaa678bea1df143d2982d603b7a334eec (patch) | |
tree | 63c1e3ad7f7f401d14411a4d44c523632906afc9 /apps/files_external/tests | |
parent | 0568b012672d650c6b5a49e72c4028dde5463c60 (diff) | |
download | nextcloud-server-3a7cf40aaa678bea1df143d2982d603b7a334eec.tar.gz nextcloud-server-3a7cf40aaa678bea1df143d2982d603b7a334eec.zip |
Mode to modern phpunit
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_external/tests')
15 files changed, 58 insertions, 57 deletions
diff --git a/apps/files_external/tests/Auth/Password/GlobalAuth.php b/apps/files_external/tests/Auth/Password/GlobalAuth.php index 15f8f5f47a9..7c28f1b3f53 100644 --- a/apps/files_external/tests/Auth/Password/GlobalAuth.php +++ b/apps/files_external/tests/Auth/Password/GlobalAuth.php @@ -105,10 +105,10 @@ class GlobalAuthTest extends TestCase { ], $storage->getBackendOptions()); } - /** - * @expectedException \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException - */ + public function testNoCredentialsPersonal() { + $this->expectException(\OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException::class); + $this->credentialsManager->expects($this->never()) ->method('retrieve'); diff --git a/apps/files_external/tests/Config/UserPlaceholderHandlerTest.php b/apps/files_external/tests/Config/UserPlaceholderHandlerTest.php index 006bb458370..ba064b8fb6f 100644 --- a/apps/files_external/tests/Config/UserPlaceholderHandlerTest.php +++ b/apps/files_external/tests/Config/UserPlaceholderHandlerTest.php @@ -50,7 +50,7 @@ class UserPlaceholderHandlerTest extends \Test\TestCase { /** @var UserPlaceholderHandler */ protected $handler; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->user = $this->createMock(IUser::class); diff --git a/apps/files_external/tests/Controller/AjaxControllerTest.php b/apps/files_external/tests/Controller/AjaxControllerTest.php index a940f49fc2a..6bb9c3418ee 100644 --- a/apps/files_external/tests/Controller/AjaxControllerTest.php +++ b/apps/files_external/tests/Controller/AjaxControllerTest.php @@ -48,7 +48,7 @@ class AjaxControllerTest extends TestCase { /** @var AjaxController */ private $ajaxController; - public function setUp(): void { + protected function setUp(): void { $this->request = $this->createMock(IRequest::class); $this->rsa = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\PublicKey\\RSA') ->disableOriginalConstructor() diff --git a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php index bcc8d3e2d98..458714e463a 100644 --- a/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php +++ b/apps/files_external/tests/Controller/GlobalStoragesControllerTest.php @@ -34,7 +34,7 @@ use OCP\ILogger; use OCP\IRequest; class GlobalStoragesControllerTest extends StoragesControllerTest { - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->service = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService') ->disableOriginalConstructor() diff --git a/apps/files_external/tests/Controller/StoragesControllerTest.php b/apps/files_external/tests/Controller/StoragesControllerTest.php index 184b7a6c699..d865b3e8d0f 100644 --- a/apps/files_external/tests/Controller/StoragesControllerTest.php +++ b/apps/files_external/tests/Controller/StoragesControllerTest.php @@ -46,11 +46,11 @@ abstract class StoragesControllerTest extends \Test\TestCase { */ protected $service; - public function setUp(): void { + protected function setUp(): void { \OC_Mount_Config::$skipTest = true; } - public function tearDown(): void { + protected function tearDown(): void { \OC_Mount_Config::$skipTest = false; } diff --git a/apps/files_external/tests/Controller/UserStoragesControllerTest.php b/apps/files_external/tests/Controller/UserStoragesControllerTest.php index ddd6d01717e..f130af7c76f 100644 --- a/apps/files_external/tests/Controller/UserStoragesControllerTest.php +++ b/apps/files_external/tests/Controller/UserStoragesControllerTest.php @@ -42,7 +42,7 @@ class UserStoragesControllerTest extends StoragesControllerTest { */ private $oldAllowedBackends; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->service = $this->getMockBuilder('\OCA\Files_External\Service\UserStoragesService') ->disableOriginalConstructor() diff --git a/apps/files_external/tests/Service/BackendServiceTest.php b/apps/files_external/tests/Service/BackendServiceTest.php index 8cd1e680dea..526098dc2b4 100644 --- a/apps/files_external/tests/Service/BackendServiceTest.php +++ b/apps/files_external/tests/Service/BackendServiceTest.php @@ -234,9 +234,10 @@ class BackendServiceTest extends \Test\TestCase { /** * @dataProvider invalidConfigPlaceholderProvider - * @expectedException \RuntimeException */ public function testRegisterConfigHandlerInvalid(array $placeholders) { + $this->expectException(\RuntimeException::class); + $service = new BackendService($this->config); $mock = $this->createMock(IConfigHandler::class); $cb = function () use ($mock) { return $mock; }; diff --git a/apps/files_external/tests/Service/DBConfigServiceTest.php b/apps/files_external/tests/Service/DBConfigServiceTest.php index 375f1e7018a..7a04a8f61b7 100644 --- a/apps/files_external/tests/Service/DBConfigServiceTest.php +++ b/apps/files_external/tests/Service/DBConfigServiceTest.php @@ -44,13 +44,13 @@ class DBConfigServiceTest extends TestCase { private $mounts = []; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); $this->dbConfig = new DBConfigService($this->connection, \OC::$server->getCrypto()); } - public function tearDown(): void { + protected function tearDown(): void { foreach ($this->mounts as $mount) { $this->dbConfig->removeMount($mount); } diff --git a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php index c4d1055521a..37ae71696f0 100644 --- a/apps/files_external/tests/Service/GlobalStoragesServiceTest.php +++ b/apps/files_external/tests/Service/GlobalStoragesServiceTest.php @@ -33,12 +33,12 @@ use OCA\Files_External\Service\GlobalStoragesService; * @group DB */ class GlobalStoragesServiceTest extends StoragesServiceTest { - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->service = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache); } - public function tearDown(): void { + protected function tearDown(): void { @unlink($this->dataDir . '/mount.json'); parent::tearDown(); } @@ -471,8 +471,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { } } - /** - */ + public function testHooksRenameMountPoint() { $storage = $this->makeTestStorageData(); $storage->setApplicableUsers(['user1', 'user2']); diff --git a/apps/files_external/tests/Service/StoragesServiceTest.php b/apps/files_external/tests/Service/StoragesServiceTest.php index 4e2b73f2612..140bbdc772b 100644 --- a/apps/files_external/tests/Service/StoragesServiceTest.php +++ b/apps/files_external/tests/Service/StoragesServiceTest.php @@ -92,7 +92,7 @@ abstract class StoragesServiceTest extends \Test\TestCase { */ protected $mountCache; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->dbConfig = new CleaningDBConfig(\OC::$server->getDatabaseConnection(), \OC::$server->getCrypto()); self::$hookCalls = array(); @@ -175,7 +175,7 @@ abstract class StoragesServiceTest extends \Test\TestCase { ->willReturn($containerMock); } - public function tearDown(): void { + protected function tearDown(): void { \OC_Mount_Config::$skipTest = false; self::$hookCalls = array(); if ($this->dbConfig) { @@ -252,10 +252,10 @@ abstract class StoragesServiceTest extends \Test\TestCase { } - /** - * @expectedException \OCA\Files_External\NotFoundException - */ + public function testNonExistingStorage() { + $this->expectException(\OCA\Files_External\NotFoundException::class); + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $storage = new StorageConfig(255); @@ -334,10 +334,10 @@ abstract class StoragesServiceTest extends \Test\TestCase { $this->assertCount($expectedCountAfterDeletion, $storages, "expected $expectedCountAfterDeletion storages, got " . json_encode($storages)); } - /** - * @expectedException \OCA\Files_External\NotFoundException - */ + public function testDeleteUnexistingStorage() { + $this->expectException(\OCA\Files_External\NotFoundException::class); + $this->service->removeStorage(255); } diff --git a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php index 9a6100d8075..83a0d9c7fd7 100644 --- a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php +++ b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php @@ -60,7 +60,7 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { const GROUP_ID = 'test_group'; const GROUP_ID2 = 'test_group2'; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->globalStoragesService = $this->service; @@ -158,10 +158,10 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { } - /** - * @expectedException \DomainException - */ + public function testAddStorage($storageParams = null) { + $this->expectException(\DomainException::class); + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); @@ -174,10 +174,10 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { $this->service->addStorage($storage); } - /** - * @expectedException \DomainException - */ + public function testUpdateStorage($storageParams = null) { + $this->expectException(\DomainException::class); + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); @@ -194,18 +194,19 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { $this->service->updateStorage($retrievedStorage); } - /** - * @expectedException \DomainException - */ + public function testNonExistingStorage() { + $this->expectException(\DomainException::class); + parent::testNonExistingStorage(); } /** - * @expectedException \DomainException * @dataProvider deleteStorageDataProvider */ public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) { + $this->expectException(\DomainException::class); + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); @@ -221,10 +222,10 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest { $this->service->removeStorage($id); } - /** - * @expectedException \DomainException - */ + public function testDeleteUnexistingStorage() { + $this->expectException(\DomainException::class); + parent::testDeleteUnexistingStorage(); } diff --git a/apps/files_external/tests/Service/UserStoragesServiceTest.php b/apps/files_external/tests/Service/UserStoragesServiceTest.php index ce0b3ab65b1..7b9d16211e0 100644 --- a/apps/files_external/tests/Service/UserStoragesServiceTest.php +++ b/apps/files_external/tests/Service/UserStoragesServiceTest.php @@ -50,7 +50,7 @@ class UserStoragesServiceTest extends StoragesServiceTest { */ protected $globalStoragesService; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->globalStoragesService = new GlobalStoragesService($this->backendService, $this->dbConfig, $this->mountCache); @@ -189,10 +189,10 @@ class UserStoragesServiceTest extends StoragesServiceTest { ); } - /** - * @expectedException \OCA\Files_External\NotFoundException - */ + public function testGetAdminStorage() { + $this->expectException(\OCA\Files_External\NotFoundException::class); + $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php index 3889fe456e4..1d24cbbde10 100644 --- a/apps/files_external/tests/Settings/AdminTest.php +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -43,7 +43,7 @@ class AdminTest extends TestCase { /** @var GlobalAuth|\PHPUnit_Framework_MockObject_MockObject */ private $globalAuth; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->encryptionManager = $this->createMock(IManager::class); $this->globalStoragesService = $this->createMock(GlobalStoragesService::class); diff --git a/apps/files_external/tests/Settings/SectionTest.php b/apps/files_external/tests/Settings/SectionTest.php index 3a8a4f5f780..b9ce3e3aa9a 100644 --- a/apps/files_external/tests/Settings/SectionTest.php +++ b/apps/files_external/tests/Settings/SectionTest.php @@ -37,7 +37,7 @@ class SectionTest extends TestCase { /** @var Section */ private $section; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->disableOriginalConstructor()->getMock(); $this->l = $this->getMockBuilder(IL10N::class)->disableOriginalConstructor()->getMock(); diff --git a/apps/files_external/tests/Storage/SFTP_KeyTest.php b/apps/files_external/tests/Storage/SFTP_KeyTest.php index fe40c0fbd95..4e8e6431a72 100644 --- a/apps/files_external/tests/Storage/SFTP_KeyTest.php +++ b/apps/files_external/tests/Storage/SFTP_KeyTest.php @@ -60,10 +60,10 @@ class SFTP_KeyTest extends \Test\Files\Storage\Storage { parent::tearDown(); } - /** - * @expectedException InvalidArgumentException - */ + public function testInvalidAddressShouldThrowException() { + $this->expectException(\InvalidArgumentException::class); + // I'd use example.com for this, but someone decided to break the spec and make it resolve $this->instance->assertHostAddressValid('notarealaddress...'); } @@ -72,24 +72,24 @@ class SFTP_KeyTest extends \Test\Files\Storage\Storage { $this->assertTrue($this->instance->assertHostAddressValid('localhost')); } - /** - * @expectedException InvalidArgumentException - */ + public function testNegativePortNumberShouldThrowException() { + $this->expectException(\InvalidArgumentException::class); + $this->instance->assertPortNumberValid('-1'); } - /** - * @expectedException InvalidArgumentException - */ + public function testNonNumericalPortNumberShouldThrowException() { + $this->expectException(\InvalidArgumentException::class); + $this->instance->assertPortNumberValid('a'); } - /** - * @expectedException InvalidArgumentException - */ - public function testHighPortNumberShouldThrowException() { + + public function testHighPortNumberShouldThrowException() { + $this->expectException(\InvalidArgumentException::class); + $this->instance->assertPortNumberValid('65536'); } |