From b09620651cbb72e5a623d47ed409e949b114c7cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Aug 2020 14:08:18 +0200 Subject: Don't use deprecated getIniWrapper() anymore Signed-off-by: Joas Schilling --- tests/lib/LargeFileHelperGetFileSizeTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/LargeFileHelperGetFileSizeTest.php b/tests/lib/LargeFileHelperGetFileSizeTest.php index 3ad8f5b8806..e21ac4ee64b 100644 --- a/tests/lib/LargeFileHelperGetFileSizeTest.php +++ b/tests/lib/LargeFileHelperGetFileSizeTest.php @@ -8,6 +8,8 @@ namespace Test; +use bantu\IniGetWrapper\IniGetWrapper; + /** * Tests whether LargeFileHelper is able to determine file size at all. * Large files are not considered yet. @@ -43,7 +45,7 @@ class LargeFileHelperGetFileSizeTest extends TestCase { 'The PHP curl extension is required for this test.' ); } - if (\OC::$server->getIniWrapper()->getString('open_basedir') !== '') { + if (\OC::$server->get(IniGetWrapper::class)->getString('open_basedir') !== '') { $this->markTestSkipped( 'The PHP curl extension does not work with the file:// protocol when open_basedir is enabled.' ); -- cgit v1.2.3 From 9e483ea9495288cd8d38d4d3570da6fd53e3970c Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 20 Aug 2020 16:35:14 +0200 Subject: Fix unit tests Signed-off-by: Morris Jobke --- .../tests/Controller/CheckSetupControllerTest.php | 13 +++++++++-- tests/lib/TempManagerTest.php | 27 ++++++++-------------- 2 files changed, 21 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index a1f7e8aa83f..0bfecd05b9a 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -35,6 +35,7 @@ namespace OCA\Settings\Tests\Controller; +use bantu\IniGetWrapper\IniGetWrapper; use OC; use OC\DB\Connection; use OC\IntegrityCheck\Checker; @@ -93,6 +94,8 @@ class CheckSetupControllerTest extends TestCase { private $memoryInfo; /** @var SecureRandom|\PHPUnit\Framework\MockObject\MockObject */ private $secureRandom; + /** @var IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */ + private $iniGetWrapper; /** * Holds a list of directories created during tests. @@ -132,6 +135,7 @@ class CheckSetupControllerTest extends TestCase { ->setMethods(['isMemoryLimitSufficient',]) ->getMock(); $this->secureRandom = $this->getMockBuilder(SecureRandom::class)->getMock(); + $this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class)->getMock(); $this->checkSetupController = $this->getMockBuilder(CheckSetupController::class) ->setConstructorArgs([ 'settings', @@ -148,6 +152,7 @@ class CheckSetupControllerTest extends TestCase { $this->dateTimeFormatter, $this->memoryInfo, $this->secureRandom, + $this->iniGetWrapper, ]) ->setMethods([ 'isReadOnlyConfig', @@ -618,6 +623,7 @@ class CheckSetupControllerTest extends TestCase { $this->dateTimeFormatter, $this->memoryInfo, $this->secureRandom, + $this->iniGetWrapper, ]) ->setMethods(null)->getMock(); @@ -651,6 +657,7 @@ class CheckSetupControllerTest extends TestCase { $this->dateTimeFormatter, $this->memoryInfo, $this->secureRandom, + $this->iniGetWrapper, ]) ->setMethods(null)->getMock(); @@ -1418,7 +1425,8 @@ Array $this->lockingProvider, $this->dateTimeFormatter, $this->memoryInfo, - $this->secureRandom + $this->secureRandom, + $this->iniGetWrapper ); $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isMysqlUsedWithoutUTF8MB4')); @@ -1466,7 +1474,8 @@ Array $this->lockingProvider, $this->dateTimeFormatter, $this->memoryInfo, - $this->secureRandom + $this->secureRandom, + $this->iniGetWrapper ); $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed')); diff --git a/tests/lib/TempManagerTest.php b/tests/lib/TempManagerTest.php index a1b5e732b40..8ae67fb1a90 100644 --- a/tests/lib/TempManagerTest.php +++ b/tests/lib/TempManagerTest.php @@ -9,18 +9,10 @@ namespace Test; +use bantu\IniGetWrapper\IniGetWrapper; use OC\Log; use OCP\IConfig; - -class NullLogger extends Log { - public function __construct($logger = null) { - //disable original constructor - } - - public function log(int $level, string $message, array $context = []) { - //noop - } -} +use Psr\Log\LoggerInterface; class TempManagerTest extends \Test\TestCase { protected $baseDir = null; @@ -47,7 +39,7 @@ class TempManagerTest extends \Test\TestCase { */ protected function getManager($logger = null, $config = null) { if (!$logger) { - $logger = new NullLogger(); + $logger = $this->createMock(LoggerInterface::class); } if (!$config) { $config = $this->createMock(IConfig::class); @@ -55,7 +47,8 @@ class TempManagerTest extends \Test\TestCase { ->with('tempdirectory', null) ->willReturn('/tmp'); } - $manager = new \OC\TempManager($logger, $config); + $iniGetWrapper = $this->createMock(IniGetWrapper::class); + $manager = new \OC\TempManager($logger, $config, $iniGetWrapper); if ($this->baseDir) { $manager->overrideTempBaseDir($this->baseDir); } @@ -140,7 +133,7 @@ class TempManagerTest extends \Test\TestCase { public function testLogCantCreateFile() { $this->markTestSkipped('TODO: Disable because fails on drone'); - $logger = $this->createMock(NullLogger::class); + $logger = $this->createMock(LoggerInterface::class); $manager = $this->getManager($logger); chmod($this->baseDir, 0500); $logger->expects($this->once()) @@ -152,7 +145,7 @@ class TempManagerTest extends \Test\TestCase { public function testLogCantCreateFolder() { $this->markTestSkipped('TODO: Disable because fails on drone'); - $logger = $this->createMock(NullLogger::class); + $logger = $this->createMock(LoggerInterface::class); $manager = $this->getManager($logger); chmod($this->baseDir, 0500); $logger->expects($this->once()) @@ -162,7 +155,7 @@ class TempManagerTest extends \Test\TestCase { } public function testBuildFileNameWithPostfix() { - $logger = $this->createMock(NullLogger::class); + $logger = $this->createMock(LoggerInterface::class); $tmpManager = self::invokePrivate( $this->getManager($logger), 'buildFileNameWithSuffix', @@ -173,7 +166,7 @@ class TempManagerTest extends \Test\TestCase { } public function testBuildFileNameWithoutPostfix() { - $logger = $this->createMock(NullLogger::class); + $logger = $this->createMock(LoggerInterface::class); $tmpManager = self::invokePrivate( $this->getManager($logger), 'buildFileNameWithSuffix', @@ -184,7 +177,7 @@ class TempManagerTest extends \Test\TestCase { } public function testBuildFileNameWithSuffixPathTraversal() { - $logger = $this->createMock(NullLogger::class); + $logger = $this->createMock(LoggerInterface::class); $tmpManager = self::invokePrivate( $this->getManager($logger), 'buildFileNameWithSuffix', -- cgit v1.2.3 From 590d46121097d8b7dcd6f722b95f9dc4bdee653e Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 20 Aug 2020 16:53:34 +0200 Subject: Remove unneeded import Signed-off-by: Morris Jobke --- tests/lib/TempManagerTest.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/TempManagerTest.php b/tests/lib/TempManagerTest.php index 8ae67fb1a90..5df0e68d4fa 100644 --- a/tests/lib/TempManagerTest.php +++ b/tests/lib/TempManagerTest.php @@ -10,7 +10,6 @@ namespace Test; use bantu\IniGetWrapper\IniGetWrapper; -use OC\Log; use OCP\IConfig; use Psr\Log\LoggerInterface; -- cgit v1.2.3