Adds tests for the memory checks
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
This commit is contained in:
parent
c164409ee7
commit
7aed47f776
3 changed files with 57 additions and 73 deletions
|
@ -171,7 +171,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -219,7 +219,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -268,7 +268,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -315,7 +315,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -360,7 +360,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -405,7 +405,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -450,7 +450,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -463,7 +463,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should return a warning if the memory limit is too small', function(done) {
|
||||
it('should return a warning if the memory limit is below the recommended value', function(done) {
|
||||
var async = OC.SetupChecks.checkSetup();
|
||||
|
||||
suite.server.requests[0].respond(
|
||||
|
@ -495,7 +495,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: false
|
||||
isMemoryLimitSufficient: false
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -561,7 +561,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -607,7 +607,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -653,7 +653,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -699,7 +699,7 @@ describe('OC.SetupChecks tests', function() {
|
|||
cronInfo: {
|
||||
diffInSeconds: 0
|
||||
},
|
||||
isTheMemoryLimitHighEnough: true
|
||||
isMemoryLimitSufficient: true
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -78,13 +78,6 @@ class CheckSetupControllerTest extends TestCase {
|
|||
/** @var MemoryInfo|MockObject */
|
||||
private $memoryInfo;
|
||||
|
||||
/**
|
||||
* Backup of the "memory_limit" ini value before tests.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $memoryLimitIniValueBeforeTest;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
@ -115,7 +108,7 @@ class CheckSetupControllerTest extends TestCase {
|
|||
$this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock();
|
||||
$this->dateTimeFormatter = $this->getMockBuilder(IDateTimeFormatter::class)->getMock();
|
||||
$this->memoryInfo = $this->getMockBuilder(MemoryInfo::class)
|
||||
->setMethods(['getMemoryLimit',])
|
||||
->setMethods(['isMemoryLimitSufficient',])
|
||||
->getMock();
|
||||
$this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController')
|
||||
->setConstructorArgs([
|
||||
|
@ -440,8 +433,8 @@ class CheckSetupControllerTest extends TestCase {
|
|||
->method('hasPassedCheck')
|
||||
->willReturn(true);
|
||||
$this->memoryInfo
|
||||
->method('getMemoryLimit')
|
||||
->willReturn(512 * 1024 * 1024);
|
||||
->method('isMemoryLimitSufficient')
|
||||
->willReturn(true);
|
||||
|
||||
$expected = new DataResponse(
|
||||
[
|
||||
|
@ -483,7 +476,7 @@ class CheckSetupControllerTest extends TestCase {
|
|||
'missingIndexes' => [],
|
||||
'isPhpMailerUsed' => false,
|
||||
'mailSettingsDocumentation' => 'https://server/index.php/settings/admin',
|
||||
'isTheMemoryLimitHighEnough' => true,
|
||||
'isMemoryLimitSufficient' => true,
|
||||
]
|
||||
);
|
||||
$this->assertEquals($expected, $this->checkSetupController->check());
|
||||
|
@ -1180,37 +1173,4 @@ Array
|
|||
);
|
||||
$this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns test values for the memory limit check.
|
||||
* 1. the memory limit
|
||||
* 2. the expected check value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMemoryLimitTestData(): array {
|
||||
return [
|
||||
'unlimited' => [-1, true,],
|
||||
'512M' => [512 * 1024 * 1024, true,],
|
||||
'1G' => [1024 * 1024 * 1024, true,],
|
||||
'64M' => [64 * 1024 * 1024, false,],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that if the memory limit is high enough, there is no message.
|
||||
*
|
||||
* @param string $memoryLimit The memory limit reported by MemoryInfo.
|
||||
* @param bool $expected The expected memory check return value.
|
||||
* @dataProvider getMemoryLimitTestData
|
||||
*/
|
||||
public function testMemoryLimit(string $memoryLimit, bool $expected) {
|
||||
$this->memoryInfo
|
||||
->method('getMemoryLimit')
|
||||
->willReturn($memoryLimit);
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->invokePrivate($this->checkSetupController, 'isTheMemoryLimitHighEnough')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,12 @@
|
|||
namespace Test;
|
||||
|
||||
use OC\MemoryInfo;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
/**
|
||||
* This class provides tests for the MemoryInfo class.
|
||||
*/
|
||||
class MemoryInfoTest extends TestCase {
|
||||
/**
|
||||
* @var MemoryInfo
|
||||
*/
|
||||
private $memoryInfo;
|
||||
|
||||
/**
|
||||
* The "memory_limit" value before tests.
|
||||
*
|
||||
|
@ -34,15 +30,6 @@ class MemoryInfoTest extends TestCase {
|
|||
ini_set('memory_limit', $this->iniSettingBeforeTest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setups a MemoryInfo instance for tests.
|
||||
*
|
||||
* @before
|
||||
*/
|
||||
public function setupMemoryInfo() {
|
||||
$this->memoryInfo = new MemoryInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data.
|
||||
*
|
||||
|
@ -66,8 +53,45 @@ class MemoryInfoTest extends TestCase {
|
|||
* @param int $expected The expected detected memory limit.
|
||||
* @dataProvider getMemoryLimitTestData
|
||||
*/
|
||||
public function testMemoryLimit($iniValue, $expected) {
|
||||
public function testMemoryLimit($iniValue, int $expected) {
|
||||
ini_set('memory_limit', $iniValue);
|
||||
self::assertEquals($expected, $this->memoryInfo->getMemoryLimit());
|
||||
$memoryInfo = new MemoryInfo();
|
||||
self::assertEquals($expected, $memoryInfo->getMemoryLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides sufficient memory limit test data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSufficientMemoryTestData(): array {
|
||||
return [
|
||||
'unlimited' => [-1, true,],
|
||||
'512M' => [512 * 1024 * 1024, true,],
|
||||
'1G' => [1024 * 1024 * 1024, true,],
|
||||
'256M' => [256 * 1024 * 1024, false,],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that isMemoryLimitSufficient returns the correct values.
|
||||
*
|
||||
* @param int $memoryLimit The memory limit
|
||||
* @param bool $expected If the memory limit is sufficient.
|
||||
* @dataProvider getSufficientMemoryTestData
|
||||
* @return void
|
||||
*/
|
||||
public function testIsMemoryLimitSufficient(int $memoryLimit, bool $expected) {
|
||||
/* @var MemoryInfo|MockObject $memoryInfo */
|
||||
$memoryInfo = $this->getMockBuilder(MemoryInfo::class)
|
||||
->setMethods(['getMemoryLimit',])
|
||||
->getMock();
|
||||
|
||||
$memoryInfo
|
||||
->method('getMemoryLimit')
|
||||
->willReturn($memoryLimit);
|
||||
|
||||
$isMemoryLimitSufficient = $memoryInfo->isMemoryLimitSufficient();
|
||||
self::assertEquals($expected, $isMemoryLimitSufficient);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue