Browse Source
Merge pull request #48218 from nextcloud/ci/noid/prepare-phpunit-10
chore: Cleanup and prepare some app tests for PHPUnit 10
pull/48220/head
Ferdinand Thiessen
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
45 additions and
28 deletions
-
apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php
-
apps/webhook_listeners/tests/Service/PHPMongoQueryTest.php
-
apps/workflowengine/tests/Check/AbstractStringCheckTest.php
-
apps/workflowengine/tests/ManagerTest.php
-
tests/lib/TestCase.php
|
|
|
@ -31,15 +31,9 @@ class PredefinedStatusServiceTest extends TestCase { |
|
|
|
public function testGetDefaultStatuses(): void { |
|
|
|
$this->l10n->expects($this->exactly(7)) |
|
|
|
->method('t') |
|
|
|
->withConsecutive( |
|
|
|
['In a meeting'], |
|
|
|
['Commuting'], |
|
|
|
['Working remotely'], |
|
|
|
['Out sick'], |
|
|
|
['Vacationing'], |
|
|
|
['In a call'], |
|
|
|
) |
|
|
|
->willReturnArgument(0); |
|
|
|
->willReturnCallback(function ($text, $parameters = []) { |
|
|
|
return vsprintf($text, $parameters); |
|
|
|
}); |
|
|
|
|
|
|
|
$actual = $this->service->getDefaultStatuses(); |
|
|
|
$this->assertEquals([ |
|
|
|
@ -186,15 +180,9 @@ class PredefinedStatusServiceTest extends TestCase { |
|
|
|
public function testGetDefaultStatusById(): void { |
|
|
|
$this->l10n->expects($this->exactly(7)) |
|
|
|
->method('t') |
|
|
|
->withConsecutive( |
|
|
|
['In a meeting'], |
|
|
|
['Commuting'], |
|
|
|
['Working remotely'], |
|
|
|
['Out sick'], |
|
|
|
['Vacationing'], |
|
|
|
['In a call'], |
|
|
|
) |
|
|
|
->willReturnArgument(0); |
|
|
|
->willReturnCallback(function ($text, $parameters = []) { |
|
|
|
return vsprintf($text, $parameters); |
|
|
|
}); |
|
|
|
|
|
|
|
$this->assertEquals([ |
|
|
|
'id' => 'call', |
|
|
|
|
|
|
|
@ -14,7 +14,7 @@ use OCP\Files\Events\Node\NodeWrittenEvent; |
|
|
|
use Test\TestCase; |
|
|
|
|
|
|
|
class PHPMongoQueryTest extends TestCase { |
|
|
|
private function dataExecuteQuery() { |
|
|
|
public static function dataExecuteQuery(): array { |
|
|
|
$event = [ |
|
|
|
'event' => [ |
|
|
|
'class' => NodeWrittenEvent::class, |
|
|
|
|
|
|
|
@ -22,8 +22,7 @@ class AbstractStringCheckTest extends \Test\TestCase { |
|
|
|
->setConstructorArgs([ |
|
|
|
$l, |
|
|
|
]) |
|
|
|
->setMethods([ |
|
|
|
'setPath', |
|
|
|
->onlyMethods([ |
|
|
|
'executeCheck', |
|
|
|
'getActualValue', |
|
|
|
]) |
|
|
|
|
|
|
|
@ -362,16 +362,22 @@ class ManagerTest extends TestCase { |
|
|
|
$cache->expects($this->exactly(4)) |
|
|
|
->method('remove') |
|
|
|
->with('events'); |
|
|
|
$this->cacheFactory->method('createDistributed')->willReturn($cache); |
|
|
|
$this->cacheFactory->method('createDistributed') |
|
|
|
->willReturn($cache); |
|
|
|
|
|
|
|
$expectedCalls = [ |
|
|
|
[IManager::SCOPE_ADMIN], |
|
|
|
[IManager::SCOPE_USER], |
|
|
|
]; |
|
|
|
$i = 0; |
|
|
|
$operationMock = $this->createMock(IOperation::class); |
|
|
|
$operationMock->expects($this->any()) |
|
|
|
->method('isAvailableForScope') |
|
|
|
->withConsecutive( |
|
|
|
[IManager::SCOPE_ADMIN], |
|
|
|
[IManager::SCOPE_USER] |
|
|
|
) |
|
|
|
->willReturn(true); |
|
|
|
->willReturnCallback(function () use (&$expectedCalls, &$i): bool { |
|
|
|
$this->assertEquals($expectedCalls[$i], func_get_args()); |
|
|
|
$i++; |
|
|
|
return true; |
|
|
|
}); |
|
|
|
|
|
|
|
$this->container->expects($this->any()) |
|
|
|
->method('query') |
|
|
|
@ -390,7 +396,7 @@ class ManagerTest extends TestCase { |
|
|
|
$this->createMock(UserMountCache::class), |
|
|
|
$this->createMock(IMountManager::class), |
|
|
|
]) |
|
|
|
->setMethodsExcept(['getEvents']) |
|
|
|
->onlyMethods($this->filterClassMethods(File::class, ['getEvents'])) |
|
|
|
->getMock(); |
|
|
|
} |
|
|
|
return $this->createMock(ICheck::class); |
|
|
|
|
|
|
|
@ -271,6 +271,30 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Filter methods |
|
|
|
* |
|
|
|
* Returns all methods of the given class, |
|
|
|
* that are public or abstract and not in the ignoreMethods list, |
|
|
|
* to be able to fill onlyMethods() with an inverted list. |
|
|
|
* |
|
|
|
* @param string $className |
|
|
|
* @param string[] $filterMethods |
|
|
|
* @return string[] |
|
|
|
*/ |
|
|
|
public function filterClassMethods(string $className, array $filterMethods): array { |
|
|
|
$class = new \ReflectionClass($className); |
|
|
|
|
|
|
|
$methods = []; |
|
|
|
foreach ($class->getMethods() as $method) { |
|
|
|
if (($method->isPublic() || $method->isAbstract()) && !in_array($method->getName(), $filterMethods, true)) { |
|
|
|
$methods[] = $method->getName(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $methods; |
|
|
|
} |
|
|
|
|
|
|
|
public static function tearDownAfterClass(): void { |
|
|
|
if (!self::$wasDatabaseAllowed && self::$realDatabase !== null) { |
|
|
|
// in case an error is thrown in a test, PHPUnit jumps straight to tearDownAfterClass,
|
|
|
|
|