Fix unit tests

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
pull/22331/head
Morris Jobke 2020-08-20 16:35:14 +07:00
parent 567e99abe2
commit 9e483ea949
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
2 changed files with 21 additions and 19 deletions

@ -35,6 +35,7 @@
namespace OCA\Settings\Tests\Controller; namespace OCA\Settings\Tests\Controller;
use bantu\IniGetWrapper\IniGetWrapper;
use OC; use OC;
use OC\DB\Connection; use OC\DB\Connection;
use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Checker;
@ -93,6 +94,8 @@ class CheckSetupControllerTest extends TestCase {
private $memoryInfo; private $memoryInfo;
/** @var SecureRandom|\PHPUnit\Framework\MockObject\MockObject */ /** @var SecureRandom|\PHPUnit\Framework\MockObject\MockObject */
private $secureRandom; private $secureRandom;
/** @var IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */
private $iniGetWrapper;
/** /**
* Holds a list of directories created during tests. * Holds a list of directories created during tests.
@ -132,6 +135,7 @@ class CheckSetupControllerTest extends TestCase {
->setMethods(['isMemoryLimitSufficient',]) ->setMethods(['isMemoryLimitSufficient',])
->getMock(); ->getMock();
$this->secureRandom = $this->getMockBuilder(SecureRandom::class)->getMock(); $this->secureRandom = $this->getMockBuilder(SecureRandom::class)->getMock();
$this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class)->getMock();
$this->checkSetupController = $this->getMockBuilder(CheckSetupController::class) $this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
->setConstructorArgs([ ->setConstructorArgs([
'settings', 'settings',
@ -148,6 +152,7 @@ class CheckSetupControllerTest extends TestCase {
$this->dateTimeFormatter, $this->dateTimeFormatter,
$this->memoryInfo, $this->memoryInfo,
$this->secureRandom, $this->secureRandom,
$this->iniGetWrapper,
]) ])
->setMethods([ ->setMethods([
'isReadOnlyConfig', 'isReadOnlyConfig',
@ -618,6 +623,7 @@ class CheckSetupControllerTest extends TestCase {
$this->dateTimeFormatter, $this->dateTimeFormatter,
$this->memoryInfo, $this->memoryInfo,
$this->secureRandom, $this->secureRandom,
$this->iniGetWrapper,
]) ])
->setMethods(null)->getMock(); ->setMethods(null)->getMock();
@ -651,6 +657,7 @@ class CheckSetupControllerTest extends TestCase {
$this->dateTimeFormatter, $this->dateTimeFormatter,
$this->memoryInfo, $this->memoryInfo,
$this->secureRandom, $this->secureRandom,
$this->iniGetWrapper,
]) ])
->setMethods(null)->getMock(); ->setMethods(null)->getMock();
@ -1418,7 +1425,8 @@ Array
$this->lockingProvider, $this->lockingProvider,
$this->dateTimeFormatter, $this->dateTimeFormatter,
$this->memoryInfo, $this->memoryInfo,
$this->secureRandom $this->secureRandom,
$this->iniGetWrapper
); );
$this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isMysqlUsedWithoutUTF8MB4')); $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isMysqlUsedWithoutUTF8MB4'));
@ -1466,7 +1474,8 @@ Array
$this->lockingProvider, $this->lockingProvider,
$this->dateTimeFormatter, $this->dateTimeFormatter,
$this->memoryInfo, $this->memoryInfo,
$this->secureRandom $this->secureRandom,
$this->iniGetWrapper
); );
$this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed')); $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed'));

@ -9,18 +9,10 @@
namespace Test; namespace Test;
use bantu\IniGetWrapper\IniGetWrapper;
use OC\Log; use OC\Log;
use OCP\IConfig; use OCP\IConfig;
use Psr\Log\LoggerInterface;
class NullLogger extends Log {
public function __construct($logger = null) {
//disable original constructor
}
public function log(int $level, string $message, array $context = []) {
//noop
}
}
class TempManagerTest extends \Test\TestCase { class TempManagerTest extends \Test\TestCase {
protected $baseDir = null; protected $baseDir = null;
@ -47,7 +39,7 @@ class TempManagerTest extends \Test\TestCase {
*/ */
protected function getManager($logger = null, $config = null) { protected function getManager($logger = null, $config = null) {
if (!$logger) { if (!$logger) {
$logger = new NullLogger(); $logger = $this->createMock(LoggerInterface::class);
} }
if (!$config) { if (!$config) {
$config = $this->createMock(IConfig::class); $config = $this->createMock(IConfig::class);
@ -55,7 +47,8 @@ class TempManagerTest extends \Test\TestCase {
->with('tempdirectory', null) ->with('tempdirectory', null)
->willReturn('/tmp'); ->willReturn('/tmp');
} }
$manager = new \OC\TempManager($logger, $config); $iniGetWrapper = $this->createMock(IniGetWrapper::class);
$manager = new \OC\TempManager($logger, $config, $iniGetWrapper);
if ($this->baseDir) { if ($this->baseDir) {
$manager->overrideTempBaseDir($this->baseDir); $manager->overrideTempBaseDir($this->baseDir);
} }
@ -140,7 +133,7 @@ class TempManagerTest extends \Test\TestCase {
public function testLogCantCreateFile() { public function testLogCantCreateFile() {
$this->markTestSkipped('TODO: Disable because fails on drone'); $this->markTestSkipped('TODO: Disable because fails on drone');
$logger = $this->createMock(NullLogger::class); $logger = $this->createMock(LoggerInterface::class);
$manager = $this->getManager($logger); $manager = $this->getManager($logger);
chmod($this->baseDir, 0500); chmod($this->baseDir, 0500);
$logger->expects($this->once()) $logger->expects($this->once())
@ -152,7 +145,7 @@ class TempManagerTest extends \Test\TestCase {
public function testLogCantCreateFolder() { public function testLogCantCreateFolder() {
$this->markTestSkipped('TODO: Disable because fails on drone'); $this->markTestSkipped('TODO: Disable because fails on drone');
$logger = $this->createMock(NullLogger::class); $logger = $this->createMock(LoggerInterface::class);
$manager = $this->getManager($logger); $manager = $this->getManager($logger);
chmod($this->baseDir, 0500); chmod($this->baseDir, 0500);
$logger->expects($this->once()) $logger->expects($this->once())
@ -162,7 +155,7 @@ class TempManagerTest extends \Test\TestCase {
} }
public function testBuildFileNameWithPostfix() { public function testBuildFileNameWithPostfix() {
$logger = $this->createMock(NullLogger::class); $logger = $this->createMock(LoggerInterface::class);
$tmpManager = self::invokePrivate( $tmpManager = self::invokePrivate(
$this->getManager($logger), $this->getManager($logger),
'buildFileNameWithSuffix', 'buildFileNameWithSuffix',
@ -173,7 +166,7 @@ class TempManagerTest extends \Test\TestCase {
} }
public function testBuildFileNameWithoutPostfix() { public function testBuildFileNameWithoutPostfix() {
$logger = $this->createMock(NullLogger::class); $logger = $this->createMock(LoggerInterface::class);
$tmpManager = self::invokePrivate( $tmpManager = self::invokePrivate(
$this->getManager($logger), $this->getManager($logger),
'buildFileNameWithSuffix', 'buildFileNameWithSuffix',
@ -184,7 +177,7 @@ class TempManagerTest extends \Test\TestCase {
} }
public function testBuildFileNameWithSuffixPathTraversal() { public function testBuildFileNameWithSuffixPathTraversal() {
$logger = $this->createMock(NullLogger::class); $logger = $this->createMock(LoggerInterface::class);
$tmpManager = self::invokePrivate( $tmpManager = self::invokePrivate(
$this->getManager($logger), $this->getManager($logger),
'buildFileNameWithSuffix', 'buildFileNameWithSuffix',