Merge pull request #21981 from nextcloud/backport/21972/stable19

[stable19] Fix PHPUnit deprecation warnings
This commit is contained in:
Morris Jobke 2020-07-30 11:03:54 +02:00 committed by GitHub
commit de70dcf708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 43 additions and 80 deletions

View File

@ -279,7 +279,7 @@ EOD;
$this->assertCount(0, $calendarObjects); $this->assertCount(0, $calendarObjects);
} }
public function testMultipleCalendarObjectsWithSameUID() { public function testMultipleCalendarObjectsWithSameUID() {
$this->expectException(\Sabre\DAV\Exception\BadRequest::class); $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
$this->expectExceptionMessage('Calendar object with uid already exists in this calendar collection.'); $this->expectExceptionMessage('Calendar object with uid already exists in this calendar collection.');
@ -441,7 +441,7 @@ EOD;
$expectedEventsInResult = array_map(function ($index) use ($events) { $expectedEventsInResult = array_map(function ($index) use ($events) {
return $events[$index]; return $events[$index];
}, $expectedEventsInResult); }, $expectedEventsInResult);
$this->assertEquals($expectedEventsInResult, $result, '', 0.0, 10, true); $this->assertEqualsCanonicalizing($expectedEventsInResult, $result);
} }
public function testGetCalendarObjectByUID() { public function testGetCalendarObjectByUID() {

View File

@ -63,7 +63,6 @@ class ListCalendarsTest extends TestCase {
); );
} }
public function testWithBadUser() { public function testWithBadUser() {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
@ -76,7 +75,7 @@ class ListCalendarsTest extends TestCase {
$commandTester->execute([ $commandTester->execute([
'uid' => self::USERNAME, 'uid' => self::USERNAME,
]); ]);
$this->assertContains("User <" . self::USERNAME . "> in unknown", $commandTester->getDisplay()); $this->assertStringContainsString("User <" . self::USERNAME . "> in unknown", $commandTester->getDisplay());
} }
public function testWithCorrectUserWithNoCalendars() { public function testWithCorrectUserWithNoCalendars() {
@ -94,7 +93,7 @@ class ListCalendarsTest extends TestCase {
$commandTester->execute([ $commandTester->execute([
'uid' => self::USERNAME, 'uid' => self::USERNAME,
]); ]);
$this->assertContains("User <" . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay()); $this->assertStringContainsString("User <" . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay());
} }
public function dataExecute() { public function dataExecute() {
@ -133,7 +132,7 @@ class ListCalendarsTest extends TestCase {
$commandTester->execute([ $commandTester->execute([
'uid' => self::USERNAME, 'uid' => self::USERNAME,
]); ]);
$this->assertContains($output, $commandTester->getDisplay()); $this->assertStringContainsString($output, $commandTester->getDisplay());
$this->assertNotContains(BirthdayService::BIRTHDAY_CALENDAR_URI, $commandTester->getDisplay()); $this->assertStringNotContainsString(BirthdayService::BIRTHDAY_CALENDAR_URI, $commandTester->getDisplay());
} }
} }

View File

@ -121,7 +121,7 @@ class MoveCalendarTest extends TestCase {
]); ]);
} }
public function testMoveWithInexistantCalendar() { public function testMoveWithInexistantCalendar() {
$this->expectException(\InvalidArgumentException::class); $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->expectExceptionMessage('User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user.');
@ -148,7 +148,7 @@ class MoveCalendarTest extends TestCase {
]); ]);
} }
public function testMoveWithExistingDestinationCalendar() { public function testMoveWithExistingDestinationCalendar() {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('User <user2> already has a calendar named <personal>.'); $this->expectExceptionMessage('User <user2> already has a calendar named <personal>.');
@ -313,7 +313,7 @@ class MoveCalendarTest extends TestCase {
'destinationuid' => 'user2', 'destinationuid' => 'user2',
]); ]);
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay()); $this->assertStringContainsString("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
} }
public function testMoveWithDestinationNotPartOfGroupAndForce() { public function testMoveWithDestinationNotPartOfGroupAndForce() {
@ -360,7 +360,7 @@ class MoveCalendarTest extends TestCase {
'--force' => true '--force' => true
]); ]);
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay()); $this->assertStringContainsString("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
} }
public function dataTestMoveWithCalendarAlreadySharedToDestination(): array { public function dataTestMoveWithCalendarAlreadySharedToDestination(): array {

View File

@ -197,7 +197,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
'accepted' => 0, 'accepted' => 0,
'token' => 'token', 'token' => 'token',
]; ];
$this->assertArraySubset($expected, $data); foreach (array_keys($expected) as $key) {
$this->assertEquals($expected[$key], $data[$key], "Assert that value for key '$key' is the same");
}
$this->assertEquals($data['id'], $share->getId()); $this->assertEquals($data['id'], $share->getId());
$this->assertEquals(\OCP\Share::SHARE_TYPE_REMOTE, $share->getShareType()); $this->assertEquals(\OCP\Share::SHARE_TYPE_REMOTE, $share->getShareType());

View File

@ -60,6 +60,6 @@ class CleanupTest extends TestCase {
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$output = $this->cmd->getDisplay(); $output = $this->cmd->getDisplay();
$this->assertContains("All user-provider associations for provider u2f have been removed", $output); $this->assertStringContainsString("All user-provider associations for provider u2f have been removed", $output);
} }
} }

View File

@ -67,7 +67,7 @@ class DisableTest extends TestCase {
]); ]);
$this->assertEquals(1, $rc); $this->assertEquals(1, $rc);
$this->assertContains("Invalid UID", $this->command->getDisplay()); $this->assertStringContainsString("Invalid UID", $this->command->getDisplay());
} }
public function testEnableNotSupported() { public function testEnableNotSupported() {
@ -87,7 +87,7 @@ class DisableTest extends TestCase {
]); ]);
$this->assertEquals(2, $rc); $this->assertEquals(2, $rc);
$this->assertContains("The provider does not support this operation", $this->command->getDisplay()); $this->assertStringContainsString("The provider does not support this operation", $this->command->getDisplay());
} }
public function testEnabled() { public function testEnabled() {
@ -107,6 +107,6 @@ class DisableTest extends TestCase {
]); ]);
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$this->assertContains("Two-factor provider totp disabled for user ricky", $this->command->getDisplay()); $this->assertStringContainsString("Two-factor provider totp disabled for user ricky", $this->command->getDisplay());
} }
} }

View File

@ -67,7 +67,7 @@ class EnableTest extends TestCase {
]); ]);
$this->assertEquals(1, $rc); $this->assertEquals(1, $rc);
$this->assertContains("Invalid UID", $this->command->getDisplay()); $this->assertStringContainsString("Invalid UID", $this->command->getDisplay());
} }
public function testEnableNotSupported() { public function testEnableNotSupported() {
@ -87,7 +87,7 @@ class EnableTest extends TestCase {
]); ]);
$this->assertEquals(2, $rc); $this->assertEquals(2, $rc);
$this->assertContains("The provider does not support this operation", $this->command->getDisplay()); $this->assertStringContainsString("The provider does not support this operation", $this->command->getDisplay());
} }
public function testEnabled() { public function testEnabled() {
@ -107,6 +107,6 @@ class EnableTest extends TestCase {
]); ]);
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$this->assertContains("Two-factor provider totp enabled for user belle", $this->command->getDisplay()); $this->assertStringContainsString("Two-factor provider totp enabled for user belle", $this->command->getDisplay());
} }
} }

View File

@ -64,7 +64,7 @@ class EnforceTest extends TestCase {
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$display = $this->command->getDisplay(); $display = $this->command->getDisplay();
$this->assertContains("Two-factor authentication is enforced for all users", $display); $this->assertStringContainsString("Two-factor authentication is enforced for all users", $display);
} }
public function testEnforceForOneGroup() { public function testEnforceForOneGroup() {
@ -82,7 +82,7 @@ class EnforceTest extends TestCase {
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$display = $this->command->getDisplay(); $display = $this->command->getDisplay();
$this->assertContains("Two-factor authentication is enforced for members of the group(s) twofactorers", $display); $this->assertStringContainsString("Two-factor authentication is enforced for members of the group(s) twofactorers", $display);
} }
public function testEnforceForAllExceptOneGroup() { public function testEnforceForAllExceptOneGroup() {
@ -100,7 +100,7 @@ class EnforceTest extends TestCase {
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$display = $this->command->getDisplay(); $display = $this->command->getDisplay();
$this->assertContains("Two-factor authentication is enforced for all users, except members of yoloers", $display); $this->assertStringContainsString("Two-factor authentication is enforced for all users, except members of yoloers", $display);
} }
public function testDisableEnforced() { public function testDisableEnforced() {
@ -117,7 +117,7 @@ class EnforceTest extends TestCase {
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$display = $this->command->getDisplay(); $display = $this->command->getDisplay();
$this->assertContains("Two-factor authentication is not enforced", $display); $this->assertStringContainsString("Two-factor authentication is not enforced", $display);
} }
public function testCurrentStateEnabled() { public function testCurrentStateEnabled() {
@ -129,7 +129,7 @@ class EnforceTest extends TestCase {
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$display = $this->command->getDisplay(); $display = $this->command->getDisplay();
$this->assertContains("Two-factor authentication is enforced for all users", $display); $this->assertStringContainsString("Two-factor authentication is enforced for all users", $display);
} }
public function testCurrentStateDisabled() { public function testCurrentStateDisabled() {
@ -141,6 +141,6 @@ class EnforceTest extends TestCase {
$this->assertEquals(0, $rc); $this->assertEquals(0, $rc);
$display = $this->command->getDisplay(); $display = $this->command->getDisplay();
$this->assertContains("Two-factor authentication is not enforced", $display); $this->assertStringContainsString("Two-factor authentication is not enforced", $display);
} }
} }

View File

@ -61,7 +61,7 @@ class StateTest extends TestCase {
]); ]);
$output = $this->cmd->getDisplay(); $output = $this->cmd->getDisplay();
$this->assertContains("Invalid UID", $output); $this->assertStringContainsString("Invalid UID", $output);
} }
public function testStateNoProvidersActive() { public function testStateNoProvidersActive() {
@ -84,7 +84,7 @@ class StateTest extends TestCase {
]); ]);
$output = $this->cmd->getDisplay(); $output = $this->cmd->getDisplay();
$this->assertContains("Two-factor authentication is not enabled for user eldora", $output); $this->assertStringContainsString("Two-factor authentication is not enabled for user eldora", $output);
} }
public function testStateOneProviderActive() { public function testStateOneProviderActive() {
@ -107,6 +107,6 @@ class StateTest extends TestCase {
]); ]);
$output = $this->cmd->getDisplay(); $output = $this->cmd->getDisplay();
$this->assertContains("Two-factor authentication is enabled for user mohamed", $output); $this->assertStringContainsString("Two-factor authentication is enabled for user mohamed", $output);
} }
} }

View File

@ -45,7 +45,7 @@ class DownloadResponseTest extends \Test\TestCase {
public function testHeaders() { public function testHeaders() {
$headers = $this->response->getHeaders(); $headers = $this->response->getHeaders();
$this->assertContains('attachment; filename="file"', $headers['Content-Disposition']); $this->assertStringContainsString('attachment; filename="file"', $headers['Content-Disposition']);
$this->assertContains('content', $headers['Content-Type']); $this->assertStringContainsString('content', $headers['Content-Type']);
} }
} }

View File

@ -71,9 +71,7 @@ class ConfigTest extends TestCase {
public function testSetValue() { public function testSetValue() {
$this->config->setValue('foo', 'moo'); $this->config->setValue('foo', 'moo');
$expectedConfig = $this->initialConfig; $this->assertSame('moo', $this->config->getValue('foo'));
$expectedConfig['foo'] = 'moo';
$this->assertAttributeEquals($expectedConfig, 'cache', $this->config);
$content = file_get_contents($this->configFile); $content = file_get_contents($this->configFile);
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " . $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " .
@ -82,9 +80,8 @@ class ConfigTest extends TestCase {
$this->config->setValue('bar', 'red'); $this->config->setValue('bar', 'red');
$this->config->setValue('apps', ['files', 'gallery']); $this->config->setValue('apps', ['files', 'gallery']);
$expectedConfig['bar'] = 'red'; $this->assertSame('red', $this->config->getValue('bar'));
$expectedConfig['apps'] = ['files', 'gallery']; $this->assertSame(['files', 'gallery'], $this->config->getValue('apps'));
$this->assertAttributeEquals($expectedConfig, 'cache', $this->config);
$content = file_get_contents($this->configFile); $content = file_get_contents($this->configFile);
@ -105,7 +102,8 @@ class ConfigTest extends TestCase {
'not_exists' => null, 'not_exists' => null,
]); ]);
$this->assertAttributeEquals($this->initialConfig, 'cache', $this->config); $this->assertSame('bar', $this->config->getValue('foo'));
$this->assertSame(null, $this->config->getValue('not_exists'));
$content = file_get_contents($this->configFile); $content = file_get_contents($this->configFile);
$this->assertEquals(self::TESTCONTENT, $content); $this->assertEquals(self::TESTCONTENT, $content);
@ -113,10 +111,8 @@ class ConfigTest extends TestCase {
'foo' => 'moo', 'foo' => 'moo',
'alcohol_free' => null, 'alcohol_free' => null,
]); ]);
$expectedConfig = $this->initialConfig; $this->assertSame('moo', $this->config->getValue('foo'));
$expectedConfig['foo'] = 'moo'; $this->assertSame(null, $this->config->getValue('not_exists'));
unset($expectedConfig['alcohol_free']);
$this->assertAttributeEquals($expectedConfig, 'cache', $this->config);
$content = file_get_contents($this->configFile); $content = file_get_contents($this->configFile);
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " . $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " .
@ -126,9 +122,7 @@ class ConfigTest extends TestCase {
public function testDeleteKey() { public function testDeleteKey() {
$this->config->deleteKey('foo'); $this->config->deleteKey('foo');
$expectedConfig = $this->initialConfig; $this->assertSame('this_was_clearly_not_set_before', $this->config->getValue('foo', 'this_was_clearly_not_set_before'));
unset($expectedConfig['foo']);
$this->assertAttributeEquals($expectedConfig, 'cache', $this->config);
$content = file_get_contents($this->configFile); $content = file_get_contents($this->configFile);
$expected = "<?php\n\$CONFIG = array (\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " . $expected = "<?php\n\$CONFIG = array (\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " .

View File

@ -83,8 +83,8 @@ class DBSchemaTest extends TestCase {
$outfile = $this->tempManager->getTemporaryFile(); $outfile = $this->tempManager->getTemporaryFile();
OC_DB::getDbStructure($outfile); OC_DB::getDbStructure($outfile);
$content = file_get_contents($outfile); $content = file_get_contents($outfile);
$this->assertContains($this->table1, $content); $this->assertStringContainsString($this->table1, $content);
$this->assertContains($this->table2, $content); $this->assertStringContainsString($this->table2, $content);
} }
public function doTestSchemaRemoving() { public function doTestSchemaRemoving() {

View File

@ -329,7 +329,7 @@ class FactoryTest extends TestCase {
->with($app) ->with($app)
->willReturn(\OC::$SERVERROOT . '/tests/data/l10n/'); ->willReturn(\OC::$SERVERROOT . '/tests/data/l10n/');
$this->assertEquals(['cs', 'de', 'en', 'ru'], $factory->findAvailableLanguages($app), '', 0.0, 10, true); $this->assertEqualsCanonicalizing(['cs', 'de', 'en', 'ru'], $factory->findAvailableLanguages($app));
} }
public function dataLanguageExists() { public function dataLanguageExists() {
@ -360,7 +360,7 @@ class FactoryTest extends TestCase {
->with('theme') ->with('theme')
->willReturn('abc'); ->willReturn('abc');
$this->assertEquals(['en', 'zz'], $factory->findAvailableLanguages($app), '', 0.0, 10, true); $this->assertEqualsCanonicalizing(['en', 'zz'], $factory->findAvailableLanguages($app));
} }
/** /**

View File

@ -107,16 +107,6 @@ class CSSResourceLocatorTest extends \Test\TestCase {
return sha1(uniqid(mt_rand(), true)); return sha1(uniqid(mt_rand(), true));
} }
public function testConstructor() {
$locator = $this->cssResourceLocator();
$this->assertAttributeEquals('theme', 'theme', $locator);
$this->assertAttributeEquals('core', 'serverroot', $locator);
$this->assertAttributeEquals(['core'=>'map','3rd'=>'party'], 'mapping', $locator);
$this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
$this->assertAttributeEquals('map', 'webroot', $locator);
$this->assertAttributeEquals([], 'resources', $locator);
}
public function testFindWithAppPathSymlink() { public function testFindWithAppPathSymlink() {
// First create new apps path, and a symlink to it // First create new apps path, and a symlink to it
$apps_dirname = $this->randomString(); $apps_dirname = $this->randomString();

View File

@ -86,17 +86,6 @@ class JSResourceLocatorTest extends \Test\TestCase {
return sha1(uniqid(mt_rand(), true)); return sha1(uniqid(mt_rand(), true));
} }
public function testConstructor() {
$locator = $this->jsResourceLocator();
$this->assertAttributeEquals('theme', 'theme', $locator);
$this->assertAttributeEquals('core', 'serverroot', $locator);
$this->assertAttributeEquals(['core'=>'map','3rd'=>'party'], 'mapping', $locator);
$this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
$this->assertAttributeEquals('map', 'webroot', $locator);
$this->assertAttributeEquals([], 'resources', $locator);
}
public function testFindWithAppPathSymlink() { public function testFindWithAppPathSymlink() {
// First create new apps path, and a symlink to it // First create new apps path, and a symlink to it
$apps_dirname = $this->randomString(); $apps_dirname = $this->randomString();

View File

@ -33,17 +33,6 @@ class ResourceLocatorTest extends \Test\TestCase {
'', true, true, true, []); '', true, true, true, []);
} }
public function testConstructor() {
$locator = $this->getResourceLocator('theme',
['core'=>'map'], ['3rd'=>'party'], ['foo'=>'bar']);
$this->assertAttributeEquals('theme', 'theme', $locator);
$this->assertAttributeEquals('core', 'serverroot', $locator);
$this->assertAttributeEquals(['core'=>'map','3rd'=>'party'], 'mapping', $locator);
$this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator);
$this->assertAttributeEquals('map', 'webroot', $locator);
$this->assertAttributeEquals([], 'resources', $locator);
}
public function testFind() { public function testFind() {
$locator = $this->getResourceLocator('theme', $locator = $this->getResourceLocator('theme',
['core' => 'map'], ['3rd' => 'party'], ['foo' => 'bar']); ['core' => 'map'], ['3rd' => 'party'], ['foo' => 'bar']);