test: Remove more withConsecutive

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/52851/head
Joas Schilling 12 months ago
parent 158b3ef859
commit 53b116b8a5
No known key found for this signature in database
GPG Key ID: F72FA5B49FFA96B0
  1. 95
      tests/lib/AppFramework/Db/QBMapperTest.php
  2. 41
      tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php
  3. 53
      tests/lib/AppFramework/Routing/RoutingTest.php
  4. 15
      tests/lib/Authentication/Listeners/UserDeletedTokenCleanupListenerTest.php
  5. 4
      tests/lib/Authentication/Login/ALoginTestCommand.php
  6. 2
      tests/lib/Authentication/Login/ClearLostPasswordTokensCommandTest.php
  7. 2
      tests/lib/Authentication/Login/CompleteLoginCommandTest.php
  8. 2
      tests/lib/Authentication/Login/CreateSessionTokenCommandTest.php
  9. 2
      tests/lib/Authentication/Login/FinishRememberedLoginCommandTest.php
  10. 2
      tests/lib/Authentication/Login/LoggedInCheckCommandTest.php
  11. 2
      tests/lib/Authentication/Login/PreLoginHookCommandTest.php
  12. 2
      tests/lib/Authentication/Login/SetUserTimezoneCommandTest.php
  13. 2
      tests/lib/Authentication/Login/TwoFactorCommandTest.php
  14. 2
      tests/lib/Authentication/Login/UidLoginCommandTest.php
  15. 2
      tests/lib/Authentication/Login/UpdateLastPasswordConfirmCommandTest.php
  16. 2
      tests/lib/Authentication/Login/UserDisabledCheckCommandTest.php
  17. 41
      tests/lib/Authentication/Token/ManagerTest.php
  18. 47
      tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
  19. 115
      tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
  20. 13
      tests/lib/Authentication/TwoFactorAuth/RegistryTest.php
  21. 20
      tests/lib/Command/AsyncBusTestCase.php
  22. 5
      tests/lib/Command/BackgroundModeTest.php
  23. 5
      tests/lib/Command/CronBusTest.php
  24. 217
      tests/lib/Command/Integrity/SignAppTest.php
  25. 166
      tests/lib/Command/Integrity/SignCoreTest.php
  26. 107
      tests/lib/LegacyHelperTest.php

@ -99,7 +99,7 @@ class QBMapperTest extends \Test\TestCase {
$this->mapper = new QBTestMapper($this->db);
}
public function testInsertEntityParameterTypeMapping(): void {
$datetime = new \DateTimeImmutable();
$entity = new QBTestEntity();
@ -117,31 +117,40 @@ class QBMapperTest extends \Test\TestCase {
$booleanParam = $this->qb->createNamedParameter('boolean_prop', IQueryBuilder::PARAM_BOOL);
$datetimeParam = $this->qb->createNamedParameter('datetime_prop', IQueryBuilder::PARAM_DATETIME_IMMUTABLE);
$createNamedParameterCalls = [
[123, IQueryBuilder::PARAM_INT, null],
[true, IQueryBuilder::PARAM_BOOL, null],
['string', IQueryBuilder::PARAM_STR, null],
[456, IQueryBuilder::PARAM_INT, null],
[false, IQueryBuilder::PARAM_BOOL, null],
[$datetime, IQueryBuilder::PARAM_DATETIME_IMMUTABLE, null],
];
$this->qb->expects($this->exactly(6))
->method('createNamedParameter')
->withConsecutive(
[$this->equalTo(123), $this->equalTo(IQueryBuilder::PARAM_INT)],
[$this->equalTo(true), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
[$this->equalTo('string'), $this->equalTo(IQueryBuilder::PARAM_STR)],
[$this->equalTo(456), $this->equalTo(IQueryBuilder::PARAM_INT)],
[$this->equalTo(false), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
[$this->equalTo($datetime), $this->equalTo(IQueryBuilder::PARAM_DATETIME_IMMUTABLE)],
);
->willReturnCallback(function() use (&$createNamedParameterCalls) {
$expected = array_shift($createNamedParameterCalls);
$this->assertEquals($expected, func_get_args());
});
$setValueCalls = [
['int_prop', $intParam],
['bool_prop', $boolParam],
['string_prop', $stringParam],
['integer_prop', $integerParam],
['boolean_prop', $booleanParam],
['datetime_prop', $datetimeParam],
];
$this->qb->expects($this->exactly(6))
->method('setValue')
->withConsecutive(
[$this->equalTo('int_prop'), $this->equalTo($intParam)],
[$this->equalTo('bool_prop'), $this->equalTo($boolParam)],
[$this->equalTo('string_prop'), $this->equalTo($stringParam)],
[$this->equalTo('integer_prop'), $this->equalTo($integerParam)],
[$this->equalTo('boolean_prop'), $this->equalTo($booleanParam)],
[$this->equalTo('datetime_prop'), $this->equalTo($datetimeParam)],
);
->willReturnCallback(function() use (&$setValueCalls) {
$expected = array_shift($setValueCalls);
$this->assertEquals($expected, func_get_args());
});
$this->mapper->insert($entity);
}
public function testUpdateEntityParameterTypeMapping(): void {
$datetime = new \DateTimeImmutable();
$entity = new QBTestEntity();
@ -163,30 +172,38 @@ class QBMapperTest extends \Test\TestCase {
$jsonParam = $this->qb->createNamedParameter('json_prop', IQueryBuilder::PARAM_JSON);
$datetimeParam = $this->qb->createNamedParameter('datetime_prop', IQueryBuilder::PARAM_DATETIME_IMMUTABLE);
$createNamedParameterCalls = [
[123, IQueryBuilder::PARAM_INT, null],
[true, IQueryBuilder::PARAM_BOOL, null],
['string', IQueryBuilder::PARAM_STR, null],
[456, IQueryBuilder::PARAM_INT, null],
[false, IQueryBuilder::PARAM_BOOL, null],
[['hello' => 'world'], IQueryBuilder::PARAM_JSON, null],
[$datetime, IQueryBuilder::PARAM_DATETIME_IMMUTABLE, null],
[789, IQueryBuilder::PARAM_INT, null],
];
$this->qb->expects($this->exactly(8))
->method('createNamedParameter')
->withConsecutive(
[$this->equalTo(123), $this->equalTo(IQueryBuilder::PARAM_INT)],
[$this->equalTo(true), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
[$this->equalTo('string'), $this->equalTo(IQueryBuilder::PARAM_STR)],
[$this->equalTo(456), $this->equalTo(IQueryBuilder::PARAM_INT)],
[$this->equalTo(false), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
[$this->equalTo(['hello' => 'world']), $this->equalTo(IQueryBuilder::PARAM_JSON)],
[$this->equalTo($datetime), $this->equalTo(IQueryBuilder::PARAM_DATETIME_IMMUTABLE)],
[$this->equalTo(789), $this->equalTo(IQueryBuilder::PARAM_INT)],
);
->willReturnCallback(function() use (&$createNamedParameterCalls) {
$expected = array_shift($createNamedParameterCalls);
$this->assertEquals($expected, func_get_args());
});
$setCalls = [
['int_prop', $intParam],
['bool_prop', $boolParam],
['string_prop', $stringParam],
['integer_prop', $integerParam],
['boolean_prop', $booleanParam],
['json_prop', $datetimeParam],
['datetime_prop', $datetimeParam],
];
$this->qb->expects($this->exactly(7))
->method('set')
->withConsecutive(
[$this->equalTo('int_prop'), $this->equalTo($intParam)],
[$this->equalTo('bool_prop'), $this->equalTo($boolParam)],
[$this->equalTo('string_prop'), $this->equalTo($stringParam)],
[$this->equalTo('integer_prop'), $this->equalTo($integerParam)],
[$this->equalTo('boolean_prop'), $this->equalTo($booleanParam)],
[$this->equalTo('json_prop'), $this->equalTo($jsonParam)],
[$this->equalTo('datetime_prop'), $this->equalTo($datetimeParam)],
);
->willReturnCallback(function() use (&$setCalls) {
$expected = array_shift($setCalls);
$this->assertEquals($expected, func_get_args());
});
$this->expr->expects($this->once())
->method('eq')
@ -196,7 +213,7 @@ class QBMapperTest extends \Test\TestCase {
$this->mapper->update($entity);
}
public function testGetParameterTypeForProperty(): void {
$entity = new QBTestEntity();

@ -98,13 +98,19 @@ class BruteForceMiddlewareTest extends TestCase {
->expects($this->once())
->method('getRemoteAddress')
->willReturn('::1');
$calls = [
['::1', 'first'],
['::1', 'second'],
];
$this->throttler
->expects($this->exactly(2))
->method('sleepDelayOrThrowOnMax')
->withConsecutive(
['::1', 'first'],
['::1', 'second'],
);
->willReturnCallback(function() use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
return 0;
});
$controller = new TestController('test', $this->request);
$this->reflector->reflect($controller, 'multipleAttributes');
@ -221,20 +227,31 @@ class BruteForceMiddlewareTest extends TestCase {
->expects($this->once())
->method('getRemoteAddress')
->willReturn('::1');
$sleepCalls = [
['::1', 'first'],
['::1', 'second'],
];
$this->throttler
->expects($this->exactly(2))
->method('sleepDelayOrThrowOnMax')
->withConsecutive(
['::1', 'first'],
['::1', 'second'],
);
->willReturnCallback(function() use (&$sleepCalls) {
$expected = array_shift($sleepCalls);
$this->assertEquals($expected, func_get_args());
return 0;
});
$attemptCalls = [
['first', '::1', []],
['second', '::1', []],
];
$this->throttler
->expects($this->exactly(2))
->method('registerAttempt')
->withConsecutive(
['first', '::1'],
['second', '::1'],
);
->willReturnCallback(function() use (&$attemptCalls) {
$expected = array_shift($attemptCalls);
$this->assertEquals($expected, func_get_args());
});
$controller = new TestController('test', $this->request);
$this->reflector->reflect($controller, 'multipleAttributes');

@ -348,23 +348,24 @@ class RoutingTest extends \Test\TestCase {
$urlWithParam = $url . '/{' . $paramName . '}';
$calls = [
['name' => 'ocs.app1.' . $resourceName . '.index', 'pattern' => $url, 'route' => $indexRoute],
['name' => 'ocs.app1.' . $resourceName . '.show', 'pattern' => $urlWithParam, 'route' => $showRoute],
['name' => 'ocs.app1.' . $resourceName . '.create', 'pattern' => $url, 'route' => $createRoute],
['name' => 'ocs.app1.' . $resourceName . '.update', 'pattern' => $urlWithParam, 'route' => $updateRoute],
['name' => 'ocs.app1.' . $resourceName . '.destroy', 'pattern' => $urlWithParam, 'route' => $destroyRoute],
];
// we expect create to be called five times:
$router
->expects($this->exactly(5))
->method('create')
->withConsecutive(
[$this->equalTo('ocs.app1.' . $resourceName . '.index'), $this->equalTo($url)],
[$this->equalTo('ocs.app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)],
[$this->equalTo('ocs.app1.' . $resourceName . '.create'), $this->equalTo($url)],
[$this->equalTo('ocs.app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)],
[$this->equalTo('ocs.app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)],
)->willReturnOnConsecutiveCalls(
$indexRoute,
$showRoute,
$createRoute,
$updateRoute,
$destroyRoute,
);
->willReturnCallback(function(string $name, string $pattern) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected['name'], $name);
$this->assertEquals($expected['pattern'], $pattern);
return $expected['route'];
});
// load route configuration
$config = new RouteConfig($container, $router, $yaml);
@ -402,23 +403,23 @@ class RoutingTest extends \Test\TestCase {
$urlWithParam = $url . '/{' . $paramName . '}';
$calls = [
['name' => 'app1.' . $resourceName . '.index', 'pattern' => $url, 'route' => $indexRoute],
['name' => 'app1.' . $resourceName . '.show', 'pattern' => $urlWithParam, 'route' => $showRoute],
['name' => 'app1.' . $resourceName . '.create', 'pattern' => $url, 'route' => $createRoute],
['name' => 'app1.' . $resourceName . '.update', 'pattern' => $urlWithParam, 'route' => $updateRoute],
['name' => 'app1.' . $resourceName . '.destroy', 'pattern' => $urlWithParam, 'route' => $destroyRoute],
];
// we expect create to be called five times:
$router
->expects($this->exactly(5))
->method('create')
->withConsecutive(
[$this->equalTo('app1.' . $resourceName . '.index'), $this->equalTo($url)],
[$this->equalTo('app1.' . $resourceName . '.show'), $this->equalTo($urlWithParam)],
[$this->equalTo('app1.' . $resourceName . '.create'), $this->equalTo($url)],
[$this->equalTo('app1.' . $resourceName . '.update'), $this->equalTo($urlWithParam)],
[$this->equalTo('app1.' . $resourceName . '.destroy'), $this->equalTo($urlWithParam)],
)->willReturnOnConsecutiveCalls(
$indexRoute,
$showRoute,
$createRoute,
$updateRoute,
$destroyRoute,
);
->willReturnCallback(function(string $name, string $pattern) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected['name'], $name);
$this->assertEquals($expected['pattern'], $pattern);
return $expected['route'];
});
// load route configuration
$config = new RouteConfig($container, $router, $yaml);

@ -83,13 +83,18 @@ class UserDeletedTokenCleanupListenerTest extends TestCase {
$token2,
$token3,
]);
$calls = [
['user123', 1],
['user123', 2],
['user123', 3],
];
$this->manager->expects($this->exactly(3))
->method('invalidateTokenById')
->withConsecutive(
['user123', 1],
['user123', 2],
['user123', 3]
);
->willReturnCallback(function() use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->logger->expects($this->never())
->method('error');

@ -15,7 +15,7 @@ use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
abstract class ALoginCommandTest extends TestCase {
abstract class ALoginTestCommand extends TestCase {
/** @var IRequest|MockObject */
protected $request;
@ -36,7 +36,7 @@ abstract class ALoginCommandTest extends TestCase {
/** @var IUser|MockObject */
protected $user;
/** @var ALoginCommand */
/** @var ALoginTestCommand */
protected $cmd;
protected function setUp(): void {

@ -13,7 +13,7 @@ use OC\Authentication\Login\ClearLostPasswordTokensCommand;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
class ClearLostPasswordTokensCommandTest extends ALoginCommandTest {
class ClearLostPasswordTokensCommandTest extends ALoginTestCommand {
/** @var IConfig|MockObject */
private $config;

@ -13,7 +13,7 @@ use OC\Authentication\Login\CompleteLoginCommand;
use OC\User\Session;
use PHPUnit\Framework\MockObject\MockObject;
class CompleteLoginCommandTest extends ALoginCommandTest {
class CompleteLoginCommandTest extends ALoginTestCommand {
/** @var Session|MockObject */
private $session;

@ -15,7 +15,7 @@ use OC\User\Session;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
class CreateSessionTokenCommandTest extends ALoginCommandTest {
class CreateSessionTokenCommandTest extends ALoginTestCommand {
/** @var IConfig|MockObject */
private $config;

@ -14,7 +14,7 @@ use OC\User\Session;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
class FinishRememberedLoginCommandTest extends ALoginCommandTest {
class FinishRememberedLoginCommandTest extends ALoginTestCommand {
/** @var Session|MockObject */
private $userSession;
/** @var IConfig|MockObject */

@ -15,7 +15,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class LoggedInCheckCommandTest extends ALoginCommandTest {
class LoggedInCheckCommandTest extends ALoginTestCommand {
/** @var LoggerInterface|MockObject */
private $logger;

@ -14,7 +14,7 @@ use OC\User\Manager;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
class PreLoginHookCommandTest extends ALoginCommandTest {
class PreLoginHookCommandTest extends ALoginTestCommand {
/** @var IUserManager|MockObject */
private $userManager;

@ -14,7 +14,7 @@ use OCP\IConfig;
use OCP\ISession;
use PHPUnit\Framework\MockObject\MockObject;
class SetUserTimezoneCommandTest extends ALoginCommandTest {
class SetUserTimezoneCommandTest extends ALoginTestCommand {
/** @var IConfig|MockObject */
private $config;

@ -18,7 +18,7 @@ use OCP\Authentication\TwoFactorAuth\IProvider as ITwoFactorAuthProvider;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
class TwoFactorCommandTest extends ALoginCommandTest {
class TwoFactorCommandTest extends ALoginTestCommand {
/** @var Manager|MockObject */
private $twoFactorManager;

@ -13,7 +13,7 @@ use OC\Authentication\Login\UidLoginCommand;
use OC\User\Manager;
use PHPUnit\Framework\MockObject\MockObject;
class UidLoginCommandTest extends ALoginCommandTest {
class UidLoginCommandTest extends ALoginTestCommand {
/** @var Manager|MockObject */
private $userManager;

@ -13,7 +13,7 @@ use OC\Authentication\Login\UpdateLastPasswordConfirmCommand;
use OCP\ISession;
use PHPUnit\Framework\MockObject\MockObject;
class UpdateLastPasswordConfirmCommandTest extends ALoginCommandTest {
class UpdateLastPasswordConfirmCommandTest extends ALoginTestCommand {
/** @var ISession|MockObject */
private $session;

@ -15,7 +15,7 @@ use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class UserDisabledCheckCommandTest extends ALoginCommandTest {
class UserDisabledCheckCommandTest extends ALoginTestCommand {
/** @var IUserManager|MockObject */
private $userManager;

@ -128,10 +128,10 @@ class ManagerTest extends TestCase {
$this->assertSame(121, mb_strlen($actual->getName()));
}
public function tokenData(): array {
public static function tokenData(): array {
return [
[new PublicKeyToken()],
[$this->createMock(IToken::class)],
[IToken::class],
];
}
@ -160,7 +160,11 @@ class ManagerTest extends TestCase {
/**
* @dataProvider tokenData
*/
public function testUpdateToken(IToken $token): void {
public function testUpdateToken(IToken|string $token): void {
if (is_string($token)) {
$token = $this->createMock($token);
}
$this->setNoCall($token);
$this->setCall($token, 'updateToken');
$this->setException($token);
@ -171,7 +175,11 @@ class ManagerTest extends TestCase {
/**
* @dataProvider tokenData
*/
public function testUpdateTokenActivity(IToken $token): void {
public function testUpdateTokenActivity(IToken|string $token): void {
if (is_string($token)) {
$token = $this->createMock($token);
}
$this->setNoCall($token);
$this->setCall($token, 'updateTokenActivity');
$this->setException($token);
@ -182,7 +190,11 @@ class ManagerTest extends TestCase {
/**
* @dataProvider tokenData
*/
public function testGetPassword(IToken $token): void {
public function testGetPassword(IToken|string $token): void {
if (is_string($token)) {
$token = $this->createMock($token);
}
$this->setNoCall($token);
$this->setCall($token, 'getPassword', 'password');
$this->setException($token);
@ -195,7 +207,11 @@ class ManagerTest extends TestCase {
/**
* @dataProvider tokenData
*/
public function testSetPassword(IToken $token): void {
public function testSetPassword(IToken|string $token): void {
if (is_string($token)) {
$token = $this->createMock($token);
}
$this->setNoCall($token);
$this->setCall($token, 'setPassword');
$this->setException($token);
@ -358,13 +374,18 @@ class ManagerTest extends TestCase {
->method('getTokenByUser')
->with('theUser')
->willReturn([$t1, $t2]);
$calls = [
['theUser', 123],
['theUser', 456],
];
$this->publicKeyTokenProvider
->expects($this->exactly(2))
->method('invalidateTokenById')
->withConsecutive(
['theUser', 123],
['theUser', 456],
);
->willReturnCallback(function() use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->manager->invalidateTokensOfUser('theUser', null);
}

@ -304,12 +304,17 @@ class PublicKeyTokenProviderTest extends TestCase {
}
public function testInvalidateToken(): void {
$calls = [
[hash('sha512', 'token7' . '1f4h9s')],
[hash('sha512', 'token7')]
];
$this->mapper->expects($this->exactly(2))
->method('invalidate')
->withConsecutive(
[hash('sha512', 'token7' . '1f4h9s')],
[hash('sha512', 'token7')]
);
->willReturnCallback(function() use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->tokenProvider->invalidateToken('token7');
}
@ -336,14 +341,19 @@ class PublicKeyTokenProviderTest extends TestCase {
['token_auth_wipe_token_retention', $wipeTokenLifetime, 500],
['token_auth_token_retention', 60 * 60 * 24 * 365, 800],
]);
$calls = [
[$this->time - 150, IToken::TEMPORARY_TOKEN, IToken::DO_NOT_REMEMBER],
[$this->time - 300, IToken::TEMPORARY_TOKEN, IToken::REMEMBER],
[$this->time - 500, IToken::WIPE_TOKEN, null],
[$this->time - 800, IToken::PERMANENT_TOKEN, null],
];
$this->mapper->expects($this->exactly(4))
->method('invalidateOld')
->withConsecutive(
[$this->time - 150, IToken::TEMPORARY_TOKEN, IToken::DO_NOT_REMEMBER],
[$this->time - 300, IToken::TEMPORARY_TOKEN, IToken::REMEMBER],
[$this->time - 500, IToken::WIPE_TOKEN, null],
[$this->time - 800, IToken::PERMANENT_TOKEN, null],
);
->willReturnCallback(function() use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->tokenProvider->invalidateOldTokens();
}
@ -453,16 +463,17 @@ class PublicKeyTokenProviderTest extends TestCase {
public function testGetInvalidToken(): void {
$this->expectException(InvalidTokenException::class);
$calls = [
'unhashedTokentokentokentokentoken' . '1f4h9s',
'unhashedTokentokentokentokentoken',
];
$this->mapper->expects($this->exactly(2))
->method('getToken')
->withConsecutive(
[$this->callback(function (string $token): bool {
return hash('sha512', 'unhashedTokentokentokentokentoken' . '1f4h9s') === $token;
})],
[$this->callback(function (string $token): bool {
return hash('sha512', 'unhashedTokentokentokentokentoken') === $token;
})]
)->willThrowException(new DoesNotExistException('nope'));
->willReturnCallback(function (string $token) use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals(hash('sha512', $expected), $token);
throw new DoesNotExistException('nope');
});
$this->tokenProvider->getToken('unhashedTokentokentokentokentoken');
}

@ -204,7 +204,7 @@ class ManagerTest extends TestCase {
$this->assertTrue($this->manager->isTwoFactorAuthenticated($this->user));
}
public function providerStatesFixData(): array {
public static function providerStatesFixData(): array {
return [
[false, false],
[true, true],
@ -356,12 +356,18 @@ class ManagerTest extends TestCase {
->method('get')
->with('two_factor_remember_login')
->willReturn(false);
$calls = [
['two_factor_auth_uid'],
['two_factor_remember_login'],
];
$this->session->expects($this->exactly(2))
->method('remove')
->withConsecutive(
['two_factor_auth_uid'],
['two_factor_remember_login']
);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->session->expects($this->once())
->method('set')
->with(Manager::SESSION_UID_DONE, 'jos');
@ -474,14 +480,19 @@ class ManagerTest extends TestCase {
public function testNeedsSecondFactor(): void {
$user = $this->createMock(IUser::class);
$calls = [
['app_password'],
['two_factor_auth_uid'],
[Manager::SESSION_UID_DONE],
];
$this->session->expects($this->exactly(3))
->method('exists')
->withConsecutive(
['app_password'],
['two_factor_auth_uid'],
[Manager::SESSION_UID_DONE],
)
->willReturn(false);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
return false;
});
$this->session->method('getId')
->willReturn('mysessionid');
@ -513,7 +524,7 @@ class ManagerTest extends TestCase {
$this->timeFactory,
$this->dispatcher,
])
->setMethods(['loadTwoFactorApp', 'isTwoFactorAuthenticated'])// Do not actually load the apps
->onlyMethods(['isTwoFactorAuthenticated'])// Do not actually load the apps
->getMock();
$manager->method('isTwoFactorAuthenticated')
@ -550,12 +561,16 @@ class ManagerTest extends TestCase {
$this->user->method('getUID')
->willReturn('ferdinand');
$calls = [
['two_factor_auth_uid', 'ferdinand'],
['two_factor_remember_login', true],
];
$this->session->expects($this->exactly(2))
->method('set')
->withConsecutive(
['two_factor_auth_uid', 'ferdinand'],
['two_factor_remember_login', true]
);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->session->method('getId')
->willReturn('mysessionid');
@ -580,12 +595,16 @@ class ManagerTest extends TestCase {
$this->user->method('getUID')
->willReturn('ferdinand');
$calls = [
['two_factor_auth_uid', 'ferdinand'],
['two_factor_remember_login', false],
];
$this->session->expects($this->exactly(2))
->method('set')
->withConsecutive(
['two_factor_auth_uid', 'ferdinand'],
['two_factor_remember_login', false]
);
->willReturnCallback(function () use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->session->method('getId')
->willReturn('mysessionid');
@ -710,21 +729,29 @@ class ManagerTest extends TestCase {
'42', '43', '44'
]);
$deleteUserValueCalls = [
['theUserId', 'login_token_2fa', '42'],
['theUserId', 'login_token_2fa', '43'],
['theUserId', 'login_token_2fa', '44'],
];
$this->config->expects($this->exactly(3))
->method('deleteUserValue')
->withConsecutive(
['theUserId', 'login_token_2fa', '42'],
['theUserId', 'login_token_2fa', '43'],
['theUserId', 'login_token_2fa', '44'],
);
->willReturnCallback(function () use (&$deleteUserValueCalls) {
$expected = array_shift($deleteUserValueCalls);
$this->assertEquals($expected, func_get_args());
});
$invalidateCalls = [
['theUserId', 42],
['theUserId', 43],
['theUserId', 44],
];
$this->tokenProvider->expects($this->exactly(3))
->method('invalidateTokenById')
->withConsecutive(
['theUserId', 42],
['theUserId', 43],
['theUserId', 44],
);
->willReturnCallback(function () use (&$invalidateCalls) {
$expected = array_shift($invalidateCalls);
$this->assertEquals($expected, func_get_args());
});
$this->manager->clearTwoFactorPending('theUserId');
}
@ -736,22 +763,28 @@ class ManagerTest extends TestCase {
'42', '43', '44'
]);
$deleteUserValueCalls = [
['theUserId', 'login_token_2fa', '42'],
['theUserId', 'login_token_2fa', '43'],
['theUserId', 'login_token_2fa', '44'],
];
$this->config->expects($this->exactly(3))
->method('deleteUserValue')
->withConsecutive(
['theUserId', 'login_token_2fa', '42'],
['theUserId', 'login_token_2fa', '43'],
['theUserId', 'login_token_2fa', '44'],
);
->willReturnCallback(function () use (&$deleteUserValueCalls) {
$expected = array_shift($deleteUserValueCalls);
$this->assertEquals($expected, func_get_args());
});
$invalidateCalls = [
['theUserId', 42],
['theUserId', 43],
['theUserId', 44],
];
$this->tokenProvider->expects($this->exactly(3))
->method('invalidateTokenById')
->withConsecutive(
['theUserId', 42],
['theUserId', 43],
['theUserId', 44],
)
->willReturnCallback(function ($user, $tokenId) {
->willReturnCallback(function ($user, $tokenId) use (&$invalidateCalls) {
$expected = array_shift($invalidateCalls);
$this->assertEquals($expected, func_get_args());
if ($tokenId === 43) {
throw new DoesNotExistException('token does not exist');
}

@ -119,12 +119,17 @@ class RegistryTest extends TestCase {
'provider_id' => 'twofactor_u2f',
]
]);
$calls = [
[new TwoFactorProviderDisabled('twofactor_u2f')],
[new TwoFactorProviderUserDeleted($user, 'twofactor_u2f')],
];
$this->dispatcher->expects($this->exactly(2))
->method('dispatchTyped')
->withConsecutive(
[new TwoFactorProviderDisabled('twofactor_u2f')],
[new TwoFactorProviderUserDeleted($user, 'twofactor_u2f')],
);
->willReturnCallback(function() use (&$calls) {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
$this->registry->deleteUserData($user);
}

@ -15,7 +15,7 @@ use Test\TestCase;
class SimpleCommand implements ICommand {
public function handle() {
AsyncBusTest::$lastCommand = 'SimpleCommand';
AsyncBusTestCase::$lastCommand = 'SimpleCommand';
}
}
@ -27,7 +27,7 @@ class StateFullCommand implements ICommand {
}
public function handle() {
AsyncBusTest::$lastCommand = $this->state;
AsyncBusTestCase::$lastCommand = $this->state;
}
}
@ -35,18 +35,18 @@ class FilesystemCommand implements ICommand {
use FileAccess;
public function handle() {
AsyncBusTest::$lastCommand = 'FileAccess';
AsyncBusTestCase::$lastCommand = 'FileAccess';
}
}
function basicFunction() {
AsyncBusTest::$lastCommand = 'function';
AsyncBusTestCase::$lastCommand = 'function';
}
// clean class to prevent phpunit putting closure in $this
class ThisClosureTest {
private function privateMethod() {
AsyncBusTest::$lastCommand = 'closure-this';
AsyncBusTestCase::$lastCommand = 'closure-this';
}
public function test(IBus $bus) {
@ -56,7 +56,7 @@ class ThisClosureTest {
}
}
abstract class AsyncBusTest extends TestCase {
abstract class AsyncBusTestCase extends TestCase {
/**
* Basic way to check output from a command
*
@ -107,7 +107,7 @@ abstract class AsyncBusTest extends TestCase {
}
public function testStaticCallable(): void {
$this->getBus()->push(['\Test\Command\AsyncBusTest', 'DummyCommand']);
$this->getBus()->push(['\Test\Command\AsyncBusTestCase', 'DummyCommand']);
$this->runJobs();
$this->assertEquals('static', self::$lastCommand);
}
@ -127,7 +127,7 @@ abstract class AsyncBusTest extends TestCase {
public function testClosure(): void {
$this->getBus()->push(function () {
AsyncBusTest::$lastCommand = 'closure';
AsyncBusTestCase::$lastCommand = 'closure';
});
$this->runJobs();
$this->assertEquals('closure', self::$lastCommand);
@ -135,7 +135,7 @@ abstract class AsyncBusTest extends TestCase {
public function testClosureSelf(): void {
$this->getBus()->push(function () {
AsyncBusTest::$lastCommand = 'closure-self';
AsyncBusTestCase::$lastCommand = 'closure-self';
});
$this->runJobs();
$this->assertEquals('closure-self', self::$lastCommand);
@ -153,7 +153,7 @@ abstract class AsyncBusTest extends TestCase {
public function testClosureBind(): void {
$state = 'bar';
$this->getBus()->push(function () use ($state) {
AsyncBusTest::$lastCommand = 'closure-' . $state;
AsyncBusTestCase::$lastCommand = 'closure-' . $state;
});
$this->runJobs();
$this->assertEquals('closure-bar', self::$lastCommand);

@ -16,6 +16,9 @@ use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;
/**
* @group DB
*/
class BackgroundModeTest extends TestCase {
private IAppConfig $appConfig;
@ -49,7 +52,7 @@ class BackgroundModeTest extends TestCase {
$this->assertStringContainsString($mode, $output);
}
public function dataModeCommand(): array {
public static function dataModeCommand(): array {
return [
'ajax' => ['ajax'],
'cron' => ['cron'],

@ -9,7 +9,10 @@ namespace Test\Command;
use OC\Command\CronBus;
use Test\BackgroundJob\DummyJobList;
class CronBusTest extends AsyncBusTest {
/**
* @group DB
*/
class CronBusTest extends AsyncBusTestCase {
/**
* @var \OCP\BackgroundJob\IJobList
*/

@ -44,22 +44,28 @@ class SignAppTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['path'],
['privateKey'],
['certificate'],
)->willReturnOnConsecutiveCalls(
null,
'PrivateKey',
'Certificate',
);
->willReturnMap([
['path', null],
['privateKey', 'PrivateKey'],
['certificate', 'Certificate'],
]);
$calls = [
'This command requires the --path, --privateKey and --certificate.',
'*',
'*',
];
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['This command requires the --path, --privateKey and --certificate.']
);
->willReturnCallback(function (string $message) use (&$calls) {
$expected = array_shift($calls);
if ($expected === '*') {
$this->assertNotEmpty($message);
} else {
$this->assertEquals($expected, $message);
}
});
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@ -71,22 +77,28 @@ class SignAppTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['path'],
['privateKey'],
['certificate'],
)->willReturnOnConsecutiveCalls(
'AppId',
null,
'Certificate',
);
->willReturnMap([
['path', 'AppId'],
['privateKey', null],
['certificate', 'Certificate'],
]);
$calls = [
'This command requires the --path, --privateKey and --certificate.',
'*',
'*',
];
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['This command requires the --path, --privateKey and --certificate.']
);
->willReturnCallback(function (string $message) use (&$calls) {
$expected = array_shift($calls);
if ($expected === '*') {
$this->assertNotEmpty($message);
} else {
$this->assertEquals($expected, $message);
}
});
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@ -98,22 +110,28 @@ class SignAppTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['path'],
['privateKey'],
['certificate'],
)->willReturnOnConsecutiveCalls(
'AppId',
'privateKey',
null,
);
->willReturnMap([
['path', 'AppId'],
['privateKey', 'PrivateKey'],
['certificate', null],
]);
$calls = [
'This command requires the --path, --privateKey and --certificate.',
'*',
'*',
];
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['This command requires the --path, --privateKey and --certificate.']
);
->willReturnCallback(function (string $message) use (&$calls) {
$expected = array_shift($calls);
if ($expected === '*') {
$this->assertNotEmpty($message);
} else {
$this->assertEquals($expected, $message);
}
});
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@ -125,29 +143,26 @@ class SignAppTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['path'],
['privateKey'],
['certificate'],
)->willReturnOnConsecutiveCalls(
'AppId',
'privateKey',
'certificate',
);
->willReturnMap([
['path', 'AppId'],
['privateKey', 'privateKey'],
['certificate', 'certificate'],
]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
->withConsecutive(['privateKey'])
->willReturnOnConsecutiveCalls(false);
->willReturnMap([
['privateKey', false],
]);
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['Private key "privateKey" does not exists.']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('Private key "privateKey" does not exists.', $message);
});
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@ -159,34 +174,26 @@ class SignAppTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['path'],
['privateKey'],
['certificate'],
)->willReturnOnConsecutiveCalls(
'AppId',
'privateKey',
'certificate',
);
->willReturnMap([
['path', 'AppId'],
['privateKey', 'privateKey'],
['certificate', 'certificate'],
]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
->withConsecutive(
['privateKey'],
['certificate'],
)
->willReturnOnConsecutiveCalls(
\OC::$SERVERROOT . '/tests/data/integritycheck/core.key',
false
);
->willReturnMap([
['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
['certificate', false],
]);
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['Certificate "certificate" does not exists.']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('Certificate "certificate" does not exists.', $message);
});
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@ -198,27 +205,19 @@ class SignAppTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['path'],
['privateKey'],
['certificate'],
)->willReturnOnConsecutiveCalls(
'AppId',
'privateKey',
'certificate',
);
->willReturnMap([
['path', 'AppId'],
['privateKey', 'privateKey'],
['certificate', 'certificate'],
]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
->withConsecutive(
['privateKey'],
['certificate'],
)
->willReturnOnConsecutiveCalls(
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'),
);
->willReturnMap([
['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
['certificate', \OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'],
]);
$this->checker
->expects($this->once())
@ -228,9 +227,9 @@ class SignAppTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['Error: My error message']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('Error: My error message', $message);
});
$this->assertSame(1, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}
@ -242,27 +241,19 @@ class SignAppTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['path'],
['privateKey'],
['certificate'],
)->willReturnOnConsecutiveCalls(
'AppId',
'privateKey',
'certificate',
);
->willReturnMap([
['path', 'AppId'],
['privateKey', 'privateKey'],
['certificate', 'certificate'],
]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
->withConsecutive(
['privateKey'],
['certificate'],
)
->willReturnOnConsecutiveCalls(
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'),
);
->willReturnMap([
['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
['certificate', \OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'],
]);
$this->checker
->expects($this->once())
@ -271,9 +262,9 @@ class SignAppTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['Successfully signed "AppId"']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('Successfully signed "AppId"', $message);
});
$this->assertSame(0, self::invokePrivate($this->signApp, 'execute', [$inputInterface, $outputInterface]));
}

@ -39,22 +39,18 @@ class SignCoreTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['privateKey'],
['certificate'],
['path'],
)->willReturnOnConsecutiveCalls(
null,
'certificate',
'certificate',
);
->willReturnMap([
['privateKey', null],
['certificate', 'certificate'],
['path', 'certificate'],
]);
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['--privateKey, --certificate and --path are required.']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('--privateKey, --certificate and --path are required.', $message);
});
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@ -66,22 +62,18 @@ class SignCoreTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['privateKey'],
['certificate'],
['path'],
)->willReturnOnConsecutiveCalls(
'privateKey',
null,
'certificate',
);
->willReturnMap([
['privateKey', 'privateKey'],
['certificate', null],
['path', 'certificate'],
]);
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['--privateKey, --certificate and --path are required.']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('--privateKey, --certificate and --path are required.', $message);
});
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@ -93,32 +85,24 @@ class SignCoreTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['privateKey'],
['certificate'],
['path'],
)->willReturnOnConsecutiveCalls(
'privateKey',
'certificate',
'certificate',
);
->willReturnMap([
['privateKey', 'privateKey'],
['certificate', 'certificate'],
['path', 'certificate'],
]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
->withConsecutive(
['privateKey'],
)
->willReturnOnConsecutiveCalls(
false,
);
->willReturnMap([
['privateKey', false],
]);
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['Private key "privateKey" does not exists.']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('Private key "privateKey" does not exists.', $message);
});
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@ -130,34 +114,26 @@ class SignCoreTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['privateKey'],
['certificate'],
['path'],
)->willReturnOnConsecutiveCalls(
'privateKey',
'certificate',
'certificate',
);
->willReturnMap([
['privateKey', 'privateKey'],
['certificate', 'certificate'],
['path', 'certificate'],
]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
->withConsecutive(
['privateKey'],
['certificate'],
)
->willReturnOnConsecutiveCalls(
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
false,
);
->willReturnMap([
['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
['certificate', false],
]);
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['Certificate "certificate" does not exists.']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('Certificate "certificate" does not exists.', $message);
});
$this->assertSame(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@ -169,27 +145,19 @@ class SignCoreTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['privateKey'],
['certificate'],
['path'],
)->willReturnOnConsecutiveCalls(
'privateKey',
'certificate',
'certificate',
);
->willReturnMap([
['privateKey', 'privateKey'],
['certificate', 'certificate'],
['path', 'certificate'],
]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
->withConsecutive(
['privateKey'],
['certificate'],
)
->willReturnOnConsecutiveCalls(
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'),
);
->willReturnMap([
['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
['certificate', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')],
]);
$this->checker
->expects($this->once())
@ -199,9 +167,9 @@ class SignCoreTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['Error: My exception message']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('Error: My exception message', $message);
});
$this->assertEquals(1, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}
@ -213,27 +181,19 @@ class SignCoreTest extends TestCase {
$inputInterface
->expects($this->exactly(3))
->method('getOption')
->withConsecutive(
['privateKey'],
['certificate'],
['path'],
)->willReturnOnConsecutiveCalls(
'privateKey',
'certificate',
'certificate',
);
->willReturnMap([
['privateKey', 'privateKey'],
['certificate', 'certificate'],
['path', 'certificate'],
]);
$this->fileAccessHelper
->expects($this->any())
->method('file_get_contents')
->withConsecutive(
['privateKey'],
['certificate'],
)
->willReturnOnConsecutiveCalls(
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key'),
file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt'),
);
->willReturnMap([
['privateKey', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.key')],
['certificate', file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/core.crt')],
]);
$this->checker
->expects($this->once())
@ -242,9 +202,9 @@ class SignCoreTest extends TestCase {
$outputInterface
->expects($this->any())
->method('writeln')
->withConsecutive(
['Successfully signed "core"']
);
->willReturnCallback(function (string $message) {
$this->assertEquals('Successfully signed "core"', $message);
});
$this->assertEquals(0, self::invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]));
}

@ -31,7 +31,7 @@ class LegacyHelperTest extends \Test\TestCase {
$this->assertEquals($expected, $result);
}
public function humanFileSizeProvider() {
public static function humanFileSizeProvider(): array {
return [
['0 B', 0],
['1 KB', 1024],
@ -51,7 +51,7 @@ class LegacyHelperTest extends \Test\TestCase {
$this->assertEquals($expected, $result);
}
public function providesComputerFileSize() {
public static function providesComputerFileSize(): array {
return [
[0.0, '0 B'],
[1024.0, '1 KB'],
@ -110,95 +110,87 @@ class LegacyHelperTest extends \Test\TestCase {
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(2))
->method('file_exists')
->withConsecutive(
->willReturnMap([
// Conflict on filename.ext
['dir/filename.ext'],
['dir/filename (2).ext'],
)
->will($this->onConsecutiveCalls(true, false));
['dir/filename.ext', true],
['dir/filename (2).ext', false],
]);
$this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(3))
->method('file_exists')
->withConsecutive(
['dir/filename.ext'],
['dir/filename (2).ext'],
['dir/filename (3).ext'],
)
->will($this->onConsecutiveCalls(true, true, false));
->willReturnMap([
// Conflict on filename.ext
['dir/filename.ext', true],
['dir/filename (2).ext', true],
['dir/filename (3).ext', false],
]);
$this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(2))
->method('file_exists')
->withConsecutive(
['dir/filename (1).ext'],
['dir/filename (2).ext'],
)
->will($this->onConsecutiveCalls(true, false));
->willReturnMap([
['dir/filename (1).ext', true],
['dir/filename (2).ext', false],
]);
$this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (1).ext', $viewMock));
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(2))
->method('file_exists')
->withConsecutive(
['dir/filename (2).ext'],
['dir/filename (3).ext'],
)
->will($this->onConsecutiveCalls(true, false));
->willReturnMap([
['dir/filename (2).ext', true],
['dir/filename (3).ext', false],
]);
$this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock));
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(3))
->method('file_exists')
->withConsecutive(
['dir/filename (2).ext'],
['dir/filename (3).ext'],
['dir/filename (4).ext'],
)
->will($this->onConsecutiveCalls(true, true, false));
->willReturnMap([
['dir/filename (2).ext', true],
['dir/filename (3).ext', true],
['dir/filename (4).ext', false],
]);
$this->assertEquals('dir/filename (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock));
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(2))
->method('file_exists')
->withConsecutive(
['dir/filename(1).ext'],
['dir/filename(2).ext'],
)
->will($this->onConsecutiveCalls(true, false));
->willReturnMap([
['dir/filename(1).ext', true],
['dir/filename(2).ext', false],
]);
$this->assertEquals('dir/filename(2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1).ext', $viewMock));
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(2))
->method('file_exists')
->withConsecutive(
['dir/filename(1) (1).ext'],
['dir/filename(1) (2).ext'],
)
->will($this->onConsecutiveCalls(true, false));
->willReturnMap([
['dir/filename(1) (1).ext', true],
['dir/filename(1) (2).ext', false],
]);
$this->assertEquals('dir/filename(1) (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock));
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(3))
->method('file_exists')
->withConsecutive(
['dir/filename(1) (1).ext'],
['dir/filename(1) (2).ext'],
['dir/filename(1) (3).ext'],
)
->will($this->onConsecutiveCalls(true, true, false));
->willReturnMap([
['dir/filename(1) (1).ext', true],
['dir/filename(1) (2).ext', true],
['dir/filename(1) (3).ext', false],
]);
$this->assertEquals('dir/filename(1) (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock));
$viewMock = $this->createMock(View::class);
$viewMock->expects($this->exactly(2))
->method('file_exists')
->withConsecutive(
['dir/filename(1) (2) (3).ext'],
['dir/filename(1) (2) (4).ext'],
)
->will($this->onConsecutiveCalls(true, false));
->willReturnMap([
['dir/filename(1) (2) (3).ext', true],
['dir/filename(1) (2) (4).ext', false],
]);
$this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock));
}
@ -227,7 +219,7 @@ class LegacyHelperTest extends \Test\TestCase {
}
public function streamCopyDataProvider() {
public static function streamCopyDataProvider(): array {
return [
[0, false, false, false],
[0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false],
@ -260,17 +252,4 @@ class LegacyHelperTest extends \Test\TestCase {
\OC_Helper::rmdirr($baseDir);
$this->assertFalse(file_exists($baseDir));
}
/**
* Allows us to test private methods/properties
*
* @param $object
* @param $methodName
* @param array $parameters
* @return mixed
* @deprecated Please extend \Test\TestCase and use self::invokePrivate() then
*/
public static function invokePrivate($object, $methodName, array $parameters = []) {
return parent::invokePrivate($object, $methodName, $parameters);
}
}

Loading…
Cancel
Save