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/dav/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/dav/tests')
85 files changed, 485 insertions, 472 deletions
diff --git a/apps/dav/tests/unit/Avatars/AvatarHomeTest.php b/apps/dav/tests/unit/Avatars/AvatarHomeTest.php index e5a2bfa862f..4a8d9895dd7 100644 --- a/apps/dav/tests/unit/Avatars/AvatarHomeTest.php +++ b/apps/dav/tests/unit/Avatars/AvatarHomeTest.php @@ -40,17 +40,18 @@ class AvatarHomeTest extends TestCase { /** @var IAvatarManager | \PHPUnit_Framework_MockObject_MockObject */ private $avatarManager; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->avatarManager = $this->createMock(IAvatarManager::class); $this->home = new AvatarHome(['uri' => 'principals/users/admin'], $this->avatarManager); } /** - * @expectedException \Sabre\DAV\Exception\Forbidden * @dataProvider providesForbiddenMethods */ public function testForbiddenMethods($method) { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->home->$method(''); } diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index 3facbeb954d..8772f511486 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -72,7 +72,7 @@ abstract class AbstractCalDavBackend extends TestCase { const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group'; const UNIT_TEST_GROUP2 = 'principals/groups/caldav-unit-test-group2'; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->userManager = $this->createMock(IUserManager::class); @@ -106,7 +106,7 @@ abstract class AbstractCalDavBackend extends TestCase { $this->cleanUpBackend(); } - public function tearDown(): void { + protected function tearDown(): void { $this->cleanUpBackend(); parent::tearDown(); } diff --git a/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php b/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php index 4d5bcea9966..a09cbed4fce 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php @@ -56,7 +56,7 @@ class GenericTest extends TestCase { public function testGetIdentifier($filterClass) { /** @var IFilter $filter */ $filter = \OC::$server->query($filterClass); - $this->assertInternalType('string', $filter->getIdentifier()); + $this->assertIsString($filter->getIdentifier()); } /** @@ -66,7 +66,7 @@ class GenericTest extends TestCase { public function testGetName($filterClass) { /** @var IFilter $filter */ $filter = \OC::$server->query($filterClass); - $this->assertInternalType('string', $filter->getName()); + $this->assertIsString($filter->getName()); } /** @@ -77,7 +77,7 @@ class GenericTest extends TestCase { /** @var IFilter $filter */ $filter = \OC::$server->query($filterClass); $priority = $filter->getPriority(); - $this->assertInternalType('int', $filter->getPriority()); + $this->assertIsInt($filter->getPriority()); $this->assertGreaterThanOrEqual(0, $priority); $this->assertLessThanOrEqual(100, $priority); } @@ -89,7 +89,7 @@ class GenericTest extends TestCase { public function testGetIcon($filterClass) { /** @var IFilter $filter */ $filter = \OC::$server->query($filterClass); - $this->assertInternalType('string', $filter->getIcon()); + $this->assertIsString($filter->getIcon()); $this->assertStringStartsWith('http', $filter->getIcon()); } @@ -100,7 +100,7 @@ class GenericTest extends TestCase { public function testFilterTypes($filterClass) { /** @var IFilter $filter */ $filter = \OC::$server->query($filterClass); - $this->assertInternalType('array', $filter->filterTypes([])); + $this->assertIsArray($filter->filterTypes([])); } /** @@ -110,6 +110,6 @@ class GenericTest extends TestCase { public function testAllowedApps($filterClass) { /** @var IFilter $filter */ $filter = \OC::$server->query($filterClass); - $this->assertInternalType('array', $filter->allowedApps()); + $this->assertIsArray($filter->allowedApps()); } } diff --git a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php index 64f9b6f86af..2f48b359659 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php @@ -113,10 +113,11 @@ class BaseTest extends TestCase { /** * @dataProvider dataGenerateObjectParameterThrows - * @expectedException \InvalidArgumentException * @param mixed $eventData */ public function testGenerateObjectParameterThrows($eventData) { + $this->expectException(\InvalidArgumentException::class); + $this->invokePrivate($this->provider, 'generateObjectParameter', [$eventData]); } diff --git a/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php b/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php index 73ddebeccce..ebc4f19c7d8 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php @@ -55,7 +55,7 @@ class GenericTest extends TestCase { public function testGetIdentifier($settingClass) { /** @var ISetting $setting */ $setting = \OC::$server->query($settingClass); - $this->assertInternalType('string', $setting->getIdentifier()); + $this->assertIsString($setting->getIdentifier()); } /** @@ -65,7 +65,7 @@ class GenericTest extends TestCase { public function testGetName($settingClass) { /** @var ISetting $setting */ $setting = \OC::$server->query($settingClass); - $this->assertInternalType('string', $setting->getName()); + $this->assertIsString($setting->getName()); } /** @@ -76,7 +76,7 @@ class GenericTest extends TestCase { /** @var ISetting $setting */ $setting = \OC::$server->query($settingClass); $priority = $setting->getPriority(); - $this->assertInternalType('int', $setting->getPriority()); + $this->assertIsInt($setting->getPriority()); $this->assertGreaterThanOrEqual(0, $priority); $this->assertLessThanOrEqual(100, $priority); } @@ -88,7 +88,7 @@ class GenericTest extends TestCase { public function testCanChangeStream($settingClass) { /** @var ISetting $setting */ $setting = \OC::$server->query($settingClass); - $this->assertInternalType('bool', $setting->canChangeStream()); + $this->assertIsBool($setting->canChangeStream()); } /** @@ -98,7 +98,7 @@ class GenericTest extends TestCase { public function testIsDefaultEnabledStream($settingClass) { /** @var ISetting $setting */ $setting = \OC::$server->query($settingClass); - $this->assertInternalType('bool', $setting->isDefaultEnabledStream()); + $this->assertIsBool($setting->isDefaultEnabledStream()); } /** @@ -108,7 +108,7 @@ class GenericTest extends TestCase { public function testCanChangeMail($settingClass) { /** @var ISetting $setting */ $setting = \OC::$server->query($settingClass); - $this->assertInternalType('bool', $setting->canChangeMail()); + $this->assertIsBool($setting->canChangeMail()); } /** @@ -118,6 +118,6 @@ class GenericTest extends TestCase { public function testIsDefaultEnabledMail($settingClass) { /** @var ISetting $setting */ $setting = \OC::$server->query($settingClass); - $this->assertInternalType('bool', $setting->isDefaultEnabledMail()); + $this->assertIsBool($setting->isDefaultEnabledMail()); } } diff --git a/apps/dav/tests/unit/CalDAV/BirthdayCalendar/EnablePluginTest.php b/apps/dav/tests/unit/CalDAV/BirthdayCalendar/EnablePluginTest.php index d2935850e51..26b126ed8a7 100644 --- a/apps/dav/tests/unit/CalDAV/BirthdayCalendar/EnablePluginTest.php +++ b/apps/dav/tests/unit/CalDAV/BirthdayCalendar/EnablePluginTest.php @@ -46,7 +46,7 @@ class EnablePluginTest extends TestCase { protected $response; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = $this->createMock(\Sabre\DAV\Server::class); diff --git a/apps/dav/tests/unit/CalDAV/CachedSubscriptionObjectTest.php b/apps/dav/tests/unit/CalDAV/CachedSubscriptionObjectTest.php index 7d4463c81b4..57931549019 100644 --- a/apps/dav/tests/unit/CalDAV/CachedSubscriptionObjectTest.php +++ b/apps/dav/tests/unit/CalDAV/CachedSubscriptionObjectTest.php @@ -52,11 +52,11 @@ class CachedSubscriptionObjectTest extends \Test\TestCase { $this->assertEquals('BEGIN...', $calendarObject->get()); } - /** - * @expectedException \Sabre\DAV\Exception\MethodNotAllowed - * @expectedExceptionMessage Creating objects in a cached subscription is not allowed - */ + public function testPut() { + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); + $this->expectExceptionMessage('Creating objects in a cached subscription is not allowed'); + $backend = $this->createMock(CalDavBackend::class); $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', @@ -72,11 +72,11 @@ class CachedSubscriptionObjectTest extends \Test\TestCase { $calendarObject->put(''); } - /** - * @expectedException \Sabre\DAV\Exception\MethodNotAllowed - * @expectedExceptionMessage Deleting objects in a cached subscription is not allowed - */ + public function testDelete() { + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); + $this->expectExceptionMessage('Deleting objects in a cached subscription is not allowed'); + $backend = $this->createMock(CalDavBackend::class); $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', diff --git a/apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php b/apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php index 82f9af364da..4143cd6a4fe 100644 --- a/apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php +++ b/apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php @@ -140,11 +140,11 @@ class CachedSubscriptionTest extends \Test\TestCase { $calendar->propPatch($propPatch); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - * @expectedExceptionMessage Calendar object not found - */ + public function testGetChild() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->expectExceptionMessage('Calendar object not found'); + $backend = $this->createMock(CalDavBackend::class); $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', @@ -235,11 +235,11 @@ class CachedSubscriptionTest extends \Test\TestCase { $this->assertInstanceOf(CachedSubscriptionObject::class, $res[1]); } - /** - * @expectedException \Sabre\DAV\Exception\MethodNotAllowed - * @expectedExceptionMessage Creating objects in cached subscription is not allowed - */ + public function testCreateFile() { + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); + $this->expectExceptionMessage('Creating objects in cached subscription is not allowed'); + $backend = $this->createMock(CalDavBackend::class); $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index 9a65b7c70c5..2c7e5bef56d 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -279,11 +279,11 @@ EOD; $this->assertCount(0, $calendarObjects); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage Calendar object with uid already exists in this calendar collection. - */ + public function testMultipleCalendarObjectsWithSameUID() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('Calendar object with uid already exists in this calendar collection.'); + $calendarId = $this->createTestCalendar(); $calData = <<<'EOD' diff --git a/apps/dav/tests/unit/CalDAV/CalendarHomeTest.php b/apps/dav/tests/unit/CalDAV/CalendarHomeTest.php index c93e436b1a1..913c7aa985a 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarHomeTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarHomeTest.php @@ -68,11 +68,11 @@ class CalendarHomeTest extends TestCase { $this->calendarHome->createExtendedCollection('name123', $mkCol); } - /** - * @expectedException \Sabre\DAV\Exception\MethodNotAllowed - * @expectedExceptionMessage The resource you tried to create has a reserved name - */ + public function testCreateCalendarReservedName() { + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); + $this->expectExceptionMessage('The resource you tried to create has a reserved name'); + /** @var MkCol | \PHPUnit_Framework_MockObject_MockObject $mkCol */ $mkCol = $this->createMock(MkCol::class); diff --git a/apps/dav/tests/unit/CalDAV/CalendarTest.php b/apps/dav/tests/unit/CalDAV/CalendarTest.php index 8af6524b8aa..7b3baad5127 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarTest.php @@ -43,7 +43,7 @@ class CalendarTest extends TestCase { /** @var IConfig */ protected $config; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor()->getMock(); @@ -73,10 +73,10 @@ class CalendarTest extends TestCase { $c->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDeleteFromGroup() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->never())->method('updateShares'); diff --git a/apps/dav/tests/unit/CalDAV/PluginTest.php b/apps/dav/tests/unit/CalDAV/PluginTest.php index 65b135cf905..e91c0e8391e 100644 --- a/apps/dav/tests/unit/CalDAV/PluginTest.php +++ b/apps/dav/tests/unit/CalDAV/PluginTest.php @@ -30,7 +30,7 @@ class PluginTest extends TestCase { /** @var Plugin */ private $plugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->plugin = new Plugin(); diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php index 0bbfe997304..516ced5e0e7 100644 --- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php @@ -72,7 +72,7 @@ class PublicCalendarRootTest extends TestCase { /** @var ILogger */ private $logger; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $db = \OC::$server->getDatabaseConnection(); @@ -108,7 +108,7 @@ class PublicCalendarRootTest extends TestCase { $this->l10n, $this->config); } - public function tearDown(): void { + protected function tearDown(): void { parent::tearDown(); if (is_null($this->backend)) { diff --git a/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php b/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php index 728905e6e6c..3de178fe491 100644 --- a/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php +++ b/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php @@ -48,7 +48,7 @@ class PluginTest extends TestCase { /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject */ private $urlGenerator; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->config = $this->getMockBuilder(IConfig::class)-> diff --git a/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php b/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php index 9ba3b15b23c..ba63c415c31 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php @@ -42,7 +42,7 @@ class BackendTest extends TestCase { /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ private $timeFactory; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $query = self::$realDatabase->getQueryBuilder(); diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php index 305cf4866db..87d29e603c5 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php @@ -68,7 +68,7 @@ abstract class AbstractNotificationProviderTest extends TestCase { */ protected $user; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->logger = $this->createMock(ILogger::class); diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php index 2654ac8b45c..f2fcb21fbf8 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php @@ -61,7 +61,7 @@ class EmailProviderTest extends AbstractNotificationProviderTest { /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */ private $mailer; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->mailer = $this->createMock(IMailer::class); diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php index c2a95278b3f..3c2f175fdcb 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php @@ -61,7 +61,7 @@ class PushProviderTest extends AbstractNotificationProviderTest { /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ private $timeFactory; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->config = $this->createMock(IConfig::class); diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php index 9eecc37fb1a..7006e17dd8b 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php @@ -41,7 +41,7 @@ class NotificationProviderManagerTest extends TestCase { /** * @throws \OCP\AppFramework\QueryException */ - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->providerManager = new NotificationProviderManager(); @@ -49,22 +49,24 @@ class NotificationProviderManagerTest extends TestCase { } /** - * @expectedException OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException - * @expectedExceptionMessage Type NOT EXISTENT is not an accepted type of notification * @throws ProviderNotAvailableException * @throws NotificationTypeDoesNotExistException */ public function testGetProviderForUnknownType(): void{ + $this->expectException(\OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException::class); + $this->expectExceptionMessage('Type NOT EXISTENT is not an accepted type of notification'); + $this->providerManager->getProvider('NOT EXISTENT'); } /** - * @expectedException OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException - * @expectedExceptionMessage No notification provider for type AUDIO available * @throws NotificationTypeDoesNotExistException * @throws ProviderNotAvailableException */ public function testGetProviderForUnRegisteredType(): void{ + $this->expectException(\OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException::class); + $this->expectExceptionMessage('No notification provider for type AUDIO available'); + $this->providerManager->getProvider('AUDIO'); } @@ -80,11 +82,12 @@ class NotificationProviderManagerTest extends TestCase { } /** - * @expectedExceptionMessage Invalid notification provider registered - * @expectedException \InvalidArgumentException * @throws \OCP\AppFramework\QueryException */ public function testRegisterBadProvider(): void{ + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid notification provider registered'); + $this->providerManager->registerProvider(Capabilities::class); } diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php index 6bb6a8be1c8..6d64f2615de 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php @@ -98,12 +98,12 @@ class NotifierTest extends TestCase { $this->assertEquals($this->notifier->getName(), 'Calendar'); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Notification not from this app - */ + public function testPrepareWrongApp(): void { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Notification not from this app'); + /** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ $notification = $this->createMock(INotification::class); @@ -116,11 +116,11 @@ class NotifierTest extends TestCase { $this->notifier->prepare($notification, 'en'); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown subject - */ + public function testPrepareWrongSubject() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown subject'); + /** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ $notification = $this->createMock(INotification::class); diff --git a/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php b/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php index 503478acc01..177a86ebab9 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php @@ -184,7 +184,7 @@ END:VEVENT END:VCALENDAR EOD; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->backend = $this->createMock(Backend::class); diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php index 5f59af260c1..9b2e3d32232 100644 --- a/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php @@ -64,7 +64,7 @@ abstract class AbstractPrincipalBackendTest extends TestCase { /** @var string */ protected $expectedCUType; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->userSession = $this->createMock(IUserSession::class); diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php index 5d9e3e8455c..0bbe5a7c557 100644 --- a/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php @@ -25,7 +25,7 @@ namespace OCA\DAV\Tests\unit\CalDAV\ResourceBooking; use OCA\DAV\CalDAV\ResourceBooking\ResourcePrincipalBackend; Class ResourcePrincipalBackendTest extends AbstractPrincipalBackendTest { - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->principalBackend = new ResourcePrincipalBackend(self::$realDatabase, diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php index 34fa8e38f14..357f381c878 100644 --- a/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/RoomPrincipalBackendTest.php @@ -25,7 +25,7 @@ namespace OCA\DAV\Tests\unit\CalDAV\ResourceBooking; use OCA\DAV\CalDAV\ResourceBooking\RoomPrincipalBackend; Class RoomPrincipalBackendTest extends AbstractPrincipalBackendTest { - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->principalBackend = new RoomPrincipalBackend(self::$realDatabase, diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php index 58342db12f2..44022a2b114 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php @@ -48,7 +48,7 @@ use Test\TestCase; class IMipPluginTest extends TestCase { - public function setUp(): void { + protected function setUp(): void { $this->mailMessage = $this->createMock(IMessage::class); $this->mailMessage->method('setFrom')->willReturn($this->mailMessage); $this->mailMessage->method('setReplyTo')->willReturn($this->mailMessage); diff --git a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php index a489839fc82..f75580142a3 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php @@ -36,7 +36,7 @@ class PluginTest extends TestCase { /** @var Server|\PHPUnit_Framework_MockObject_MockObject */ private $server; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = $this->createMock(Server::class); diff --git a/apps/dav/tests/unit/CalDAV/Search/Request/CalendarSearchReportTest.php b/apps/dav/tests/unit/CalDAV/Search/Request/CalendarSearchReportTest.php index 30cf768feab..d62c2528ca9 100644 --- a/apps/dav/tests/unit/CalDAV/Search/Request/CalendarSearchReportTest.php +++ b/apps/dav/tests/unit/CalDAV/Search/Request/CalendarSearchReportTest.php @@ -131,11 +131,11 @@ XML; ); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage {http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter given without any {http://nextcloud.com/ns}comp-filter - */ + public function testRequiresCompFilter() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter given without any {http://nextcloud.com/ns}comp-filter'); + $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> @@ -158,11 +158,11 @@ XML; $this->parse($xml); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage The {http://nextcloud.com/ns}filter element is required for this request - */ + public function testRequiresFilter() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('The {http://nextcloud.com/ns}filter element is required for this request'); + $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> @@ -176,11 +176,11 @@ XML; $this->parse($xml); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage {http://nextcloud.com/ns}search-term is required for this request - */ + public function testNoSearchTerm() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('{http://nextcloud.com/ns}search-term is required for this request'); + $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> @@ -204,11 +204,11 @@ XML; $this->parse($xml); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage At least one{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter is required for this request - */ + public function testCompOnly() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('At least one{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter is required for this request'); + $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> diff --git a/apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php b/apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php index e0cdfaf732f..65a225646e2 100644 --- a/apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php @@ -36,7 +36,7 @@ class SearchPluginTest extends TestCase { /** @var \OCA\DAV\CalDAV\Search\SearchPlugin $plugin */ protected $plugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = $this->createMock(\Sabre\DAV\Server::class); diff --git a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php index 02468e9686f..f3abfbbde9e 100644 --- a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php +++ b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php @@ -55,7 +55,7 @@ class AddressBookImplTest extends TestCase { /** @var VCard | \PHPUnit_Framework_MockObject_MockObject */ private $vCard; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->addressBookInfo = [ diff --git a/apps/dav/tests/unit/CardDAV/AddressBookTest.php b/apps/dav/tests/unit/CardDAV/AddressBookTest.php index 8fa6023f0d2..e801eb22b53 100644 --- a/apps/dav/tests/unit/CardDAV/AddressBookTest.php +++ b/apps/dav/tests/unit/CardDAV/AddressBookTest.php @@ -51,10 +51,10 @@ class AddressBookTest extends TestCase { $c->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDeleteFromGroup() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + /** @var \PHPUnit_Framework_MockObject_MockObject | CardDavBackend $backend */ $backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->never())->method('updateShares'); @@ -73,10 +73,10 @@ class AddressBookTest extends TestCase { $c->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testPropPatch() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + /** @var \PHPUnit_Framework_MockObject_MockObject | CardDavBackend $backend */ $backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock(); $calendarInfo = [ diff --git a/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php b/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php index 6bfda95a70e..82333143958 100644 --- a/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php +++ b/apps/dav/tests/unit/CardDAV/BirthdayServiceTest.php @@ -52,7 +52,7 @@ class BirthdayServiceTest extends TestCase { /** @var IL10N | \PHPUnit_Framework_MockObject_MockObject */ private $l10n; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->calDav = $this->createMock(CalDavBackend::class); diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index adc6df952ac..f2a85cb9dbb 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -121,7 +121,7 @@ class CardDavBackendTest extends TestCase { 'N:TestNoUID;;;;'.PHP_EOL. 'END:VCARD'; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->userManager = $this->createMock(IUserManager::class); @@ -159,7 +159,7 @@ class CardDavBackendTest extends TestCase { $this->tearDown(); } - public function tearDown(): void { + protected function tearDown(): void { parent::tearDown(); if (is_null($this->backend)) { @@ -631,10 +631,10 @@ class CardDavBackendTest extends TestCase { $this->invokePrivate($this->backend, 'getCardId', [1, 'uri'])); } - /** - * @expectedException InvalidArgumentException - */ + public function testGetCardIdFailed() { + $this->expectException(\InvalidArgumentException::class); + $this->invokePrivate($this->backend, 'getCardId', [1, 'uri']); } @@ -784,10 +784,10 @@ class CardDavBackendTest extends TestCase { $this->assertSame('uri', $this->backend->getCardUri($id)); } - /** - * @expectedException InvalidArgumentException - */ + public function testGetCardUriFailed() { + $this->expectException(\InvalidArgumentException::class); + $this->backend->getCardUri(1); } diff --git a/apps/dav/tests/unit/CardDAV/ConverterTest.php b/apps/dav/tests/unit/CardDAV/ConverterTest.php index 8484d3447f2..e308bd71cfc 100644 --- a/apps/dav/tests/unit/CardDAV/ConverterTest.php +++ b/apps/dav/tests/unit/CardDAV/ConverterTest.php @@ -39,7 +39,7 @@ class ConverterTest extends TestCase { /** @var AccountManager | PHPUnit_Framework_MockObject_MockObject */ private $accountManager; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->accountManager = $this->createMock(AccountManager::class); diff --git a/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php b/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php index 3fee2bcc827..d7f8ce5d159 100644 --- a/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php +++ b/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php @@ -53,7 +53,7 @@ class ImageExportPluginTest extends TestCase { /** @var PhotoCache|\PHPUnit_Framework_MockObject_MockObject */ private $cache; - function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->request = $this->createMock(RequestInterface::class); diff --git a/apps/dav/tests/unit/CardDAV/Sharing/PluginTest.php b/apps/dav/tests/unit/CardDAV/Sharing/PluginTest.php index 105612b5cb9..1cb7bc31f2f 100644 --- a/apps/dav/tests/unit/CardDAV/Sharing/PluginTest.php +++ b/apps/dav/tests/unit/CardDAV/Sharing/PluginTest.php @@ -44,7 +44,7 @@ class PluginTest extends TestCase { /** @var IShareable | \PHPUnit_Framework_MockObject_MockObject */ private $book; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); /** @var Auth | \PHPUnit_Framework_MockObject_MockObject $authBackend */ diff --git a/apps/dav/tests/unit/Command/ListCalendarsTest.php b/apps/dav/tests/unit/Command/ListCalendarsTest.php index 9cd02805133..0b381857573 100644 --- a/apps/dav/tests/unit/Command/ListCalendarsTest.php +++ b/apps/dav/tests/unit/Command/ListCalendarsTest.php @@ -58,11 +58,11 @@ class ListCalendarsTest extends TestCase { ); } - /** - * @expectedException InvalidArgumentException - */ + public function testWithBadUser() { + $this->expectException(\InvalidArgumentException::class); + $this->userManager->expects($this->once()) ->method('userExists') ->with(self::USERNAME) diff --git a/apps/dav/tests/unit/Command/MoveCalendarTest.php b/apps/dav/tests/unit/Command/MoveCalendarTest.php index 50c1a57e0a8..c097427b239 100644 --- a/apps/dav/tests/unit/Command/MoveCalendarTest.php +++ b/apps/dav/tests/unit/Command/MoveCalendarTest.php @@ -89,12 +89,13 @@ class MoveCalendarTest extends TestCase { /** * @dataProvider dataExecute * - * @expectedException InvalidArgumentException * @param $userOriginExists * @param $userDestinationExists */ public function testWithBadUserOrigin($userOriginExists, $userDestinationExists) { + $this->expectException(\InvalidArgumentException::class); + $this->userManager->expects($this->at(0)) ->method('userExists') ->with('user') @@ -115,12 +116,12 @@ class MoveCalendarTest extends TestCase { ]); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user. - */ + public function testMoveWithInexistantCalendar() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user.'); + $this->userManager->expects($this->at(0)) ->method('userExists') ->with('user') @@ -143,12 +144,12 @@ class MoveCalendarTest extends TestCase { ]); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage User <user2> already has a calendar named <personal>. - */ + public function testMoveWithExistingDestinationCalendar() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('User <user2> already has a calendar named <personal>.'); + $this->userManager->expects($this->at(0)) ->method('userExists') ->with('user') diff --git a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php index 1e415ceafca..7847273c975 100644 --- a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php +++ b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php @@ -37,7 +37,7 @@ use Test\TestCase; */ class RemoveInvalidSharesTest extends TestCase { - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $db = \OC::$server->getDatabaseConnection(); diff --git a/apps/dav/tests/unit/Comments/CommentsNodeTest.php b/apps/dav/tests/unit/Comments/CommentsNodeTest.php index 3c230ccfd43..b709fd01e01 100644 --- a/apps/dav/tests/unit/Comments/CommentsNodeTest.php +++ b/apps/dav/tests/unit/Comments/CommentsNodeTest.php @@ -47,7 +47,7 @@ class CommentsNodeTest extends \Test\TestCase { protected $logger; protected $userSession; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->commentsManager = $this->getMockBuilder(ICommentsManager::class) @@ -107,10 +107,10 @@ class CommentsNodeTest extends \Test\TestCase { $this->node->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDeleteForbidden() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $user = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -149,10 +149,10 @@ class CommentsNodeTest extends \Test\TestCase { $this->assertSame($this->node->getName(), $id); } - /** - * @expectedException \Sabre\DAV\Exception\MethodNotAllowed - */ + public function testSetName() { + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); + $this->node->setName('666'); } @@ -194,11 +194,11 @@ class CommentsNodeTest extends \Test\TestCase { $this->assertTrue($this->node->updateComment($msg)); } - /** - * @expectedException \Exception - * @expectedExceptionMessage buh! - */ + public function testUpdateCommentLogException() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('buh!'); + $msg = null; $user = $this->getMockBuilder(IUser::class) @@ -235,11 +235,11 @@ class CommentsNodeTest extends \Test\TestCase { $this->node->updateComment($msg); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage Message exceeds allowed character limit of - */ + public function testUpdateCommentMessageTooLongException() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('Message exceeds allowed character limit of'); + $user = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -274,10 +274,10 @@ class CommentsNodeTest extends \Test\TestCase { $this->node->updateComment('foo'); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testUpdateForbiddenByUser() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $msg = 'HaXX0r'; $user = $this->getMockBuilder(IUser::class) @@ -309,10 +309,10 @@ class CommentsNodeTest extends \Test\TestCase { $this->node->updateComment($msg); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testUpdateForbiddenByType() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $msg = 'HaXX0r'; $user = $this->getMockBuilder(IUser::class) @@ -339,10 +339,10 @@ class CommentsNodeTest extends \Test\TestCase { $this->node->updateComment($msg); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testUpdateForbiddenByNotLoggedIn() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $msg = 'HaXX0r'; $this->userSession->expects($this->once()) diff --git a/apps/dav/tests/unit/Comments/CommentsPluginTest.php b/apps/dav/tests/unit/Comments/CommentsPluginTest.php index 537989d9404..6cf23d1d42e 100644 --- a/apps/dav/tests/unit/Comments/CommentsPluginTest.php +++ b/apps/dav/tests/unit/Comments/CommentsPluginTest.php @@ -54,7 +54,7 @@ class CommentsPluginTest extends \Test\TestCase { /** @var CommentsPluginImplementation */ private $plugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->tree = $this->getMockBuilder(Tree::class) ->disableOriginalConstructor() @@ -170,10 +170,10 @@ class CommentsPluginTest extends \Test\TestCase { $this->plugin->httpPost($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testCreateCommentInvalidObject() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $commentData = [ 'actorType' => 'users', 'verb' => 'comment', @@ -252,10 +252,10 @@ class CommentsPluginTest extends \Test\TestCase { $this->plugin->httpPost($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - */ + public function testCreateCommentInvalidActor() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $commentData = [ 'actorType' => 'robots', 'verb' => 'comment', @@ -340,10 +340,10 @@ class CommentsPluginTest extends \Test\TestCase { $this->plugin->httpPost($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\UnsupportedMediaType - */ + public function testCreateCommentUnsupportedMediaType() { + $this->expectException(\Sabre\DAV\Exception\UnsupportedMediaType::class); + $commentData = [ 'actorType' => 'users', 'verb' => 'comment', @@ -428,10 +428,10 @@ class CommentsPluginTest extends \Test\TestCase { $this->plugin->httpPost($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - */ + public function testCreateCommentInvalidPayload() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $commentData = [ 'actorType' => 'users', 'verb' => '', @@ -522,11 +522,11 @@ class CommentsPluginTest extends \Test\TestCase { $this->plugin->httpPost($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage Message exceeds allowed character limit of - */ + public function testCreateCommentMessageTooLong() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('Message exceeds allowed character limit of'); + $commentData = [ 'actorType' => 'users', 'verb' => 'comment', @@ -616,10 +616,10 @@ class CommentsPluginTest extends \Test\TestCase { $this->plugin->httpPost($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\ReportNotSupported - */ + public function testOnReportInvalidNode() { + $this->expectException(\Sabre\DAV\Exception\ReportNotSupported::class); + $path = 'totally/unrelated/13'; $this->tree->expects($this->any()) @@ -639,10 +639,10 @@ class CommentsPluginTest extends \Test\TestCase { $this->plugin->onReport(CommentsPluginImplementation::REPORT_NAME, [], '/' . $path); } - /** - * @expectedException \Sabre\DAV\Exception\ReportNotSupported - */ + public function testOnReportInvalidReportName() { + $this->expectException(\Sabre\DAV\Exception\ReportNotSupported::class); + $path = 'comments/files/42'; $this->tree->expects($this->any()) diff --git a/apps/dav/tests/unit/Comments/EntityCollectionTest.php b/apps/dav/tests/unit/Comments/EntityCollectionTest.php index 2097c7ef03a..bb3992401f2 100644 --- a/apps/dav/tests/unit/Comments/EntityCollectionTest.php +++ b/apps/dav/tests/unit/Comments/EntityCollectionTest.php @@ -45,7 +45,7 @@ class EntityCollectionTest extends \Test\TestCase { /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $userSession; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->commentsManager = $this->getMockBuilder(ICommentsManager::class) @@ -89,10 +89,10 @@ class EntityCollectionTest extends \Test\TestCase { $this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildException() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->commentsManager->expects($this->once()) ->method('get') ->with('55') diff --git a/apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php b/apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php index 9286b46d2b0..038dea82fee 100644 --- a/apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php +++ b/apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php @@ -46,7 +46,7 @@ class EntityTypeCollectionTest extends \Test\TestCase { protected $childMap = []; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->commentsManager = $this->getMockBuilder(ICommentsManager::class) @@ -92,17 +92,17 @@ class EntityTypeCollectionTest extends \Test\TestCase { $this->assertTrue($ec instanceof EntityCollectionImplemantation); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildException() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->collection->getChild('17'); } - /** - * @expectedException \Sabre\DAV\Exception\MethodNotAllowed - */ + public function testGetChildren() { + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); + $this->collection->getChildren(); } } diff --git a/apps/dav/tests/unit/Comments/RootCollectionTest.php b/apps/dav/tests/unit/Comments/RootCollectionTest.php index a0e72bcd425..cee5afc0eb3 100644 --- a/apps/dav/tests/unit/Comments/RootCollectionTest.php +++ b/apps/dav/tests/unit/Comments/RootCollectionTest.php @@ -53,7 +53,7 @@ class RootCollectionTest extends \Test\TestCase { /** @var \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject */ protected $user; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->user = $this->getMockBuilder(IUser::class) @@ -106,17 +106,17 @@ class RootCollectionTest extends \Test\TestCase { }); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testCreateFile() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->collection->createFile('foo'); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testCreateDirectory() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->collection->createDirectory('foo'); } @@ -126,18 +126,18 @@ class RootCollectionTest extends \Test\TestCase { $this->assertTrue($etc instanceof EntityTypeCollectionImplementation); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildInvalid() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->prepareForInitCollections(); $this->collection->getChild('robots'); } - /** - * @expectedException \Sabre\DAV\Exception\NotAuthenticated - */ + public function testGetChildNoAuth() { + $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); + $this->collection->getChild('files'); } @@ -150,10 +150,10 @@ class RootCollectionTest extends \Test\TestCase { } } - /** - * @expectedException \Sabre\DAV\Exception\NotAuthenticated - */ + public function testGetChildrenNoAuth() { + $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); + $this->collection->getChildren(); } @@ -167,17 +167,17 @@ class RootCollectionTest extends \Test\TestCase { $this->assertFalse($this->collection->childExists('robots')); } - /** - * @expectedException \Sabre\DAV\Exception\NotAuthenticated - */ + public function testChildExistsNoAuth() { + $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); + $this->collection->childExists('files'); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDelete() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->collection->delete(); } @@ -185,10 +185,10 @@ class RootCollectionTest extends \Test\TestCase { $this->assertSame('comments', $this->collection->getName()); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testSetName() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->collection->setName('foobar'); } diff --git a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php index 447a10afc79..60ec3186ed6 100644 --- a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php @@ -60,7 +60,7 @@ class AuthTest extends TestCase { /** @var Throttler */ private $throttler; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->session = $this->getMockBuilder(ISession::class) ->disableOriginalConstructor()->getMock(); @@ -220,10 +220,10 @@ class AuthTest extends TestCase { $this->assertFalse($this->invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword'])); } - /** - * @expectedException \OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden - */ + public function testValidateUserPassWithPasswordLoginForbidden() { + $this->expectException(\OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden::class); + $this->userSession ->expects($this->once()) ->method('isLoggedIn') @@ -329,11 +329,11 @@ class AuthTest extends TestCase { $this->auth->check($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\NotAuthenticated - * @expectedExceptionMessage 2FA challenge not passed. - */ + public function testAuthenticateAlreadyLoggedInWithoutTwoFactorChallengePassed() { + $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); + $this->expectExceptionMessage('2FA challenge not passed.'); + $request = $this->getMockBuilder(RequestInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -383,11 +383,11 @@ class AuthTest extends TestCase { $this->auth->check($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\NotAuthenticated - * @expectedExceptionMessage CSRF check not passed. - */ + public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndIncorrectlyDavAuthenticated() { + $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); + $this->expectExceptionMessage('CSRF check not passed.'); + $request = $this->getMockBuilder(RequestInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -564,11 +564,11 @@ class AuthTest extends TestCase { $this->assertEquals([false, 'No \'Authorization: Basic\' header found. Either the client didn\'t send one, or the server is misconfigured'], $response); } - /** - * @expectedException \Sabre\DAV\Exception\NotAuthenticated - * @expectedExceptionMessage Cannot authenticate over ajax calls - */ + public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjax() { + $this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class); + $this->expectExceptionMessage('Cannot authenticate over ajax calls'); + /** @var \Sabre\HTTP\RequestInterface $httpRequest */ $httpRequest = $this->getMockBuilder(RequestInterface::class) ->disableOriginalConstructor() diff --git a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php index 2af8fc4c74d..b69c8af45ae 100644 --- a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php @@ -45,7 +45,7 @@ class BearerAuthTest extends TestCase { /** @var BearerAuth */ private $bearerAuth; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->userSession = $this->createMock(\OC\User\Session::class); diff --git a/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php index 03c1ef1ff93..a79186f59a5 100644 --- a/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php @@ -42,7 +42,7 @@ class BlockLegacyClientPluginTest extends TestCase { /** @var BlockLegacyClientPlugin */ private $blockLegacyClientVersionPlugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->config = $this->getMockBuilder(IConfig::class) @@ -67,10 +67,11 @@ class BlockLegacyClientPluginTest extends TestCase { /** * @dataProvider oldDesktopClientProvider * @param string $userAgent - * @expectedException \Sabre\DAV\Exception\Forbidden - * @expectedExceptionMessage Unsupported client version. */ public function testBeforeHandlerException($userAgent) { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->expectExceptionMessage('Unsupported client version.'); + /** @var \Sabre\HTTP\RequestInterface | PHPUnit_Framework_MockObject_MockObject $request */ $request = $this->createMock('\Sabre\HTTP\RequestInterface'); $request diff --git a/apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php index b605aba2bc2..2eda470b255 100644 --- a/apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php @@ -40,7 +40,7 @@ class CommentsPropertiesPluginTest extends \Test\TestCase { protected $userSession; protected $server; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->commentsManager = $this->getMockBuilder(ICommentsManager::class) diff --git a/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php index 5685580c03a..69ebc8d2a34 100644 --- a/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php @@ -45,7 +45,7 @@ class CopyEtagHeaderPluginTest extends TestCase { /** @var Server */ private $server; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = new \Sabre\DAV\Server(); $this->plugin = new CopyEtagHeaderPlugin(); diff --git a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php index 69f67f607b2..de44606fc19 100644 --- a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php @@ -67,7 +67,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase { */ private $user; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = new \Sabre\DAV\Server(); $this->tree = $this->getMockBuilder(Tree::class) @@ -90,7 +90,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase { ); } - public function tearDown(): void { + protected function tearDown(): void { $connection = \OC::$server->getDatabaseConnection(); $deleteStatement = $connection->prepare( 'DELETE FROM `*PREFIX*properties`' . diff --git a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php index ee64eb5bce6..a93ef7ee962 100644 --- a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php @@ -97,10 +97,10 @@ class DirectoryTest extends \Test\TestCase { return new Directory($this->view, $this->info); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDeleteRootFolderFails() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->info->expects($this->any()) ->method('isDeletable') ->will($this->returnValue(true)); @@ -110,10 +110,10 @@ class DirectoryTest extends \Test\TestCase { $dir->delete(); } - /** - * @expectedException \OCA\DAV\Connector\Sabre\Exception\Forbidden - */ + public function testDeleteForbidden() { + $this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class); + // deletion allowed $this->info->expects($this->once()) ->method('isDeletable') @@ -129,9 +129,7 @@ class DirectoryTest extends \Test\TestCase { $dir->delete(); } - /** - * - */ + public function testDeleteFolderWhenAllowed() { // deletion allowed $this->info->expects($this->once()) @@ -148,10 +146,10 @@ class DirectoryTest extends \Test\TestCase { $dir->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDeleteFolderFailsWhenNotAllowed() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->info->expects($this->once()) ->method('isDeletable') ->will($this->returnValue(false)); @@ -160,10 +158,10 @@ class DirectoryTest extends \Test\TestCase { $dir->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDeleteFolderThrowsWhenDeletionFailed() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + // deletion allowed $this->info->expects($this->once()) ->method('isDeletable') @@ -218,10 +216,10 @@ class DirectoryTest extends \Test\TestCase { $dir->getChildren(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testGetChildrenNoPermission() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $info = $this->createMock(FileInfo::class); $info->expects($this->any()) ->method('isReadable') @@ -231,10 +229,10 @@ class DirectoryTest extends \Test\TestCase { $dir->getChildren(); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildNoPermission() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->info->expects($this->any()) ->method('isReadable') ->will($this->returnValue(false)); @@ -243,10 +241,10 @@ class DirectoryTest extends \Test\TestCase { $dir->getChild('test'); } - /** - * @expectedException \Sabre\DAV\Exception\ServiceUnavailable - */ + public function testGetChildThrowStorageNotAvailableException() { + $this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class); + $this->view->expects($this->once()) ->method('getFileInfo') ->willThrowException(new \OCP\Files\StorageNotAvailableException()); @@ -255,10 +253,10 @@ class DirectoryTest extends \Test\TestCase { $dir->getChild('.'); } - /** - * @expectedException \OCA\DAV\Connector\Sabre\Exception\InvalidPath - */ + public function testGetChildThrowInvalidPath() { + $this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class); + $this->view->expects($this->once()) ->method('verifyPath') ->willThrowException(new \OCP\Files\InvalidPathException()); @@ -334,9 +332,10 @@ class DirectoryTest extends \Test\TestCase { /** * @dataProvider moveFailedProvider - * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testMoveFailed($source, $destination, $updatables, $deletables) { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->moveTest($source, $destination, $updatables, $deletables); } @@ -350,9 +349,10 @@ class DirectoryTest extends \Test\TestCase { /** * @dataProvider moveFailedInvalidCharsProvider - * @expectedException \OCA\DAV\Connector\Sabre\Exception\InvalidPath */ public function testMoveFailedInvalidChars($source, $destination, $updatables, $deletables) { + $this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class); + $this->moveTest($source, $destination, $updatables, $deletables); } @@ -403,11 +403,11 @@ class DirectoryTest extends \Test\TestCase { $this->assertTrue($targetNode->moveInto(basename($destination), $source, $sourceNode)); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - * @expectedExceptionMessage Could not copy directory b, target exists - */ + public function testFailingMove() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->expectExceptionMessage('Could not copy directory b, target exists'); + $source = 'a/b'; $destination = 'c/b'; $updatables = ['a' => true, 'a/b' => true, 'b' => true, 'c/b' => false]; diff --git a/apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php b/apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php index 1d22579bdd1..e6555be814d 100644 --- a/apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php @@ -41,7 +41,7 @@ class DummyGetResponsePluginTest extends TestCase { /** @var DummyGetResponsePlugin */ private $dummyGetResponsePlugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->dummyGetResponsePlugin = new DummyGetResponsePlugin(); diff --git a/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php index c2c808a8d95..49b252eb1a1 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php @@ -44,7 +44,7 @@ class FakeLockerPluginTest extends TestCase { /** @var FakeLockerPlugin */ private $fakeLockerPlugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->fakeLockerPlugin = new FakeLockerPlugin(); } diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index d0c18f6cd9e..a3cf4560387 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -62,7 +62,7 @@ class FileTest extends TestCase { /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ protected $config; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); unset($_SERVER['HTTP_OC_CHUNKED']); unset($_SERVER['CONTENT_LENGTH']); @@ -78,7 +78,7 @@ class FileTest extends TestCase { $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); } - public function tearDown(): void { + protected function tearDown(): void { $userManager = \OC::$server->getUserManager(); $userManager->get($this->user)->delete(); unset($_SERVER['HTTP_OC_CHUNKED']); @@ -815,9 +815,10 @@ class FileTest extends TestCase { /** * Test setting name with setName() with invalid chars * - * @expectedException \OCA\DAV\Connector\Sabre\Exception\InvalidPath */ public function testSetNameInvalidChars() { + $this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class); + // setup $view = $this->getMockBuilder(View::class) ->setMethods(['getRelativePath']) @@ -834,8 +835,7 @@ class FileTest extends TestCase { $file->setName('/super*star.txt'); } - /** - */ + public function testUploadAbort() { // setup $view = $this->getMockBuilder(View::class) @@ -879,9 +879,7 @@ class FileTest extends TestCase { $this->assertEmpty($this->listPartFiles($view, ''), 'No stray part files'); } - /** - * - */ + public function testDeleteWhenAllowed() { // setup $view = $this->getMockBuilder(View::class) @@ -901,10 +899,10 @@ class FileTest extends TestCase { $file->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDeleteThrowsWhenDeletionNotAllowed() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + // setup $view = $this->getMockBuilder(View::class) ->getMock(); @@ -919,10 +917,10 @@ class FileTest extends TestCase { $file->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDeleteThrowsWhenDeletionFailed() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + // setup $view = $this->getMockBuilder(View::class) ->getMock(); @@ -942,10 +940,10 @@ class FileTest extends TestCase { $file->delete(); } - /** - * @expectedException \OCA\DAV\Connector\Sabre\Exception\Forbidden - */ + public function testDeleteThrowsWhenDeletionThrows() { + $this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class); + // setup $view = $this->getMockBuilder(View::class) ->getMock(); @@ -1112,10 +1110,10 @@ class FileTest extends TestCase { ]; } - /** - * @expectedException \Sabre\DAV\Exception\ServiceUnavailable - */ + public function testGetFopenFails() { + $this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class); + $view = $this->getMockBuilder(View::class) ->setMethods(['fopen']) ->getMock(); @@ -1132,10 +1130,10 @@ class FileTest extends TestCase { $file->get(); } - /** - * @expectedException \OCA\DAV\Connector\Sabre\Exception\Forbidden - */ + public function testGetFopenThrows() { + $this->expectException(\OCA\DAV\Connector\Sabre\Exception\Forbidden::class); + $view = $this->getMockBuilder(View::class) ->setMethods(['fopen']) ->getMock(); @@ -1152,10 +1150,10 @@ class FileTest extends TestCase { $file->get(); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetThrowsIfNoPermission() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $view = $this->getMockBuilder(View::class) ->setMethods(['fopen']) ->getMock(); diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php index 564059cd1dc..45c11d0011a 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php @@ -97,7 +97,7 @@ class FilesPluginTest extends TestCase { */ private $previewManager; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = $this->getMockBuilder(Server::class) ->disableOriginalConstructor() @@ -462,10 +462,11 @@ class FilesPluginTest extends TestCase { * FolderA is an incoming shared folder and there are no delete permissions. * Thus moving /FolderA/test.txt to /test.txt should fail already on that check * - * @expectedException \Sabre\DAV\Exception\Forbidden - * @expectedExceptionMessage FolderA/test.txt cannot be deleted */ public function testMoveSrcNotDeletable() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->expectExceptionMessage('FolderA/test.txt cannot be deleted'); + $fileInfoFolderATestTXT = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor() ->getMock(); @@ -507,11 +508,11 @@ class FilesPluginTest extends TestCase { $this->plugin->checkMove('FolderA/test.txt', 'test.txt'); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - * @expectedExceptionMessage FolderA/test.txt does not exist - */ + public function testMoveSrcNotExist() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->expectExceptionMessage('FolderA/test.txt does not exist'); + $node = $this->getMockBuilder(Node::class) ->disableOriginalConstructor() ->getMock(); diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php index ea58c50480c..14c6af122a2 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php @@ -85,7 +85,7 @@ class FilesReportPluginTest extends \Test\TestCase { /** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject * */ private $appManager; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->tree = $this->getMockBuilder(Tree::class) ->disableOriginalConstructor() @@ -603,10 +603,10 @@ class FilesReportPluginTest extends \Test\TestCase { $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules]))); } - /** - * @expectedException \OCP\SystemTag\TagNotFoundException - */ + public function testProcessFilterRulesInvisibleTagAsUser() { + $this->expectException(\OCP\SystemTag\TagNotFoundException::class); + $this->groupManager->expects($this->any()) ->method('isAdmin') ->will($this->returnValue(false)); diff --git a/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php b/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php index a604757520d..a9c8929dee6 100644 --- a/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php @@ -39,18 +39,18 @@ class MaintenancePluginTest extends TestCase { /** @var MaintenancePlugin */ private $maintenancePlugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->config = $this->getMockBuilder(IConfig::class)->getMock(); $this->maintenancePlugin = new MaintenancePlugin($this->config); } - /** - * @expectedException \Sabre\DAV\Exception\ServiceUnavailable - * @expectedExceptionMessage System in maintenance mode. - */ + public function testMaintenanceMode() { + $this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class); + $this->expectExceptionMessage('System in maintenance mode.'); + $this->config ->expects($this->exactly(1)) ->method('getSystemValueBool') diff --git a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php index cd575e4ff3c..1c71d396de2 100644 --- a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php @@ -103,9 +103,10 @@ class ObjectTreeTest extends \Test\TestCase { /** * @dataProvider copyDataProvider - * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testCopyFailNotCreatable($sourcePath, $targetPath, $targetParent) { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $view = $this->createMock(View::class); $view->expects($this->never()) ->method('verifyPath'); @@ -268,10 +269,10 @@ class ObjectTreeTest extends \Test\TestCase { ); } - /** - * @expectedException \OCA\DAV\Connector\Sabre\Exception\InvalidPath - */ + public function testGetNodeForPathInvalidPath() { + $this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class); + $path = '/foo\bar'; diff --git a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php index 5320bd28302..7836191450b 100644 --- a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php @@ -65,7 +65,7 @@ class PrincipalTest extends TestCase { /** @var ProxyMapper | \PHPUnit_Framework_MockObject_MockObject */ private $proxyMapper; - public function setUp(): void { + protected function setUp(): void { $this->userManager = $this->createMock(IUserManager::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->shareManager = $this->createMock(IManager::class); @@ -209,11 +209,11 @@ class PrincipalTest extends TestCase { $this->assertSame([], $response); } - /** - * @expectedException \Sabre\DAV\Exception - * @expectedExceptionMessage Principal not found - */ + public function testGetGroupMemberSetEmpty() { + $this->expectException(\Sabre\DAV\Exception::class); + $this->expectExceptionMessage('Principal not found'); + $this->userManager ->expects($this->once()) ->method('get') @@ -334,11 +334,11 @@ class PrincipalTest extends TestCase { $this->assertSame($expectedResponse, $response); } - /** - * @expectedException \Sabre\DAV\Exception - * @expectedExceptionMessage Principal not found - */ + public function testGetGroupMembershipEmpty() { + $this->expectException(\Sabre\DAV\Exception::class); + $this->expectExceptionMessage('Principal not found'); + $this->userManager ->expects($this->once()) ->method('get') @@ -348,11 +348,11 @@ class PrincipalTest extends TestCase { $this->connector->getGroupMembership('principals/users/foo'); } - /** - * @expectedException \Sabre\DAV\Exception - * @expectedExceptionMessage Setting members of the group is not supported yet - */ + public function testSetGroupMembership() { + $this->expectException(\Sabre\DAV\Exception::class); + $this->expectExceptionMessage('Setting members of the group is not supported yet'); + $this->connector->setGroupMemberSet('principals/users/foo', ['foo']); } diff --git a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php index e5d229733c5..d09ed9cf681 100644 --- a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php @@ -85,10 +85,11 @@ class QuotaPluginTest extends TestCase { } /** - * @expectedException \Sabre\DAV\Exception\InsufficientStorage * @dataProvider quotaExceededProvider */ public function testCheckExceededQuota($quota, $headers) { + $this->expectException(\Sabre\DAV\Exception\InsufficientStorage::class); + $this->init($quota); $this->plugin->expects($this->never()) ->method('getFileChunking'); @@ -209,9 +210,10 @@ class QuotaPluginTest extends TestCase { /** * @dataProvider quotaChunkedFailProvider - * @expectedException \Sabre\DAV\Exception\InsufficientStorage */ public function testCheckQuotaChunkedFail($quota, $chunkTotalSize, $headers) { + $this->expectException(\Sabre\DAV\Exception\InsufficientStorage::class); + $this->init($quota, 'sub/test.txt'); $mockChunking = $this->getMockBuilder(\OC_FileChunking::class) diff --git a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php index 85d285f2c3b..96c2d3ba092 100644 --- a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php @@ -66,7 +66,7 @@ class SharesPluginTest extends \Test\TestCase { */ private $plugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = new \Sabre\DAV\Server(); $this->tree = $this->createMock(Tree::class); diff --git a/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php index 384441f4495..a805a776ad8 100644 --- a/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php @@ -70,7 +70,7 @@ class TagsPluginTest extends \Test\TestCase { */ private $plugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = new \Sabre\DAV\Server(); $this->tree = $this->getMockBuilder(Tree::class) diff --git a/apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php b/apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php index 509ccb7e353..cc1273f5418 100644 --- a/apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php +++ b/apps/dav/tests/unit/Controller/BirthdayCalendarControllerTest.php @@ -57,7 +57,7 @@ class BirthdayCalendarControllerTest extends TestCase { /** @var BirthdayCalendarController|\PHPUnit_Framework_MockObject_MockObject */ private $controller; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->config = $this->createMock(IConfig::class); diff --git a/apps/dav/tests/unit/Controller/DirectControllerTest.php b/apps/dav/tests/unit/Controller/DirectControllerTest.php index 18034891dc8..21282762745 100644 --- a/apps/dav/tests/unit/Controller/DirectControllerTest.php +++ b/apps/dav/tests/unit/Controller/DirectControllerTest.php @@ -59,7 +59,7 @@ class DirectControllerTest extends TestCase { /** @var DirectController */ private $controller; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->rootFolder = $this->createMock(IRootFolder::class); diff --git a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php index 44ca70b9342..c465f62eba7 100644 --- a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php +++ b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php @@ -52,7 +52,7 @@ class InvitationResponseControllerTest extends TestCase { /** @var InvitationResponseServer|\PHPUnit_Framework_MockObject_MockObject */ private $responseServer; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->dbConnection = $this->createMock(IDBConnection::class); diff --git a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php index d43e42b93b7..9c4c20c945b 100644 --- a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php @@ -45,7 +45,7 @@ class CustomPropertiesBackendTest extends TestCase { /** @var CustomPropertiesBackend | \PHPUnit_Framework_MockObject_MockObject */ private $backend; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->tree = $this->createMock(Tree::class); diff --git a/apps/dav/tests/unit/DAV/GroupPrincipalTest.php b/apps/dav/tests/unit/DAV/GroupPrincipalTest.php index 356299dab56..f0fda89ee92 100644 --- a/apps/dav/tests/unit/DAV/GroupPrincipalTest.php +++ b/apps/dav/tests/unit/DAV/GroupPrincipalTest.php @@ -49,7 +49,7 @@ class GroupPrincipalTest extends \Test\TestCase { /** @var GroupPrincipalBackend */ private $connector; - public function setUp(): void { + protected function setUp(): void { $this->groupManager = $this->createMock(IGroupManager::class); $this->userSession = $this->createMock(IUserSession::class); $this->shareManager = $this->createMock(IManager::class); @@ -174,11 +174,11 @@ class GroupPrincipalTest extends \Test\TestCase { $this->assertSame([], $response); } - /** - * @expectedException \Sabre\DAV\Exception - * @expectedExceptionMessage Setting members of the group is not supported yet - */ + public function testSetGroupMembership() { + $this->expectException(\Sabre\DAV\Exception::class); + $this->expectExceptionMessage('Setting members of the group is not supported yet'); + $this->connector->setGroupMemberSet('principals/groups/foo', ['foo']); } diff --git a/apps/dav/tests/unit/DAV/HookManagerTest.php b/apps/dav/tests/unit/DAV/HookManagerTest.php index 6b64abc8442..2a5f52cc4bd 100644 --- a/apps/dav/tests/unit/DAV/HookManagerTest.php +++ b/apps/dav/tests/unit/DAV/HookManagerTest.php @@ -46,7 +46,7 @@ class HookManagerTest extends TestCase { /** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */ private $eventDispatcher; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->l10n = $this->createMock(IL10N::class); diff --git a/apps/dav/tests/unit/DAV/Sharing/PluginTest.php b/apps/dav/tests/unit/DAV/Sharing/PluginTest.php index 38eb86baf27..69a76c3f8f9 100644 --- a/apps/dav/tests/unit/DAV/Sharing/PluginTest.php +++ b/apps/dav/tests/unit/DAV/Sharing/PluginTest.php @@ -44,7 +44,7 @@ class PluginTest extends TestCase { /** @var IShareable | \PHPUnit_Framework_MockObject_MockObject */ private $book; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); /** @var Auth | \PHPUnit_Framework_MockObject_MockObject $authBackend */ diff --git a/apps/dav/tests/unit/DAV/SystemPrincipalBackendTest.php b/apps/dav/tests/unit/DAV/SystemPrincipalBackendTest.php index 5833847cfed..32d6d47c206 100644 --- a/apps/dav/tests/unit/DAV/SystemPrincipalBackendTest.php +++ b/apps/dav/tests/unit/DAV/SystemPrincipalBackendTest.php @@ -80,13 +80,14 @@ class SystemPrincipalBackendTest extends TestCase { /** * @dataProvider providesPrincipalForGetGroupMemberSet - * @expectedException \Sabre\DAV\Exception - * @expectedExceptionMessage Principal not found * * @param string $principal * @throws \Sabre\DAV\Exception */ public function testGetGroupMemberSetExceptional($principal) { + $this->expectException(\Sabre\DAV\Exception::class); + $this->expectExceptionMessage('Principal not found'); + $backend = new SystemPrincipalBackend(); $backend->getGroupMemberSet($principal); } @@ -109,13 +110,14 @@ class SystemPrincipalBackendTest extends TestCase { /** * @dataProvider providesPrincipalForGetGroupMembership - * @expectedException \Sabre\DAV\Exception - * @expectedExceptionMessage Principal not found * * @param string $principal * @throws \Sabre\DAV\Exception */ public function testGetGroupMembershipExceptional($principal) { + $this->expectException(\Sabre\DAV\Exception::class); + $this->expectExceptionMessage('Principal not found'); + $backend = new SystemPrincipalBackend(); $backend->getGroupMembership($principal); } diff --git a/apps/dav/tests/unit/Direct/DirectFileTest.php b/apps/dav/tests/unit/Direct/DirectFileTest.php index c48b34bb175..5d2831c5bde 100644 --- a/apps/dav/tests/unit/Direct/DirectFileTest.php +++ b/apps/dav/tests/unit/Direct/DirectFileTest.php @@ -49,7 +49,7 @@ class DirectFileTest extends TestCase { /** @var DirectFile */ private $directFile; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->direct = Direct::fromParams([ diff --git a/apps/dav/tests/unit/Direct/DirectHomeTest.php b/apps/dav/tests/unit/Direct/DirectHomeTest.php index 8a976ff5dbf..ca71be06274 100644 --- a/apps/dav/tests/unit/Direct/DirectHomeTest.php +++ b/apps/dav/tests/unit/Direct/DirectHomeTest.php @@ -58,7 +58,7 @@ class DirectHomeTest extends TestCase { /** @var DirectHome */ private $directHome; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->directMapper = $this->createMock(DirectMapper::class); diff --git a/apps/dav/tests/unit/Files/FileSearchBackendTest.php b/apps/dav/tests/unit/Files/FileSearchBackendTest.php index b524af5f390..723fb9f4049 100644 --- a/apps/dav/tests/unit/Files/FileSearchBackendTest.php +++ b/apps/dav/tests/unit/Files/FileSearchBackendTest.php @@ -258,10 +258,10 @@ class FileSearchBackendTest extends TestCase { $this->assertEquals('/files/test/test/path', $result[0]->href); } - /** - * @expectedException \InvalidArgumentException - */ + public function testSearchInvalidProp() { + $this->expectException(\InvalidArgumentException::class); + $this->tree->expects($this->any()) ->method('getNodeForPath') ->willReturn($this->davFolder); @@ -295,10 +295,10 @@ class FileSearchBackendTest extends TestCase { return new Query($select, $from, $where, $orderBy, $limit); } - /** - * @expectedException \InvalidArgumentException - */ + public function testSearchNonFolder() { + $this->expectException(\InvalidArgumentException::class); + $davNode = $this->createMock(File::class); $this->tree->expects($this->any()) diff --git a/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php b/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php index f311b0f2cb3..344b6b7df51 100644 --- a/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php +++ b/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php @@ -48,7 +48,7 @@ class FilesDropPluginTest extends TestCase { /** @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ private $response; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->view = $this->createMock(View::class); diff --git a/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php b/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php index 063bf485501..63dd3480b20 100644 --- a/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php +++ b/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php @@ -89,7 +89,7 @@ CREATED:20151214T091032Z END:VEVENT END:VCALENDAR'; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->logger = $this->createMock(ILogger::class); diff --git a/apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningNodeTest.php b/apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningNodeTest.php index 2f65fc7c45f..0253592ede0 100644 --- a/apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningNodeTest.php +++ b/apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningNodeTest.php @@ -34,7 +34,7 @@ class AppleProvisioningNodeTest extends TestCase { /** @var AppleProvisioningNode */ private $node; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->timeFactory = $this->createMock(ITimeFactory::class); @@ -45,11 +45,11 @@ class AppleProvisioningNodeTest extends TestCase { $this->assertEquals('apple-provisioning.mobileconfig', $this->node->getName()); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - * @expectedExceptionMessage Renaming apple-provisioning.mobileconfig is forbidden - */ + public function testSetName() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->expectExceptionMessage('Renaming apple-provisioning.mobileconfig is forbidden'); + $this->node->setName('foo'); } @@ -57,11 +57,11 @@ class AppleProvisioningNodeTest extends TestCase { $this->assertEquals(null, $this->node->getLastModified()); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - * @expectedExceptionMessage apple-provisioning.mobileconfig may not be deleted - */ + public function testDelete() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->expectExceptionMessage('apple-provisioning.mobileconfig may not be deleted'); + $this->node->delete(); } @@ -76,11 +76,11 @@ class AppleProvisioningNodeTest extends TestCase { ], $this->node->getProperties([])); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - * @expectedExceptionMessage apple-provisioning.mobileconfig's properties may not be altered. - */ + public function testGetPropPatch() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->expectExceptionMessage('apple-provisioning.mobileconfig\'s properties may not be altered.'); + $propPatch = $this->createMock(PropPatch::class); $this->node->propPatch($propPatch); diff --git a/apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningPluginTest.php b/apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningPluginTest.php index eeadf349710..e6d5b6217d0 100644 --- a/apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningPluginTest.php +++ b/apps/dav/tests/unit/Provisioning/Apple/AppleProvisioningPluginTest.php @@ -59,7 +59,7 @@ class AppleProvisioningPluginTest extends TestCase { /** @var AppleProvisioningPlugin */ protected $plugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = $this->createMock(\Sabre\DAV\Server::class); diff --git a/apps/dav/tests/unit/Settings/CalDAVSettingsTest.php b/apps/dav/tests/unit/Settings/CalDAVSettingsTest.php index 17bcf9fba97..3f201eba17e 100644 --- a/apps/dav/tests/unit/Settings/CalDAVSettingsTest.php +++ b/apps/dav/tests/unit/Settings/CalDAVSettingsTest.php @@ -35,7 +35,7 @@ class CalDAVSettingsTest extends TestCase { /** @var CalDAVSettings */ private $settings; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->config = $this->createMock(IConfig::class); diff --git a/apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php b/apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php index 926c652b77e..bd4afe9fb10 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php @@ -144,10 +144,10 @@ class SystemTagMappingNodeTest extends \Test\TestCase { $this->assertInstanceOf($expectedException, $thrown); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testDeleteTagNotFound() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + // assuming the tag existed at the time the node was created, // but got deleted concurrently in the database $tag = new SystemTag(1, 'Test', true, true); diff --git a/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php b/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php index d2bd59bff65..53df8c91969 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php @@ -81,10 +81,10 @@ class SystemTagNodeTest extends \Test\TestCase { $this->assertEquals($tag, $node->getSystemTag()); } - /** - * @expectedException \Sabre\DAV\Exception\MethodNotAllowed - */ + public function testSetName() { + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); + $this->getTagNode()->setName('2'); } @@ -198,10 +198,10 @@ class SystemTagNodeTest extends \Test\TestCase { $this->assertInstanceOf($expectedException, $thrown); } - /** - * @expectedException \Sabre\DAV\Exception\Conflict - */ + public function testUpdateTagAlreadyExists() { + $this->expectException(\Sabre\DAV\Exception\Conflict::class); + $tag = new SystemTag(1, 'tag1', true, true); $this->tagManager->expects($this->any()) ->method('canUserSeeTag') @@ -218,10 +218,10 @@ class SystemTagNodeTest extends \Test\TestCase { $this->getTagNode(false, $tag)->update('Renamed', true, true); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testUpdateTagNotFound() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $tag = new SystemTag(1, 'tag1', true, true); $this->tagManager->expects($this->any()) ->method('canUserSeeTag') @@ -286,10 +286,10 @@ class SystemTagNodeTest extends \Test\TestCase { $this->getTagNode(false, $tag)->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testDeleteTagNotFound() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $tag = new SystemTag(1, 'tag1', true, true); $this->tagManager->expects($this->any()) ->method('canUserSeeTag') diff --git a/apps/dav/tests/unit/SystemTag/SystemTagPluginTest.php b/apps/dav/tests/unit/SystemTag/SystemTagPluginTest.php index 1282807842a..8ac14ff6cbc 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagPluginTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagPluginTest.php @@ -85,7 +85,7 @@ class SystemTagPluginTest extends \Test\TestCase { */ private $plugin; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->tree = $this->getMockBuilder(Tree::class) ->disableOriginalConstructor() @@ -234,10 +234,10 @@ class SystemTagPluginTest extends \Test\TestCase { $this->assertEquals($expectedProperties, $result[200]); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testGetPropertiesForbidden() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $systemTag = new SystemTag(1, 'Test', true, false); $requestedProperties = [ self::ID_PROPERTYNAME, @@ -331,10 +331,10 @@ class SystemTagPluginTest extends \Test\TestCase { $this->assertEquals(200, $result[self::USERVISIBLE_PROPERTYNAME]); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testUpdatePropertiesForbidden() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $systemTag = new SystemTag(1, 'Test', true, false); $this->user->expects($this->any()) ->method('getUID') @@ -385,10 +385,11 @@ class SystemTagPluginTest extends \Test\TestCase { } /** * @dataProvider createTagInsufficientPermissionsProvider - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage Not sufficient permissions */ public function testCreateNotAssignableTagAsRegularUser($userVisible, $userAssignable, $groups) { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('Not sufficient permissions'); + $this->user->expects($this->once()) ->method('getUID') ->willReturn('admin'); @@ -658,10 +659,10 @@ class SystemTagPluginTest extends \Test\TestCase { $this->plugin->httpPost($request, $response); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testCreateTagToUnknownNode() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $node = $this->getMockBuilder(SystemTagsObjectMappingCollection::class) ->disableOriginalConstructor() ->getMock(); @@ -692,9 +693,10 @@ class SystemTagPluginTest extends \Test\TestCase { /** * @dataProvider nodeClassProvider - * @expectedException \Sabre\DAV\Exception\Conflict */ public function testCreateTagConflict($nodeClass) { + $this->expectException(\Sabre\DAV\Exception\Conflict::class); + $this->user->expects($this->once()) ->method('getUID') ->willReturn('admin'); diff --git a/apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php b/apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php index da46843a5b2..496caebc907 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php @@ -80,17 +80,17 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { return [[true], [false]]; } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testForbiddenCreateFile() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->getNode()->createFile('555'); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testForbiddenCreateDirectory() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->getNode()->createDirectory('789'); } @@ -113,10 +113,10 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { $this->assertEquals($tag, $childNode->getSystemTag()); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - */ + public function testGetChildInvalidName() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->tagManager->expects($this->once()) ->method('getTagsByIds') ->with(['invalid']) @@ -125,10 +125,10 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { $this->getNode()->getChild('invalid'); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildNotFound() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->tagManager->expects($this->once()) ->method('getTagsByIds') ->with(['444']) @@ -137,10 +137,10 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { $this->getNode()->getChild('444'); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildUserNotVisible() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $tag = new SystemTag(123, 'Test', false, false); $this->tagManager->expects($this->once()) @@ -231,10 +231,10 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { $this->assertFalse($this->getNode()->childExists('123')); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - */ + public function testChildExistsBadRequest() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->tagManager->expects($this->once()) ->method('getTagsByIds') ->with(['invalid']) diff --git a/apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php b/apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php index ff56ae3d447..7efe6b19c78 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php @@ -133,10 +133,10 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { $this->assertInstanceOf($expectedException, $thrown); } - /** - * @expectedException \Sabre\DAV\Exception\PreconditionFailed - */ + public function testAssignTagNotFound() { + $this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class); + $this->tagManager->expects($this->once()) ->method('getTagsByIds') ->with(['555']) @@ -145,10 +145,10 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { $this->getNode()->createFile('555'); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testForbiddenCreateDirectory() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->getNode()->createDirectory('789'); } @@ -175,10 +175,10 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { $this->assertEquals('555', $childNode->getName()); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildNonVisible() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $tag = new SystemTag(555, 'TheTag', false, false); $this->tagManager->expects($this->once()) ->method('canUserSeeTag') @@ -198,10 +198,10 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { $this->getNode()->getChild('555'); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildRelationNotFound() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->tagMapper->expects($this->once()) ->method('haveTag') ->with([111], 'files', '777') @@ -210,10 +210,10 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { $this->getNode()->getChild('777'); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - */ + public function testGetChildInvalidId() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->tagMapper->expects($this->once()) ->method('haveTag') ->with([111], 'files', 'badid') @@ -222,10 +222,10 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { $this->getNode()->getChild('badid'); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildTagDoesNotExist() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->tagMapper->expects($this->once()) ->method('haveTag') ->with([111], 'files', '777') @@ -326,10 +326,10 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { $this->assertFalse($this->getNode()->childExists('555')); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - */ + public function testChildExistsInvalidId() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->tagMapper->expects($this->once()) ->method('haveTag') ->with([111], 'files', '555') @@ -338,17 +338,17 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { $this->getNode()->childExists('555'); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDelete() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->getNode()->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testSetName() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->getNode()->setName('somethingelse'); } diff --git a/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php b/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php index 5e4e539b1e7..90b6e703a71 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php @@ -98,17 +98,17 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { ); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testForbiddenCreateFile() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->node->createFile('555'); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testForbiddenCreateDirectory() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->node->createDirectory('789'); } @@ -123,10 +123,10 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { $this->assertEquals('555', $childNode->getName()); } - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ + public function testGetChildWithoutAccess() { + $this->expectException(\Sabre\DAV\Exception\NotFound::class); + $this->userFolder->expects($this->once()) ->method('getById') ->with('555') @@ -134,10 +134,10 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { $this->node->getChild('555'); } - /** - * @expectedException \Sabre\DAV\Exception\MethodNotAllowed - */ + public function testGetChildren() { + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); + $this->node->getChildren(); } @@ -157,17 +157,17 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { $this->assertFalse($this->node->childExists('555')); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testDelete() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->node->delete(); } - /** - * @expectedException \Sabre\DAV\Exception\Forbidden - */ + public function testSetName() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $this->node->setName('somethingelse'); } diff --git a/apps/dav/tests/unit/Upload/ChunkingPluginTest.php b/apps/dav/tests/unit/Upload/ChunkingPluginTest.php index bc2b434bcf7..3135ced2612 100644 --- a/apps/dav/tests/unit/Upload/ChunkingPluginTest.php +++ b/apps/dav/tests/unit/Upload/ChunkingPluginTest.php @@ -51,7 +51,7 @@ class ChunkingPluginTest extends TestCase { /** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject */ private $response; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->server = $this->getMockBuilder('\Sabre\DAV\Server') @@ -141,11 +141,11 @@ class ChunkingPluginTest extends TestCase { $this->assertFalse($this->plugin->beforeMove('source', 'target')); } - /** - * @expectedException \Sabre\DAV\Exception\BadRequest - * @expectedExceptionMessage Chunks on server do not sum up to 4 but to 3 bytes - */ + public function testBeforeMoveSizeIsWrong() { + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); + $this->expectExceptionMessage('Chunks on server do not sum up to 4 but to 3 bytes'); + $sourceNode = $this->createMock(FutureFile::class); $sourceNode->expects($this->once()) ->method('getSize') diff --git a/apps/dav/tests/unit/Upload/FutureFileTest.php b/apps/dav/tests/unit/Upload/FutureFileTest.php index 94be4ea66dd..cfe3491d13f 100644 --- a/apps/dav/tests/unit/Upload/FutureFileTest.php +++ b/apps/dav/tests/unit/Upload/FutureFileTest.php @@ -73,18 +73,18 @@ class FutureFileTest extends \Test\TestCase { $f->delete(); } - /** - * @expectedException Sabre\DAV\Exception\Forbidden - */ + public function testPut() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $f = $this->mockFutureFile(); $f->put(''); } - /** - * @expectedException Sabre\DAV\Exception\Forbidden - */ + public function testSetName() { + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); + $f = $this->mockFutureFile(); $f->setName(''); } |